Skip to content

Commit d0fc299

Browse files
Update to framework library
Moved DV settings to internal library support
2 parents b08f57f + 42c9576 commit d0fc299

File tree

6 files changed

+57
-65
lines changed

6 files changed

+57
-65
lines changed

efd/FreeHUD/FreeHUD.as

+4-39
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Released under the terms of the MIT License
33
// https://github.com/Earthfiredrake/SWL-FreeHUD
44

5-
import com.GameInterface.DistributedValue;
65
import com.GameInterface.Game.Character;
76
import com.GameInterface.Game.Shortcut;
87
import com.GameInterface.Game.ShortcutData;
@@ -51,10 +50,10 @@ class efd.FreeHUD.FreeHUD extends Mod {
5150
public function FreeHUD(hostMovie:MovieClip) {
5251
super(GetModInfo(), hostMovie);
5352
Config.NewSetting("CooldownLayout", GetDefaultLayout());
54-
Config.NewSetting("HideReady", false);
55-
Config.NewSetting("HideOutOfCombat", true);
56-
Config.NewSetting("ShowSGReloads", true);
57-
Config.NewSetting("ShowSGHotkeys", true);
53+
Config.NewSetting("HideReady", false, "");
54+
Config.NewSetting("HideOutOfCombat", true, "");
55+
Config.NewSetting("ShowSGReloads", true, "");
56+
Config.NewSetting("ShowSGHotkeys", true, "");
5857

5958
Equipment = new Inventory(new ID32(_global.Enums.InvType.e_Type_GC_WeaponContainer, Character.GetClientCharID().GetInstance()));
6059

@@ -107,20 +106,6 @@ class efd.FreeHUD.FreeHUD extends Mod {
107106
}
108107

109108
private function LoadComplete():Void {
110-
// TODO: Setting DVs are frequently used, see about adding feature into lib.Config
111-
HideReadyDV = DistributedValue.Create(DVPrefix + ModName + "HideReady");
112-
HideReadyDV.SetValue(Config.GetValue("HideReady"));
113-
HideReadyDV.SignalChanged.Connect(HideReadyChanged, this);
114-
HideOutOfCombatDV = DistributedValue.Create(DVPrefix + ModName + "HideOutOfCombat");
115-
HideOutOfCombatDV.SetValue(Config.GetValue("HideOutOfCombat"));
116-
HideOutOfCombatDV.SignalChanged.Connect(HideOutOfCombatChanged, this);
117-
SGReloadsDV = DistributedValue.Create(DVPrefix + ModName + "ShowSGReloads");
118-
SGReloadsDV.SetValue(Config.GetValue("ShowSGReloads"));
119-
SGReloadsDV.SignalChanged.Connect(SGReloadsChanged, this);
120-
SGHotkeysDV = DistributedValue.Create(DVPrefix + ModName + "ShowSGHotkeys");
121-
SGHotkeysDV.SetValue(Config.GetValue("ShowSGHotkeys"));
122-
SGHotkeysDV.SignalChanged.Connect(SGHotkeysChanged, this);
123-
124109
GlobalSignal.SignalSetGUIEditMode.Connect(ToggleGEM, this);
125110
var clientChar:Character = Character.GetClientCharacter();
126111
clientChar.SignalToggleCombat.Connect(UpdateWrapperVisibility, this);
@@ -182,22 +167,6 @@ class efd.FreeHUD.FreeHUD extends Mod {
182167
}
183168
}
184169

185-
private function HideReadyChanged(dv:DistributedValue):Void {
186-
Config.SetValue("HideReady", dv.GetValue());
187-
}
188-
189-
private function HideOutOfCombatChanged(dv:DistributedValue):Void {
190-
Config.SetValue("HideOutOfCombat", dv.GetValue());
191-
}
192-
193-
private function SGReloadsChanged(dv:DistributedValue):Void {
194-
Config.SetValue("ShowSGReloads", dv.GetValue());
195-
}
196-
197-
private function SGHotkeysChanged(dv:DistributedValue):Void {
198-
Config.SetValue("ShowSGHotkeys", dv.GetValue());
199-
}
200-
201170
private function UpdateMod(newVersion:String, oldVersion:String):Void {
202171
UpdateLayoutArray();
203172
}
@@ -303,9 +272,5 @@ class efd.FreeHUD.FreeHUD extends Mod {
303272

304273
private var CooldownWrapper:MovieClip;
305274
private var CooldownViews:Array;
306-
private var HideReadyDV:DistributedValue;
307-
private var HideOutOfCombatDV:DistributedValue;
308-
private var SGReloadsDV:DistributedValue;
309-
private var SGHotkeysDV:DistributedValue;
310275
private var Equipment:Inventory;
311276
}

efd/FreeHUD/lib/DebugUtils.as

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018, Earthfiredrake
1+
// Copyright 2018-2020, Earthfiredrake
22
// Released under the terms of the MIT License
33
// https://github.com/Earthfiredrake/SWL-FrameworkMod
44

@@ -76,6 +76,7 @@ import com.Utils.Signal;
7676
IsDev = Character.GetClientCharacter().GetName() == devName;
7777
SignalFatalError = new Signal();
7878

79+
// Avoid using DV generation util function to avoid stomping values on reload
7980
GlobalDebugDV = DistributedValue.Create("emfDebugMode");
8081
GlobalDebugDV.SignalChanged.Connect(SetDebugMode);
8182
LocalDebugDV = DistributedValue.Create(dvPrefix + modName + "DebugMode");

efd/FreeHUD/lib/Mod.as

+24-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// Copyright 2017-2018, Earthfiredrake
1+
// Copyright 2017-2020, Earthfiredrake
22
// Released under the terms of the MIT License
33
// https://github.com/Earthfiredrake/SWL-FrameworkMod
44

5-
// Mod Framework v1.1.2
5+
// Mod Framework v1.1.3
66
// Revision numbers are for internal merge tracking only, and do not require an upgrade notification
77
// See ConfigManager for notification format for major/minor upgrades
88

@@ -35,11 +35,11 @@
3535
// Config (ConfigManager.as):
3636
// Setting serialization and change notification
3737
// Versioning and upgrade detection
38-
// Configuration window
38+
// Configuration window or DistributedValue exposure for changing settings
3939
// Icon (ModIcon.as): Icon display with topbar integration and GEM layout options
4040
// VTIOHelper: Integration with VTIO compatible mod containers and topbars
4141
// Window: Interface window management
42-
// AutoReport: Mail based reporting system for errors or other information
42+
// AutoReport: DEPRECATED Mail based reporting system for errors or other information
4343
// Subclass is responsible for:
4444
// Initialization data, including subsystems and their dependencies
4545
// Additional setting definitions
@@ -109,14 +109,10 @@ import com.Utils.Signal;
109109
SignalLoadCompleted = new Signal();
110110
SystemsLoaded = { LocalizedText: false };
111111
if (modInfo.Subsystems.Config != undefined) { SystemsLoaded.Config = false; }
112-
ModLoadedDV = DistributedValue.Create(ModLoadedVarName);
113-
ModLoadedDV.SetValue(false);
114-
ModEnabledDV = DistributedValue.Create(ModEnabledVarName);
115-
ModEnabledDV.SetValue(undefined);
116-
ModEnabledDV.SignalChanged.Connect(ModEnabledChanged, this);
112+
ModLoadedDV = CreateModDV("Loaded", false);
113+
ModEnabledDV = CreateModDV("Enabled", undefined, ModEnabledChanged, this);
117114

118-
ModListDV = DistributedValue.Create("emfListMods");
119-
ModListDV.SignalChanged.Connect(ReportVersion, this);
115+
ModListDV = CreateFrameworkDV("ListMods", false, ReportVersion, this);
120116

121117
LocaleManager.Initialize();
122118
LocaleManager.SignalStringsLoaded.Connect(StringsLoaded, this);
@@ -196,7 +192,7 @@ import com.Utils.Signal;
196192
for (var key:String in SystemsLoaded) {
197193
if (!SystemsLoaded[key]) { Debug.ErrorMsg("Missing: " + key, { noHeader : true }); }
198194
}
199-
}
195+
}
200196
dv.SetValue(false);
201197
return;
202198
}
@@ -238,6 +234,22 @@ import com.Utils.Signal;
238234
if (dv.GetValue()) { dv.SetValue(false); }
239235
}
240236

