Skip to content

Commit

Permalink
json update for all plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikk155 committed Apr 15, 2024
1 parent 19e87aa commit 0062593
Show file tree
Hide file tree
Showing 21 changed files with 110 additions and 84 deletions.
74 changes: 52 additions & 22 deletions .vscode/shared.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,59 @@
"body": "HookReturnCode PlayerObserverModeHook( ${1:CBasePlayer@}, ${2:ObserverMode})",
"description": "Called when a player change its spectator mode."
},
"void load( string m_szLoad, bool include = true )":
"string opIndex( uint index )":
{
"prefix":[ "load", "json", "pars" ],
"body": "load( ${1:string m_szLoad}, ${2:bool include = true})",
"description": "Loads a json file within a json class. if include is false the json is cleared before loading the new one"
"prefix":[ "JsonValue", "opInd" ],
"body": "opIndex( ${1:uint index})",
"description": "Return the given value on the array of this json if any, else returns empty string"
},
"string opIndex( uint index )":
{
"prefix":[ "json", "exists" ],
"body": "opIndex( ${1:uint index})",
"description": "Return the value of the given index"
},
"bool exists( string &in key, bool CheckValue = false )":
{
"prefix":[ "json", "exists" ],
"body": "exists( ${1:string &in key}, ${2:bool CheckValue = false})",
"description": "Return whatever the given key exists, if vlvalue is true it will check for both to exist"
},
"uint size()":
{
"prefix":[ "json", "siz" ],
"body": "size()",
"description": "Return the whole size of this json data"
},
"uint length()":
{
"prefix":[ "json", "length" ],
"body": "length()",
"description": "Return the length of this json data"
},
"string instance( string key )":
"JsonValue opIndex( string key )":
{
"prefix":[ "json", "instanc" ],
"body": "instance( ${1:string key})",
"description": "Return a string with the instance of the value for the given key"
"prefix":[ "json", "opInd" ],
"body": "opIndex( ${1:string key})",
"description": "Return the JsonValue of the given key"
},
"bool isinstance( string key, string instance )":
"string Instance( string key, bool ToString = false ){ return get( key ).Instance( ToString ); }":
{
"prefix":[ "json", "instance", "isinstanc" ],
"body": "isinstance( ${1:string key}, ${2:string instance})",
"description": "Return whatever the value for the given key is the given instance"
"prefix":[ "json", "Instanc" ],
"body": "Instance( ${1:string key}, ${2:bool ToString = false})",
"description": "Return the instance name on enum JsonValueType, if ToString is true return as a string"
},
"int get( string key, int value ){ return this[ key, value ]; }":
"":
{
"prefix":[ "json", "get" ],
"body": "get( ${1:string key}, ${2:int value})",
"description": "Use opIndex instead."
"prefix":[ "" ],
"body": "",
"description": "Vector get( string key, Vector value ){ return this[ key, value ]; } Vector opIndex( string key, Vector value ) { return ( this[ key, '' ].IsEmpty() && && g_Utility.IsString3DVec( this[ key, '' ]) ? value : atov( this[ key, '' ] ) ); } Vector2D get( string key, Vector2D value ){ return this[ key, value ]; } Vector2D opIndex( string key, Vector2D value ) { if( this.exists( key, true ) ) { array<string> szSplit = string( data[ key ] ).Split( ' ' ); if( szSplit.length() == 2 && g_Utility.IsStringFloat( szSplit[0] ) && g_Utility.IsStringFloat( szSplit[1] ) ) { return atov( string( data[ key ] ) ).Make2D(); } } return value; } RGBA get( string key, RGBA value ){ return this[ key, value ]; } RGBA opIndex( string key, RGBA value ) { if( this.exists( key, true ) ) { array<string> szSplit = this[ key ].Split( ' ' ); for( uint ui = 0; ui < szSplit.length() && g_Utility.IsStringInt( szSplit[ui] ); ui++ ) { if( ui == 3 ) { return atorgba( string( data[ key ] ) ); } } } return value; }*/ json get( string key, json value ){ return this[ key, value ]; } json opIndex( string key, json value ){ return this[ key, value.data ]; } json get( string key, dictionary value ){ return this[ key, value ]; } json opIndex( string key, dictionary value ) { json pJson; if( this.data.exists( key ) ) { if( this.Instance( key ) == JsonValueType::ARRAY ) { array<string> str = this[ key ].arrayvalue; for( uint ui = 0; ui < str.length(); ui++ ) { pJson.data[ string(ui) ] = str[ui]; } } else { pJson.data = dictionary( this.data[ key ] ); } } return pJson; } array<string> getKeys() { return this.data.getKeys(); } json opAssign( dictionary pkvd ) { array<string> str = pkvd.getKeys(); for( uint ui = 0; ui < str.length(); ui++ ) { if( string( pkvd[ str[ui] ] ).IsEmpty() ) { this.data.delete( str[ui] ); } else { this.data[ str[ui] ] = string( pkvd[ str[ui] ] ); } } return this; }"
},
"uint load( string m_szLoad, bool include = false )":
{
"prefix":[ "load", "json", "pars" ],
"body": "load( ${1:string m_szLoad}, ${2:bool include = false})",
"description": "Loads a json file within a json class. if no format '.json' is provided it asumes you sent a string with json format if include is true the json is not cleared and new data will be written above, When specifying format, folder maps/plugins is necesary to include in the path. Return codes: 0 = everything fine 1 = empty string sent 2 = file not found"
},
"enum MKLANG::CHAT":
{
Expand Down Expand Up @@ -182,7 +212,7 @@
"Reflection::Function@ opIndex( string m_iszFunction )":
{
"prefix":[ "g_Reflection.opIndex", "g_Reflection.Get", "g_Reflection.Function", "Reflection" ],
"body": "g_Reflection[ ${1:string m_iszFunction}]",
"body": "g_Reflection.opIndex( ${1:string m_iszFunction})",
"description": "Get a script function by name or namespace::name"
},
"string GetDiscord()":
Expand Down Expand Up @@ -219,13 +249,13 @@
{
"prefix":[ "atov", "StringToVecto" ],
"body": "atov( ${1:const string m_iszFrom})",
"description": "Return the given string_t as a 3D Vector"
"description": "Return the given string as a 3D Vector"
},
"Vector2D atov2( const string m_iszFrom )":
"bool atob( const string m_iszFrom )":
{
"prefix":[ "atov2", "StringToVecto" ],
"body": "atov2( ${1:const string m_iszFrom})",
"description": "Return the given string_t as a 2D Vector"
"prefix":[ "atobool", "stringtobool" ],
"body": "atob( ${1:const string m_iszFrom})",
"description": "Return the given string as a boolean, 0/1 or false/true"
},
"string CustomKeyValue( CBaseEntity@ pEntity, const string&in m_iszKey, const string&in m_iszValue = String::EMPTY_STRING )":
{
Expand Down
3 changes: 3 additions & 0 deletions makesnippets.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
makesnippets.py
pause
25 changes: 8 additions & 17 deletions makesnippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# This is used by me to update these snippets, you dont need this in your game server.

import os
import json

def CreateSnippets():

Expand All @@ -12,19 +13,19 @@ def CreateSnippets():

os.makedirs(vsfolder)

res_file = os.path.join( os.path.dirname(__file__), 'resources/shared.res' )
res_file = os.path.join( os.path.dirname(__file__), 'resources/shared.json' )

with open(res_file, 'r') as f, open( f'{vsfolder}/shared.code-snippets', 'w') as snippet:

Quote = ''

snippet.write( '{\n' )

for line in f:
datajs = json.load(f)

file_path = line.strip().strip('"')
for i in datajs.get( 'Resources', {} ):

asDst = os.path.join( os.path.dirname(__file__), file_path )
asDst = os.path.join( os.path.dirname(__file__), i )

with open( asDst, 'r' ) as a:

Expand Down Expand Up @@ -108,21 +109,14 @@ def CreateSnippets():

function = function[ : function.find( '(' ) ]

dArgs = ''
dListArgs = Arguments.split( ',' )

snippet.write( f'\t\t"body": "' )

if function.startswith( 'opIndex' ):
snippet.write( f'{body}' )

elif body != '':
if body != '':
snippet.write( f'{body}{Dot}' )

if function.startswith( 'opIndex' ):
snippet.write( f'[' )
else:
snippet.write( f'{function}(' )
snippet.write( f'{function}(' )

for i, Args in enumerate( dListArgs ):

Expand All @@ -141,10 +135,7 @@ def CreateSnippets():

snippet.write( f' {s}' )

if function.startswith( 'opIndex' ):
snippet.write( f']",\n' )
else:
snippet.write( f')",\n' )
snippet.write( f')",\n' )

snippet.write( f'\t\t"description": "{description}"\n' )

Expand Down
17 changes: 7 additions & 10 deletions scripts/mikk/json.as
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ class json
{
}

/*
@prefix json exists
Return the value of the given index
*/
string opIndex( uint index )
{
if( index < this.OpIndex.length() )
Expand All @@ -116,17 +112,17 @@ class json
Return whatever the given key exists, if vlvalue is true it will check for both to exist
*/
bool exists( string &in key, bool CheckValue = false )
{/*
{
if( CheckValue && this.data.exists( key ) )
{
JsonValue@ pValue = this[ key ];

if( this.isinstance( key, 'array' ) || this.isinstance( key, 'json' ) )
if( this.Instance( key ) == JsonValueType::ARRAY || this.Instance( key ) == JsonValueType::JSON )
{
return ( this[ key, {} ].length() > 0 );
return ( array<string>( this[ key ] ).length() > 0 || this[ key ].dictionaryvalue.getKeys().length() > 0 );
}
return ( this[ key ] != String::EMPTY_STRING );
}*/
return ( this[ key, '' ] != String::EMPTY_STRING );
}
return this.data.exists( key );
}

Expand Down Expand Up @@ -234,6 +230,7 @@ class json
json opIndex( string key, dictionary value )
{
json pJson;

if( this.data.exists( key ) )
{
if( this.Instance( key ) == JsonValueType::ARRAY )
Expand All @@ -247,7 +244,7 @@ class json
}
else
{
pJson.data = dictionary( this.data[ key ] );
pJson.data = this[ key ].dictionaryvalue;
}
}
return pJson;
Expand Down
2 changes: 1 addition & 1 deletion scripts/plugins/mikk/AFKManager.as
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void PluginInit()

Mikk.UpdateTimer( g_Think, 'Think', 1.0f, g_Scheduler.REPEAT_INFINITE_TIMES );

pJson.load( "plugins/mikk/AFKManager" );
pJson.load( "plugins/mikk/AFKManager.json" );
}

json pJson;
Expand Down
2 changes: 1 addition & 1 deletion scripts/plugins/mikk/PlayerDecalTracker.as
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void PluginInit()
// g_Module.ScriptInfo.SetMinimumAdminLevel( ADMIN_YES );

g_Hooks.RegisterHook( Hooks::Player::PlayerDecal, @PlayerDecalTracker::PlayerDecalHook );
pJson.load( 'plugins/mikk/PlayerDecalTracker' );
pJson.load( 'plugins/mikk/PlayerDecalTracker.json' );
}

