Skip to content

Commit

Permalink
Fix Config Creation/Updating
Browse files Browse the repository at this point in the history
  • Loading branch information
CADIndie committed Aug 9, 2024
1 parent bec4914 commit 8372df7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 43 deletions.
37 changes: 20 additions & 17 deletions Assets/Scenes/Main.unity
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ RectTransform:
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: -40, y: 0}
m_SizeDelta: {x: -40, y: 35.420013}
m_Pivot: {x: 0, y: 1}
--- !u!114 &21137409
MonoBehaviour:
Expand Down Expand Up @@ -11538,7 +11538,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!114 &668226022
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -13385,6 +13385,7 @@ MonoBehaviour:
supportedVersions: []
uiHandler: {fileID: 1460469782}
instancesDropdown: {fileID: 194192002}
configHandler: {fileID: 766335867}
--- !u!4 &766335866
Transform:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -13414,6 +13415,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
windowHandler: {fileID: 1460469781}
devHandler: {fileID: 1460469780}
configPath:
--- !u!1 &769034882
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -13954,9 +13956,9 @@ RectTransform:
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_SizeDelta: {x: -17, y: 0}
m_Pivot: {x: 0, y: 1}
--- !u!114 &790450252
MonoBehaviour:
Expand Down Expand Up @@ -14587,7 +14589,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &821339274
RectTransform:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -16547,8 +16549,8 @@ RectTransform:
m_Father: {fileID: 1878022783}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 0.095727205}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 20, y: 20}
m_Pivot: {x: 0.5, y: 0.5}
Expand Down Expand Up @@ -17157,7 +17159,7 @@ MonoBehaviour:
m_fontColor32:
serializedVersion: 2
rgba: 4284572001
m_fontColor: {r: 0.381132, g: 0.381132, b: 0.381132, a: 1}
m_fontColor: {r: 0.8, g: 0.8, b: 0.8, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
Expand Down Expand Up @@ -21172,7 +21174,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &1096674383
RectTransform:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -25343,7 +25345,7 @@ RectTransform:
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 0, y: -0}
m_SizeDelta: {x: 948.57, y: 0}
m_SizeDelta: {x: 948.57, y: 370.01}
m_Pivot: {x: 0, y: 1}
--- !u!114 &1276876736
MonoBehaviour:
Expand Down Expand Up @@ -25399,8 +25401,8 @@ MonoBehaviour:
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4284572001
m_fontColor: {r: 0.381132, g: 0.381132, b: 0.381132, a: 1}
rgba: 4291611852
m_fontColor: {r: 0.8018868, g: 0.8018868, b: 0.8018868, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
Expand Down Expand Up @@ -29455,6 +29457,7 @@ MonoBehaviour:
_ramSetterToggle: {fileID: 659075708}
_ramSetterField: {fileID: 1068650133}
configHandler: {fileID: 766335867}
configPath:
--- !u!114 &1460469781
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -30713,7 +30716,7 @@ RectTransform:
m_GameObject: {fileID: 1588127158}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0.00008946657}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalScale: {x: 0.99999994, y: 0.99999994, z: 0.99999994}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 460482963}
Expand All @@ -30722,7 +30725,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.5}
m_AnchorMax: {x: 0, y: 0.5}
m_AnchoredPosition: {x: 594, y: -214.1}
m_AnchoredPosition: {x: 594, y: -214.09998}
m_SizeDelta: {x: 201.2, y: 55}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1588127160
Expand Down Expand Up @@ -33401,7 +33404,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!114 &1748472356
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -36820,7 +36823,7 @@ Canvas:
m_Enabled: 1
serializedVersion: 3
m_RenderMode: 2
m_Camera: {fileID: 879282675}
m_Camera: {fileID: 1079186319}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_ReceivesEvents: 1
Expand Down Expand Up @@ -42770,7 +42773,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!114 &2040011914
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
29 changes: 16 additions & 13 deletions Assets/Scripts/ConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ public class ConfigHandler : MonoBehaviour
public WindowHandler windowHandler;
public DevHandler devHandler;
public Config config;
public static string configPath;

private void Start()
{
configPath = Application.persistentDataPath + "/launcher.conf";
}
public string configPath;