237+
/// DistributedValue Utility Functions
238+
public function CreateFrameworkDV(dvName:String, initialValue:Object, callback:Function, callbackContext:Object):DistributedValue {
239+
return CreateDV("emf" + dvName, initialValue, callback, callbackContext);
240+
}
241+
242+
public function CreateModDV(dvName:String, initialValue:Object, callback:Function, callbackContext:Object):DistributedValue {
243+
return CreateDV(DVPrefix + ModName + dvName, initialValue, callback, callbackContext);
244+
}
245+
246+
public static function CreateDV(dvName:String, initialValue:Object, callback:Function, callbackContext:Object):DistributedValue {
247+
var dv:DistributedValue = DistributedValue.Create(dvName);
248+
dv.SetValue(initialValue);
249+
if (callback != undefined) { dv.SignalChanged.Connect(callback, callbackContext); }
250+
return dv;
251+
}
252+
241253
/// Configuration Settings
242254
private function ConfigLoaded():Void {
243255
Config.SignalValueChanged.Connect(ConfigChanged, this);
@@ -345,13 +357,11 @@ import com.Utils.Signal;
345357
public static var DevName:String = "Peloprata";
346358
public static var DVPrefix:String = "efd";
347359

348-
public function get ModLoadedVarName():String { return DVPrefix + ModName + "Loaded"; }
349360
public var ModLoadedDV:DistributedValue; // Locks-out interface when mod fails to load, may also be used for basic cross-mod integration
350361
public var SystemsLoaded:Object; // Tracks asynchronous data loads so that functions aren't called without proper data, removed once loading complete
351362
public var FatalError:String;
352363
public var SignalLoadCompleted:Signal;
353364

354-
public function get ModEnabledVarName():String { return DVPrefix + ModName + "Enabled"; }
355365
private var ModEnabledDV:DistributedValue; // Doesn't reflect game toggles, only the player or internal mod disabling
356366
private var EnabledByGame:Boolean = false;
357367
private var Enabled:Boolean = false; // PlayerEnabled && GameEnabled

efd/FreeHUD/lib/sys/ConfigManager.as

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018, Earthfiredrake
1+
// Copyright 2018-2020, Earthfiredrake
22
// Released under the terms of the MIT License
33
// https://github.com/Earthfiredrake/SWL-FrameworkMod
44

@@ -38,13 +38,12 @@ import com.Utils.Archive;
3838
}
3939

