Skip to content

Commit

Permalink
Update to framework library
Browse files Browse the repository at this point in the history
Moved DV settings to internal library support
  • Loading branch information
Earthfiredrake committed Jul 24, 2020
2 parents b08f57f + 42c9576 commit d0fc299
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 65 deletions.
43 changes: 4 additions & 39 deletions efd/FreeHUD/FreeHUD.as
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Released under the terms of the MIT License
// https://github.com/Earthfiredrake/SWL-FreeHUD

import com.GameInterface.DistributedValue;
import com.GameInterface.Game.Character;
import com.GameInterface.Game.Shortcut;
import com.GameInterface.Game.ShortcutData;
Expand Down Expand Up @@ -51,10 +50,10 @@ class efd.FreeHUD.FreeHUD extends Mod {
public function FreeHUD(hostMovie:MovieClip) {
super(GetModInfo(), hostMovie);
Config.NewSetting("CooldownLayout", GetDefaultLayout());
Config.NewSetting("HideReady", false);
Config.NewSetting("HideOutOfCombat", true);
Config.NewSetting("ShowSGReloads", true);
Config.NewSetting("ShowSGHotkeys", true);
Config.NewSetting("HideReady", false, "");
Config.NewSetting("HideOutOfCombat", true, "");
Config.NewSetting("ShowSGReloads", true, "");
Config.NewSetting("ShowSGHotkeys", true, "");

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

Expand Down Expand Up @@ -107,20 +106,6 @@ class efd.FreeHUD.FreeHUD extends Mod {
}

private function LoadComplete():Void {
// TODO: Setting DVs are frequently used, see about adding feature into lib.Config
HideReadyDV = DistributedValue.Create(DVPrefix + ModName + "HideReady");
HideReadyDV.SetValue(Config.GetValue("HideReady"));
HideReadyDV.SignalChanged.Connect(HideReadyChanged, this);
HideOutOfCombatDV = DistributedValue.Create(DVPrefix + ModName + "HideOutOfCombat");
HideOutOfCombatDV.SetValue(Config.GetValue("HideOutOfCombat"));
HideOutOfCombatDV.SignalChanged.Connect(HideOutOfCombatChanged, this);
SGReloadsDV = DistributedValue.Create(DVPrefix + ModName + "ShowSGReloads");
SGReloadsDV.SetValue(Config.GetValue("ShowSGReloads"));
SGReloadsDV.SignalChanged.Connect(SGReloadsChanged, this);
SGHotkeysDV = DistributedValue.Create(DVPrefix + ModName + "ShowSGHotkeys");
SGHotkeysDV.SetValue(Config.GetValue("ShowSGHotkeys"));
SGHotkeysDV.SignalChanged.Connect(SGHotkeysChanged, this);

GlobalSignal.SignalSetGUIEditMode.Connect(ToggleGEM, this);
var clientChar:Character = Character.GetClientCharacter();
clientChar.SignalToggleCombat.Connect(UpdateWrapperVisibility, this);
Expand Down Expand Up @@ -182,22 +167,6 @@ class efd.FreeHUD.FreeHUD extends Mod {
}
}

private function HideReadyChanged(dv:DistributedValue):Void {
Config.SetValue("HideReady", dv.GetValue());
}

private function HideOutOfCombatChanged(dv:DistributedValue):Void {
Config.SetValue("HideOutOfCombat", dv.GetValue());
}

private function SGReloadsChanged(dv:DistributedValue):Void {
Config.SetValue("ShowSGReloads", dv.GetValue());
}

private function SGHotkeysChanged(dv:DistributedValue):Void {
Config.SetValue("ShowSGHotkeys", dv.GetValue());
}

private function UpdateMod(newVersion:String, oldVersion:String):Void {
UpdateLayoutArray();
}
Expand Down Expand Up @@ -303,9 +272,5 @@ class efd.FreeHUD.FreeHUD extends Mod {

private var CooldownWrapper:MovieClip;
private var CooldownViews:Array;
private var HideReadyDV:DistributedValue;
private var HideOutOfCombatDV:DistributedValue;
private var SGReloadsDV:DistributedValue;
private var SGHotkeysDV:DistributedValue;
private var Equipment:Inventory;
}
3 changes: 2 additions & 1 deletion efd/FreeHUD/lib/DebugUtils.as
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018, Earthfiredrake
// Copyright 2018-2020, Earthfiredrake
// Released under the terms of the MIT License
// https://github.com/Earthfiredrake/SWL-FrameworkMod

Expand Down Expand Up @@ -76,6 +76,7 @@ import com.Utils.Signal;
IsDev = Character.GetClientCharacter().GetName() == devName;
SignalFatalError = new Signal();

// Avoid using DV generation util function to avoid stomping values on reload
GlobalDebugDV = DistributedValue.Create("emfDebugMode");
GlobalDebugDV.SignalChanged.Connect(SetDebugMode);
LocalDebugDV = DistributedValue.Create(dvPrefix + modName + "DebugMode");
Expand Down
38 changes: 24 additions & 14 deletions efd/FreeHUD/lib/Mod.as
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2017-2018, Earthfiredrake
// Copyright 2017-2020, Earthfiredrake
// Released under the terms of the MIT License
// https://github.com/Earthfiredrake/SWL-FrameworkMod

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

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

ModListDV = DistributedValue.Create("emfListMods");
ModListDV.SignalChanged.Connect(ReportVersion, this);
ModListDV = CreateFrameworkDV("ListMods", false, ReportVersion, this);

LocaleManager.Initialize();
LocaleManager.SignalStringsLoaded.Connect(StringsLoaded, this);
Expand Down Expand Up @@ -196,7 +192,7 @@ import com.Utils.Signal;
for (var key:String in SystemsLoaded) {
if (!SystemsLoaded[key]) { Debug.ErrorMsg("Missing: " + key, { noHeader : true }); }
}
}
}
dv.SetValue(false);
return;
}
Expand Down Expand Up @@ -238,6 +234,22 @@ import com.Utils.Signal;
if (dv.GetValue()) { dv.SetValue(false); }
}

