Ive got this Working in the inspector but it won't serialize when I save and reopen the project.
Base Class:
`public partial class Dict< [ MustBeVariant ] TKey, [ MustBeVariant ] TValue > : Resource {
protected TKey _newKey;
protected TValue _newValue;
protected System.Collections.Generic.Dictionary< TKey, TValue > _thisDict
= new System.Collections.Generic.Dictionary< TKey, TValue >();
// These two bools are just a quick way to add buttons to the inspector
[ Export ] bool addNewEntry { get => false; set => AddEntry(); }
[ Export ] bool removeEntry { get => false; set => RemoveEntry(); }
public Dict( ) {
}
protected bool AddEntry() {
var result = true;
if ( !_thisDict.ContainsKey( _newKey ) ) {
_thisDict.Add( _newKey, _newValue );
SetKVArrs();
_newKey = default ( TKey );
_newValue = default ( TValue );
} else {
result = false;
GD.PrintErr( this + " Already Contains an Entry For Key: " + _newKey );
}
return result;
}
protected bool RemoveEntry() {
var result = true;
if ( _thisDict.ContainsKey( _newKey ) ) {
_thisDict.Remove( _newKey );
SetKVArrs();
_newKey = default ( TKey );
_newValue = default ( TValue );
} else {
result = false;
GD.PrintErr( this + " Dosn't Contain an Entry For Key: " + _newKey );
}
return result;
}
protected void SetDict( Array< TKey > keys, Array< TValue > values ) {
for ( int i = 0; i < keys.Count; i++ ) { _thisDict.Add( keys [ i ], values [ i ] ); }
}
protected virtual void SetKVArrs() {
}
}`
Derived Class:
`public partial class SomeDict : Dict< SomeEnum, string > {
[ Export ] public SomeEnum NewKey { get { return _newKey; } set { _newKey = value; } }
[ Export ] public string NewValue { get { return _newValue; } set { _newValue = value; } }
Array<SomeEnum> _keys = new Array<SomeEnum>();
[ Export ]
public Array< SomeEnum > Keys {
get {
return _keys;
}
set {
_keys = value;
SetDict( _keys, _values );
}
}
Array< string > _values = new Array< string >();
[ Export ]
public Array< string > Values {
get {
return _values;
}
set {
_values = value;
SetDict( _keys, _values );
}
}
public SomeDict() : base() {
}
protected override void SetKVArrs() {
_keys = new Array< SomeEnum >( _thisDict.Keys.ToArray() );
_values = new Array< string >( _thisDict.Values.ToArray() );
}
}`
Test Script:
`public enum SomeEnum {
a,
b,
c
}
public partial class DictTest : Node {
[ Export ] SomeDict test = new SomeDict();
// Called when the node enters the scene tree for the first time.
public override void _Ready() {
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process( double delta ) {
}
}`
I'm not sure if the issue is that I just can't use Resources like this or not.