4040
public function ConfigManager(mod:Mod, initObj:Object) {
41-
Config = new ConfigWrapper(initObj.ArchiveName);
41+
Config = new ConfigWrapper(initObj.ArchiveName, WeakDelegate.Create(mod, mod.CreateModDV));
4242
mod.Config = Config;
4343

4444
UpdateManager = new Versioning(mod, initObj);
4545

46-
ResetDV = DistributedValue.Create(Mod.DVPrefix + mod.ModName + "ResetConfig");
47-
ResetDV.SignalChanged.Connect(ResetConfig, this);
46+
ResetDV = mod.CreateModDV("ResetConfig", false, ResetConfig, this);
4847

4948
ConfigWindow = Window.Create(mod, {WindowName : "ConfigWindow", LoadEvent : WeakDelegate.Create(this, ConfigWindowLoaded)});
5049
}

efd/FreeHUD/lib/sys/Window.as

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018, Earthfiredrake
1+
// Copyright 2018-2020, Earthfiredrake
22
// Released under the terms of the MIT License
33
// https://github.com/Earthfiredrake/SWL-FrameworkMod
44

@@ -61,9 +61,7 @@ import com.Utils.WeakPtr;
6161
mod.Config.NewSetting(WindowName + "Size", new Point(-1, -1));
6262
}
6363

64-
ShowDV = DistributedValue.Create(Mod.DVPrefix + "Show" + mod.ModName + WindowName);
65-
ShowDV.SetValue(false);
66-
ShowDV.SignalChanged.Connect(ShowWindowChanged, this);
64+
ShowDV = Mod.CreateDV(Mod.DVPrefix + "Show" + mod.ModName + WindowName, false, ShowWindowChanged, this);
6765
}
6866