json pJson;
Expand Down
2 changes: 1 addition & 1 deletion scripts/plugins/mikk/SurvivalRespawnAll.as
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void PluginInit()

g_Hooks.RegisterHook( Hooks::Player::ClientPutInServer, @ClientPutInServer );

pJson.load( "plugins/mikk/SurvivalRespawnAll" );
pJson.load( "plugins/mikk/SurvivalRespawnAll.json" );
}

json pJson;
Expand Down
4 changes: 2 additions & 2 deletions scripts/plugins/mikk/chatbridge.as
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ void LoadJson()
{
pJson.load('plugins/mikk/chatbridge/chatbridge.json');

if( pJson.keysize <= 0 )
if( pJson.length() <= 0 )
{
g_Game.AlertMessage( at_error, "WARNING! Can not open chatbridge.json! Shutting down plugin...\n" );
g_EngineFuncs.ServerPrint( "WARNING! Can not open chatbridge.json! Shutting down plugin...\n" );
array<int>i(0);i[i.length()];
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/plugins/mikk/chatbridge/ClientDisconnect.as
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace chatbridge
if( pPlayer !is null )
{
string name = g_EngineFuncs.GetPlayerAuthId( pPlayer.edict() ) + " " + string( pPlayer.pev.netname );
g_Chatbridge.Discord.print( JsonLang[ 'player_disconnect' ], { { 'name', name } } );
g_Chatbridge.Discord.print( JsonLang[ 'player_disconnect','' ], { { 'name', name } } );
}
return HOOK_CONTINUE;
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/plugins/mikk/chatbridge/ClientSay.as
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace chatbridge
if( JsonBadWords[ BadWords[ui], true ] )
sentence.Replace( BadWords[ui], '|| ' + BadWords[ui] + ' ||' );

g_Chatbridge.Discord.print( '- ' + GetEmote( pPlayer ) + ( pPlayer.IsAlive() ? "" : JsonLang[ 'player_status_dead' ] + " " ) + string( pPlayer.pev.netname ) + ": " + sentence, {} );
g_Chatbridge.Discord.print( '- ' + GetEmote( pPlayer ) + ( pPlayer.IsAlive() ? "" : JsonLang[ 'player_status_dead','' ] + " " ) + string( pPlayer.pev.netname ) + ": " + sentence, {} );

return HOOK_CONTINUE;
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/plugins/mikk/chatbridge/MapStart.as
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace chatbridge
{
if( JsonLog[ 'map start', false ] && g_Chatbridge.mapname != g_Engine.mapname )
{
g_Chatbridge.Discord.print( JsonLang[ 'map_start' ], { { 'name', string( g_Engine.mapname ) } } );
g_Chatbridge.Discord.print( JsonLang[ 'map_start','' ], { { 'name', string( g_Engine.mapname ) } } );
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/plugins/mikk/chatbridge/PlayerConnect.as
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace chatbridge
if( pPlayer !is null )
{
string name = string( Mikk.PlayerFuncs.GetSteamID( pPlayer ) ) + " " + string( pPlayer.pev.netname );
g_Chatbridge.Discord.print( JsonLang[ 'player_connected' ], { { 'name', name } } );
g_Chatbridge.Discord.print( JsonLang[ 'player_connected','' ], { { 'name', name } } );
}
return HOOK_CONTINUE;
}
Expand Down
6 changes: 3 additions & 3 deletions scripts/plugins/mikk/chatbridge/PlayerKilled.as
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ namespace chatbridge

if( pAttacker is null )
{
g_Chatbridge.Discord.print( JsonLang[ 'player_die' ], pReplacement );
g_Chatbridge.Discord.print( JsonLang[ 'player_die','' ], pReplacement );
}
else
{
if( pAttacker is pPlayer )
{
g_Chatbridge.Discord.print( JsonLang[ 'player_suicide' ], pReplacement );
g_Chatbridge.Discord.print( JsonLang[ 'player_suicide','' ], pReplacement );
}
else
{
Expand All @@ -64,7 +64,7 @@ namespace chatbridge
}
}
pReplacement["killer"] = ( pAttacker.IsPlayer() ? string( pAttacker.pev.netname ) : string( pAttacker.pev.classname ) );
g_Chatbridge.Discord.print( JsonLang[ 'player_killed' ], pReplacement );
g_Chatbridge.Discord.print( JsonLang[ 'player_killed','' ], pReplacement );
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/plugins/mikk/chatbridge/PlayerRevive.as
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace chatbridge
{
if( pPlayer is null )
{
g_Chatbridge.Discord.print( JsonLang[ 'player_revived' ], { { 'name', string( pPlayer.pev.netname ) } } );
g_Chatbridge.Discord.print( JsonLang[ 'player_revived','' ], { { 'name', string( pPlayer.pev.netname ) } } );
}
return HOOK_CONTINUE;
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/plugins/mikk/chatbridge/PlayerSpawn.as
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace chatbridge
{
if( pPlayer !is null )
{
g_Chatbridge.Discord.print( JsonLang[ 'player_spawned' ], { { 'name', string( pPlayer.pev.netname ) } } );
g_Chatbridge.Discord.print( JsonLang[ 'player_spawned','' ], { { 'name', string( pPlayer.pev.netname ) } } );
}
return HOOK_CONTINUE;
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/plugins/mikk/chatbridge/PlayersConnected.as
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace chatbridge

if( a > 0 )
{
g_Chatbridge.Discord.print( JsonLang[ 'connected_players' ], { { 'number', string(a) }, { 's', ( a == 1 ? "" : "s" ) } } );
g_Chatbridge.Discord.print( JsonLang[ 'connected_players','' ], { { 'number', string(a) }, { 's', ( a == 1 ? "" : "s" ) } } );
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/plugins/mikk/chatbridge/SurvivalEnabled.as
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace chatbridge

void SurvivalEnabled()
{
g_Chatbridge.Discord.print( JsonLang[ 'survival_start' ], {} );
g_Chatbridge.Discord.print( JsonLang[ 'survival_start','' ], {} );
}
}
}
Loading

0 comments on commit 0062593

Please sign in to comment.