/// DistributedValue Utility Functions
public function CreateFrameworkDV(dvName:String, initialValue:Object, callback:Function, callbackContext:Object):DistributedValue {
return CreateDV("emf" + dvName, initialValue, callback, callbackContext);
}

public function CreateModDV(dvName:String, initialValue:Object, callback:Function, callbackContext:Object):DistributedValue {
return CreateDV(DVPrefix + ModName + dvName, initialValue, callback, callbackContext);
}

public static function CreateDV(dvName:String, initialValue:Object, callback:Function, callbackContext:Object):DistributedValue {
var dv:DistributedValue = DistributedValue.Create(dvName);
dv.SetValue(initialValue);
if (callback != undefined) { dv.SignalChanged.Connect(callback, callbackContext); }
return dv;
}

/// Configuration Settings
private function ConfigLoaded():Void {
Config.SignalValueChanged.Connect(ConfigChanged, this);
Expand Down Expand Up @@ -345,13 +357,11 @@ import com.Utils.Signal;
public static var DevName:String = "Peloprata";
public static var DVPrefix:String = "efd";

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

public function get ModEnabledVarName():String { return DVPrefix + ModName + "Enabled"; }
private var ModEnabledDV:DistributedValue; // Doesn't reflect game toggles, only the player or internal mod disabling
private var EnabledByGame:Boolean = false;
private var Enabled:Boolean = false; // PlayerEnabled && GameEnabled
Expand Down
7 changes: 3 additions & 4 deletions efd/FreeHUD/lib/sys/ConfigManager.as
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018, Earthfiredrake
// Copyright 2018-2020, Earthfiredrake
// Released under the terms of the MIT License
// https://github.com/Earthfiredrake/SWL-FrameworkMod

Expand Down Expand Up @@ -38,13 +38,12 @@ import com.Utils.Archive;
}

public function ConfigManager(mod:Mod, initObj:Object) {
Config = new ConfigWrapper(initObj.ArchiveName);
Config = new ConfigWrapper(initObj.ArchiveName, WeakDelegate.Create(mod, mod.CreateModDV));
mod.Config = Config;

UpdateManager = new Versioning(mod, initObj);

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

ConfigWindow = Window.Create(mod, {WindowName : "ConfigWindow", LoadEvent : WeakDelegate.Create(this, ConfigWindowLoaded)});
}
Expand Down
6 changes: 2 additions & 4 deletions efd/FreeHUD/lib/sys/Window.as
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018, Earthfiredrake
// Copyright 2018-2020, Earthfiredrake
// Released under the terms of the MIT License
// https://github.com/Earthfiredrake/SWL-FrameworkMod

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

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