6967
private function CheckResizeLimits(limits:Object):Boolean {

efd/FreeHUD/lib/sys/config/ConfigWrapper.as

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017-2018, Earthfiredrake
1+
// Copyright 2017-2020, Earthfiredrake
22
// Released under the terms of the MIT License
33
// https://github.com/Earthfiredrake/SWL-FrameworkMod
44
// Based off of the Preferences class of El Torqiro's ModUtils library:
@@ -30,9 +30,10 @@ import com.Utils.Signal;
3030
// ArchiveName is distributed value name used by top level config wrappers
3131
// Leave archiveName undefined for nested config wrappers (unless they are saved externally)
3232
// Also leave undefined if loading/saving to the default config specified in Modules.xml
33-
public function ConfigWrapper(archiveName:String) {
33+
public function ConfigWrapper(archiveName:String, dvGenFunc:Function) {
3434
Debug = new DebugUtils("Config");
3535
ArchiveName = archiveName;
36+
CreateModDV = dvGenFunc;
3637
Settings = new Object();
3738
SignalValueChanged = new Signal();
3839
SignalConfigLoaded = new Signal();
@@ -43,7 +44,12 @@ import com.Utils.Signal;
4344
// - If a module needs to add additional settings it should either:
4445
// - Provide a subconfig wrapper, if the settings are specific to the mod
4546
// - Provide its own archive, if it's a static module that can share the settings between uses
46-
public function NewSetting(key:String, defaultValue):Void {
47+
// - dvName is optional, for exposing a config setting with a DistributedValue (for /setoption)
48+
// - This should only be used for simple types (numbers and strings), not objects or collections
49+
// - undefined will result in no DistributedValue being created
50+
// - "" will result in a prefixed dv based on the key name
51+
// - any other string will be used as the base for a prefixed dv name
52+
public function NewSetting(key:String, defaultValue, dvName:String):Void {
4753
if (key == "ArchiveType") { Debug.ErrorMsg("'" + key + "' is a reserved setting name."); return; } // Reserved
4854
if (Settings[key] != undefined) { Debug.TraceMsg("Setting '" + key + "' redefined, existing definition will be overwritten."); }
4955
if (IsLoaded) { Debug.TraceMsg("Setting '" + key + "' added after loading archive will have default values."); }
@@ -56,6 +62,15 @@ import com.Utils.Signal;
5662
// Change event is raised, as the setting may be created after the initialization step
5763
// Initialization creation should occur prior to change events being hooked to avoid incidental notifications at that time
5864
SignalValueChanged.Emit(key, defaultValue); // oldValue will be undefined (not to be used to identify this situation though)
65+
66+
// Generate DV
67+
if (dvName != undefined) {
68+
if (dvName == "") { dvName = key; }
69+
var callback = function(dv:DistributedValue):Void {
70+
SetValue(key, dv.GetValue());
71+
};
72+
Settings[key].dv = CreateModDV(dvName, defaultValue, callback, this);
73+
}
5974
}
6075

6176
public function DeleteSetting(key:String):Void {
@@ -99,6 +114,7 @@ import com.Utils.Signal;
99114
if (value instanceof Point && oldVal.equals(value)) { return oldVal; }
100115
Settings[key].value = value;
101116
DirtyFlag = true;
117+
Settings[key].dv.SetValue(value);
102118
SignalValueChanged.Emit(key, value, oldVal);
103119
}
104120
return value;
@@ -129,6 +145,7 @@ import com.Utils.Signal;
129145
// oldValue is optional, and may not be provided
130146
public function NotifyChange(key:String, oldValue):Void {
131147
DirtyFlag = true;
148+
// Would flag changes for DV here, but composite items should not have DVs
132149
SignalValueChanged.Emit(key, GetValue(key), oldValue);
133150
}
134151

@@ -308,5 +325,7 @@ import com.Utils.Signal;
308325
private var CurrentArchive:Archive;
309326
private var DirtyFlag:Boolean = false;
310327

328+
private var CreateModDV:Function;
329+
311330
private var Debug:DebugUtils;
312331
}

0 commit comments

Comments
 (0)