Closed YakaryBovine closed 2 years ago
If I understand correctly you want the ability to get an object's property, even if its value has not been modified?
Currently if you try this it throws because the key is not found in the modifications dictionary. This would require a change to LevelObjectDataModifications/SimpleObjectDataModifications/VariationObjectDataModifications (https://github.com/Drake53/War3Api/tree/master/src/War3Api.Generator.Object/Classes).
To change this behaviour, first you need to have access to all the default values and store them somewhere. Then the dict access should be changed to TryGetValue and have a fallback to the default values. I think it should be possible to re-use the ObjectDatabase class for this.
The fallback should also be used for object references, for example for a unit's AbilitiesNormal property. This requires a similar change in ObjectDatabase.GetObject.
Ideally there should also be a way to see if the value you got is the default value or if it's modified (in WE's object editor you can see this because the font color of modified properties is changed). This could be done by adding another public bool property for all properties that checks ContainsKey (for example for property TextName add "public bool IsTextNameModified => _modifications.ContainsKey(id);").
If I understand correctly you want the ability to get an object's property, even if its value has not been modified?
Less than that: I merely want to be able to check if an object property has been modified (i.e., whether or not the key exists).
That said, being able to do what you say would be far superior and I would make great use of it. I can make a PR if it would be helpful; it looks like the default values can be retrieved from a combination of UnitData.slk, UnitBalance.slk, and UnitAbilities.slk. I wonder why they're separated.
I have added IsModified properties: https://github.com/Drake53/War3Api/commit/e0de38cb97434278e29a5dbdfdaa4dc6bee9342b
Not tested yet so let me know if you encounter a bug.
Awesome, thanks. I've tried it out against a large dataset and everything seems to work well. I'll open another issue later regarding the default value fallback!
I'm now able to read and edit object data efficiently using War3Api.Object, but I have one major obstacle: I'm unable to check to see if an object has a particular field before editing it. This ability would be extremely useful for sanity checking. For instance, I could check to see if a unit's repair gold cost is equal to its gold cost, and change it if it isn't.
I have absolutely no idea how to accomplish this.