1717
1818#pragma newdecls required
1919
20- #define PLUGIN_VERSION " 0.2.1 "
20+ #define PLUGIN_VERSION " 0.3.0 "
2121public Plugin myinfo = {
2222 name = " Level KeyValues" ,
2323 author = " nosoop" ,
@@ -27,6 +27,7 @@ public Plugin myinfo = {
2727}
2828
2929ArrayList g_MapEntities ;
30+ bool g_bMutableList ;
3031
3132Handle g_OnEntityKeysParsed , g_OnAllEntitiesParsed ;
3233
@@ -54,6 +55,11 @@ public APLRes AskPluginLoad2(Handle self, bool late, char[] error, int err_max)
5455 CreateNative (" LevelEntityKeyValuesIterator.GetVector" , Native_MapIterGetVector );
5556 CreateNative (" LevelEntityKeyValuesIterator.SetVector" , Native_MapIterSetVector );
5657
58+ CreateNative (" LevelEntityList.Get" , Native_LevelListGet );
59+ CreateNative (" LevelEntityList.Push" , Native_InsertEntity );
60+ CreateNative (" LevelEntityList.Erase" , Native_LevelListErase );
61+ CreateNative (" LevelEntityList.Length" , Native_LevelListGetLength );
62+
5763 return APLRes_Success ;
5864}
5965
@@ -75,8 +81,10 @@ public Action OnLevelInit(const char[] mapName, char mapEntities[2097152]) {
7581
7682 g_MapEntities = ParseEntityList (mapEntities );
7783
84+ g_bMutableList = true ;
7885 Call_StartForward (g_OnAllEntitiesParsed );
7986 Call_Finish ();
87+ g_bMutableList = false ;
8088
8189 mapEntities = " " ;
8290 WriteEntityList (g_MapEntities , mapEntities , sizeof (mapEntities ));
@@ -100,12 +108,45 @@ public int Native_GetKeysByHammerID(Handle plugin, int argc) {
100108 return 0 ;
101109}
102110
111+ public int Native_LevelListGet (Handle plugin , int argc ) {
112+ return view_as <int >(CloneHandle (g_MapEntities .Get (GetNativeCell (1 ))));
113+ }
114+
115+ public int Native_LevelListErase (Handle plugin , int argc ) {
116+ if (! g_bMutableList ) {
117+ ThrowNativeError (1 , " Can't remove entities from list during non-mutable state." );
118+ }
119+ g_MapEntities .Erase (GetNativeCell (1 ));
120+ return 0 ;
121+ }
122+
103123public int Native_InsertEntity (Handle plugin , int argc ) {
124+ if (! g_bMutableList ) {
125+ ThrowNativeError (1 , " Can't push new entity into list during non-mutable state." );
126+ }
104127 StringMultiMap entity = GetNativeCell (1 );
105- g_MapEntities .Push (CloneHandle (entity ));
128+ g_MapEntities .Push (CloneStringMultiMap (entity ));
106129 return ;
107130}
108131
132+ public int Native_LevelListGetLength (Handle plugin , int argc ) {
133+ return g_MapEntities .Length ;
134+ }
135+
136+ StringMultiMap CloneStringMultiMap (StringMultiMap source ) {
137+ char key [256 ], value [256 ];
138+ StringMultiMapIterator iter = source .GetIterator ();
139+
140+ StringMultiMap output = new StringMultiMap ();
141+ while (iter .Next ()) {
142+ iter .GetKey (key , sizeof (key ));
143+ if (iter .GetString (value , sizeof (value ))) {
144+ output .AddString (key , value );
145+ }
146+ }
147+ return output ;
148+ }
149+
109150/* *
110151 * Parses the level entity string into an ArrayList of StringMultiMap handles.
111152 */
0 commit comments