public void LoadConfig()
{
configPath = Application.persistentDataPath + "/launcher.conf";

if (File.Exists(configPath))
{
config = JsonConvert.DeserializeObject<Config>(configPath);
string configFile = File.ReadAllText(configPath);
config = JsonConvert.DeserializeObject<Config>(configFile);

if (!config.acceptedLegal) { windowHandler.LegalSetter(); }
if (config.setDevMods) { devHandler._devToggle.isOn = true; }
Expand All @@ -31,20 +29,25 @@ public void LoadConfig()
}
else
{
config.acceptedLegal = false;
config.setDevMods = false;
config.setCustomRAM = false;
config.customRAMValue = "2048";
config = new Config
{
acceptedLegal = false,
setDevMods = false,
setCustomRAM = false,
customRAMValue = "2048"
};

string JSON = JsonConvert.SerializeObject(config, Formatting.Indented);
File.WriteAllText(configPath, JSON);
config = JsonConvert.DeserializeObject<Config>(configPath);
string configFile = File.ReadAllText(configPath);
config = JsonConvert.DeserializeObject<Config>(configFile);
}
}

public void SetMemoryValue()
{
config = JsonConvert.DeserializeObject<Config>(configPath);
string configFile = File.ReadAllText(configPath);
config = JsonConvert.DeserializeObject<Config>(configFile);
string ramValue = devHandler._ramSetterField.text;

if (ramValue != null)
Expand Down
27 changes: 14 additions & 13 deletions Assets/Scripts/DevHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

public class DevHandler : MonoBehaviour
{
private const string DEVELOPER_MODS_PARAMETER_NAME = "developerMods";
private const string CUSTOM_RAM_PARAMETER_NAME = "customRAMValue";

[SerializeField, FormerlySerializedAs("DevToggle")]
public Toggle _devToggle;
[SerializeField, FormerlySerializedAs("ADBToggle")]
Expand All @@ -20,10 +17,12 @@ public class DevHandler : MonoBehaviour
public TMP_InputField _ramSetterField;

public ConfigHandler configHandler;
public string configPath;

private void Start()
{
InitializeButtonListeners();
configPath = Application.persistentDataPath + "/launcher.conf";
}

private void OnDestroy()
Expand All @@ -45,23 +44,25 @@ private void DisposeButtonListeners()

private void OnDevModsToggleValueChanged(bool isOn)
{
configHandler.config = JsonConvert.DeserializeObject<ConfigHandler.Config>(ConfigHandler.configPath);

JNIStorage.apiClass.SetStatic(DEVELOPER_MODS_PARAMETER_NAME, isOn);
JNIStorage.instance.UpdateInstances();
string configFile = File.ReadAllText(configPath);
configHandler.config = JsonConvert.DeserializeObject<ConfigHandler.Config>(configFile);
configHandler.config.setDevMods = isOn;
string JSON = JsonConvert.SerializeObject(configHandler.config, Formatting.Indented);
File.WriteAllText(ConfigHandler.configPath, JSON);
File.WriteAllText(configPath, JSON);

JNIStorage.apiClass.SetStatic("developerMods", isOn);
JNIStorage.instance.UpdateInstances();
}

private void OnRamSetterToggleValueChanged(bool isOn)
{
configHandler.config = JsonConvert.DeserializeObject<ConfigHandler.Config>(ConfigHandler.configPath);

JNIStorage.apiClass.SetStatic(CUSTOM_RAM_PARAMETER_NAME, isOn);
_ramSetterField.gameObject.SetActive(isOn);
string configFile = File.ReadAllText(configPath);
configHandler.config = JsonConvert.DeserializeObject<ConfigHandler.Config>(configFile);
configHandler.config.setCustomRAM = isOn;
string JSON = JsonConvert.SerializeObject(configHandler.config, Formatting.Indented);
File.WriteAllText(ConfigHandler.configPath, JSON);
File.WriteAllText(configPath, JSON);

JNIStorage.apiClass.SetStatic("customRAMValue", isOn);
_ramSetterField.gameObject.SetActive(isOn);
}
}

0 comments on commit 8372df7

Please sign in to comment.