7 protected string m_sGuid;
10 protected string m_sName;
46 class SCR_WorkshopAddonPreset
52 protected ref array<ref SCR_WorkshopAddonPresetAddonMeta> m_aAddonsMeta;
62 void SetName(
string name)
70 SCR_WorkshopAddonPreset
Init(
string name, notnull array<ref SCR_WorkshopAddonPresetAddonMeta> addons)
75 foreach (
auto meta : addons)
76 m_aAddonsMeta.Insert(meta.Copy());
83 SCR_WorkshopAddonPreset
Copy()
85 SCR_WorkshopAddonPreset a = (
new SCR_WorkshopAddonPreset).
Init(
m_sName, m_aAddonsMeta);
93 return m_aAddonsMeta.Count();
98 array<ref SCR_WorkshopAddonPresetAddonMeta> GetAddons()
100 array<ref SCR_WorkshopAddonPresetAddonMeta> outArray = {};
101 foreach (
auto m : m_aAddonsMeta)
116 protected int m_iVersion;
119 protected ref array<ref SCR_WorkshopAddonPreset> m_aPresets;
122 protected string m_sUsedPreset;
124 const int VERSION = 1;
125 const string FILE_NAME =
"$profile:.WorkshopPresets.json";
127 protected ref ScriptInvoker<string, string> Event_OnUsedPresetChanged;
130 protected void InvokeEventOnUsedPresetChanged(
string arg0)
132 if (Event_OnUsedPresetChanged)
133 Event_OnUsedPresetChanged.Invoke(arg0);
137 ScriptInvoker GetEventOnUsedPresetChanged()
139 if (!Event_OnUsedPresetChanged)
140 Event_OnUsedPresetChanged =
new ScriptInvoker();
142 return Event_OnUsedPresetChanged;
150 ReadPresetsFromStorage();
159 array<ref SCR_WorkshopAddonPreset> GetAllPresets()
161 array<ref SCR_WorkshopAddonPreset> arrayOut = {};
163 foreach (SCR_WorkshopAddonPreset preset :
m_aPresets)
165 arrayOut.Insert(preset);
173 void SavePreset(notnull SCR_WorkshopAddonPreset preset,
string prevName =
"")
175 string name = preset.GetName();
177 int id = GetPresetId(name);
179 preset.SetName(name.Trim());
184 SCR_WorkshopAddonPreset presetCopy = preset.Copy();
191 if (CanChangePresetName(
id, name, prevName))
195 SavePresetsToStorage();
199 protected bool CanChangePresetName(
int id,
string name,
string prevName)
206 if (name == GetUsedPreset() || prevName ==
"")
213 void SetUsedPreset(
string name)
215 m_sUsedPreset = name;
216 SavePresetsToStorage();
218 InvokeEventOnUsedPresetChanged(name);
222 void ClearUsedPreset()
228 string GetUsedPreset()
230 return m_sUsedPreset;
234 void DeletePreset(
string name)
236 int id = GetPresetId(name);
243 SavePresetsToStorage();
245 if (name == m_sUsedPreset)
250 bool PresetExists(
string name)
252 return GetPresetId(name) != -1;
257 SCR_WorkshopAddonPreset GetPreset(
string name)
259 int id = GetPresetId(name);
268 array<ref SCR_WorkshopAddonPreset> GetPresets()
278 protected bool ReadPresetsFromStorage()
280 BaseContainer allPresetsContainer =
GetGame().GetGameUserSettings().GetModule(
"SCR_WorkshopAddonManagerPresetStorage");
282 if (allPresetsContainer)
283 BaseContainerTools.WriteToInstance(
this, allPresetsContainer);
287 m_iVersion = VERSION;
295 protected void SavePresetsToStorage()
297 m_iVersion = VERSION;
299 BaseContainer allPresetsContainer =
GetGame().GetGameUserSettings().GetModule(
"SCR_WorkshopAddonManagerPresetStorage");
300 BaseContainerTools.ReadFromInstance(
this, allPresetsContainer);
301 GetGame().UserSettingsChanged();
306 protected int GetPresetId(
string name)
308 foreach (
int i, SCR_WorkshopAddonPreset preset :
m_aPresets)
310 if (preset.GetName() == name)