private function CheckResizeLimits(limits:Object):Boolean {
Expand Down
25 changes: 22 additions & 3 deletions efd/FreeHUD/lib/sys/config/ConfigWrapper.as
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2018, Earthfiredrake
// Copyright 2017-2020, Earthfiredrake
// Released under the terms of the MIT License
// https://github.com/Earthfiredrake/SWL-FrameworkMod
// Based off of the Preferences class of El Torqiro's ModUtils library:
Expand Down Expand Up @@ -30,9 +30,10 @@ import com.Utils.Signal;
// ArchiveName is distributed value name used by top level config wrappers
// Leave archiveName undefined for nested config wrappers (unless they are saved externally)
// Also leave undefined if loading/saving to the default config specified in Modules.xml
public function ConfigWrapper(archiveName:String) {
public function ConfigWrapper(archiveName:String, dvGenFunc:Function) {
Debug = new DebugUtils("Config");
ArchiveName = archiveName;
CreateModDV = dvGenFunc;
Settings = new Object();
SignalValueChanged = new Signal();
SignalConfigLoaded = new Signal();
Expand All @@ -43,7 +44,12 @@ import com.Utils.Signal;
// - If a module needs to add additional settings it should either:
// - Provide a subconfig wrapper, if the settings are specific to the mod
// - Provide its own archive, if it's a static module that can share the settings between uses
public function NewSetting(key:String, defaultValue):Void {
// - dvName is optional, for exposing a config setting with a DistributedValue (for /setoption)
// - This should only be used for simple types (numbers and strings), not objects or collections
// - undefined will result in no DistributedValue being created
// - "" will result in a prefixed dv based on the key name
// - any other string will be used as the base for a prefixed dv name
public function NewSetting(key:String, defaultValue, dvName:String):Void {
if (key == "ArchiveType") { Debug.ErrorMsg("'" + key + "' is a reserved setting name."); return; } // Reserved
if (Settings[key] != undefined) { Debug.TraceMsg("Setting '" + key + "' redefined, existing definition will be overwritten."); }
if (IsLoaded) { Debug.TraceMsg("Setting '" + key + "' added after loading archive will have default values."); }
Expand All @@ -56,6 +62,15 @@ import com.Utils.Signal;
// Change event is raised, as the setting may be created after the initialization step
// Initialization creation should occur prior to change events being hooked to avoid incidental notifications at that time
SignalValueChanged.Emit(key, defaultValue); // oldValue will be undefined (not to be used to identify this situation though)

// Generate DV
if (dvName != undefined) {
if (dvName == "") { dvName = key; }
var callback = function(dv:DistributedValue):Void {
SetValue(key, dv.GetValue());
};
Settings[key].dv = CreateModDV(dvName, defaultValue, callback, this);
}
}

public function DeleteSetting(key:String):Void {
Expand Down Expand Up @@ -99,6 +114,7 @@ import com.Utils.Signal;
if (value instanceof Point && oldVal.equals(value)) { return oldVal; }
Settings[key].value = value;
DirtyFlag = true;
Settings[key].dv.SetValue(value);
SignalValueChanged.Emit(key, value, oldVal);
}
return value;
Expand Down Expand Up @@ -129,6 +145,7 @@ import com.Utils.Signal;
// oldValue is optional, and may not be provided
public function NotifyChange(key:String, oldValue):Void {
DirtyFlag = true;
// Would flag changes for DV here, but composite items should not have DVs
SignalValueChanged.Emit(key, GetValue(key), oldValue);
}

Expand Down Expand Up @@ -308,5 +325,7 @@ import com.Utils.Signal;
private var CurrentArchive:Archive;
private var DirtyFlag:Boolean = false;

private var CreateModDV:Function;

private var Debug:DebugUtils;
}

0 comments on commit d0fc299

Please sign in to comment.