|
3 | 3 | #endif |
4 | 4 | #define _level_keyvalues_included |
5 | 5 |
|
6 | | -/** |
7 | | - * Returns a copy of the KeyValues associated with the entity of a specified Hammer ID. |
8 | | - * The KeyValues handle returned by the native is read-only; any changes made do not propagate |
9 | | - * up to the shared plugin. |
10 | | - */ |
11 | | -native KeyValues LevelEntity_GetKeysByHammerID(int iHammerID); |
| 6 | +#include <more_adt> |
12 | 7 |
|
13 | | -/** |
14 | | - * A KeyValues-backed handle that returns and iterates over keys that match the given output |
15 | | - * name, parsing the output value into its components while being iterated. |
| 8 | +/** |
| 9 | + * Wrapper for StringMultiMap that uses an intermediary parsing step to ensure all values are |
| 10 | + * strings. |
16 | 11 | */ |
17 | | -methodmap LevelEntityOutputIterator < KeyValues { |
18 | | - /** |
19 | | - * Creates an output iterator for a given Hammer ID. |
20 | | - */ |
21 | | - public LevelEntityOutputIterator(int hammerID, const char[] output) { |
22 | | - KeyValues outputs = LevelEntity_GetKeysByHammerID(hammerID); |
23 | | - if (outputs) { |
24 | | - char keyBuffer[128], valueBuffer[128]; |
25 | | - outputs.GotoFirstSubKey(false); |
26 | | - bool bNext; |
27 | | - do { |
28 | | - outputs.GetSectionName(keyBuffer, sizeof(keyBuffer)); |
29 | | - outputs.GetString(NULL_STRING, valueBuffer, sizeof(valueBuffer)); |
30 | | - |
31 | | - if (!StrEqual(keyBuffer, output)) { |
32 | | - bNext = outputs.DeleteThis() != -1; |
33 | | - } else { |
34 | | - bNext = outputs.GotoNextKey(false); |
35 | | - } |
36 | | - } while (bNext); |
37 | | - outputs.GotoFirstSubKey(false); |
38 | | - } |
39 | | - return view_as<LevelEntityOutputIterator>(outputs); |
| 12 | +methodmap LevelEntityKeyValues < StringMultiMap { |
| 13 | + public LevelEntityKeyValues() { |
| 14 | + return view_as<LevelEntityKeyValues>(new StringMultiMap()); |
40 | 15 | } |
41 | 16 |
|
42 | | - /** |
43 | | - * Returns an output iterator for a given entity (reference), looking it up by its Hammer |
44 | | - * ID. |
45 | | - */ |
46 | | - public static LevelEntityOutputIterator FromEntity(int entref, const char[] output) { |
47 | | - int entity = EntRefToEntIndex(entref); |
48 | | - return new LevelEntityOutputIterator(GetEntProp(entity, Prop_Data, "m_iHammerID"), |
49 | | - output); |
50 | | - } |
51 | | - |
52 | | - /** |
53 | | - * Parses the current output string, storing the values by reference and advancing to the |
54 | | - * next key. |
55 | | - */ |
56 | | - public bool Next(char[] targetName, int targetNameLength, |
57 | | - char[] inputName, int inputNameLength, char[] variantValue, int variantValueLength, |
58 | | - float &delay, int &nFireCount) { |
59 | | - char outputString[512]; |
60 | | - this.GetString(NULL_STRING, outputString, sizeof(outputString)); |
61 | | - |
62 | | - // this.GoBack() is a disgusting hack just to make sure it returns true on the last item |
63 | | - return ParseEntityOutputString(outputString, targetName, targetNameLength, inputName, |
64 | | - inputNameLength, variantValue, variantValueLength, delay, nFireCount) |
65 | | - && (this.GotoNextKey(false) || this.GoBack()); |
66 | | - } |
| 17 | + // TODO implementation -- for now make sure that you only use the string-related |
| 18 | + // getters / setters in StringMultiMap. |
67 | 19 | } |
68 | 20 |
|
| 21 | +/** |
| 22 | + * Called when a block of entity keys is finished parsing. |
| 23 | + * Changes to the StringMultiMap will be reflected in the level. |
| 24 | + * |
| 25 | + * @return Plugin_Changed to copy back changed values, Plugin_Stop to remove the entity. |
| 26 | + */ |
| 27 | +forward Action LevelEntity_OnEntityKeysParsed(LevelEntityKeyValues entity); |
| 28 | + |
| 29 | +/** |
| 30 | + * Called when the entity string in `OnLevelInit` has been fully parsed out. |
| 31 | + * Plugins may call LevelEntity_InsertEntityKeys here to insert new entities into the entity |
| 32 | + * string. |
| 33 | + */ |
| 34 | +forward void LevelEntity_OnAllEntitiesParsed(); |
| 35 | + |
| 36 | +/** |
| 37 | + * Adds a new entity entry. All values should be strings. |
| 38 | + */ |
| 39 | +native void LevelEntity_InsertEntityKeys(LevelEntityKeyValues entity); |
| 40 | + |
| 41 | +/** |
| 42 | + * Returns a copy of the KeyValues associated with the entity of a specified Hammer ID. |
| 43 | + * Any changes to the returned StringMultiMap handle will not be reflected in the level. |
| 44 | + */ |
| 45 | +native LevelEntityKeyValues LevelEntity_GetKeysByHammerID(int iHammerID); |
| 46 | + |
69 | 47 | /** |
70 | 48 | * Returns a copy of the KeyValues associated with a given entity. |
71 | 49 | */ |
72 | | -stock KeyValues LevelEntity_GetKeysByEntity(int entref) { |
| 50 | +stock LevelEntityKeyValues LevelEntity_GetKeysByEntity(int entref) { |
73 | 51 | int entity = EntRefToEntIndex(entref); |
74 | 52 | return LevelEntity_GetKeysByHammerID(GetEntProp(entity, Prop_Data, "m_iHammerID")); |
75 | 53 | } |
|
0 commit comments