Add 'options' command

This commit is contained in:
Jens Pitkänen 2020-08-07 02:42:59 +03:00
parent dd4c8a2eb3
commit 92ff5c1cf3
5 changed files with 121 additions and 8 deletions

View File

@ -8107,6 +8107,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 1931179857} - {fileID: 1931179857}
- {fileID: 1262176262}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -11464,6 +11465,49 @@ Mesh:
offset: 0 offset: 0
size: 0 size: 0
path: path:
--- !u!1 &1262176261
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1262176262}
- component: {fileID: 1262176263}
m_Layer: 0
m_Name: OptionsCommand
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1262176262
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1262176261}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 875920203}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1262176263
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1262176261}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ef9117cc11410da479d1af23fbe77b23, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1349294154 --- !u!1 &1349294154
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -0,0 +1,45 @@
using UnityEngine;
using System.Diagnostics;
using System;
namespace NeonTea.Quakeball.Interface {
public class OptionsCommand : MonoBehaviour {
private void Awake() {
Terminal Terminal = Terminal.Singleton;
Terminal.RegisterCommand("options", args => {
if (args.Length == 0) {
return false;
}
switch (args[0]) {
case "explore":
Process.Start("explorer.exe", Options.GetDirectory());
return true;
case "save":
try {
Options.Save(Options.Get());
return true;
} catch (Exception ex) {
Terminal.Println($"<color={Terminal.ERROR_COLOR}>{ex.ToString()}</color>");
return false;
}
case "load":
try {
OptionsData Opts = Options.Load(true);
if (Opts != null) {
Options.Set(Opts);
return true;
} else {
Terminal.Println($"<color={Terminal.ERROR_COLOR}>No saved configuration on disk.</color>");
return false;
}
} catch (Exception ex) {
Terminal.Println($"<color={Terminal.ERROR_COLOR}>{ex.ToString()}</color>");
return false;
}
default:
return false;
}
}, "\n options explore - Opens the configuration directory in explorer.exe.\n options save - Saves the current configuration on disk.\n options load - Loads the configuration from disk.");
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ef9117cc11410da479d1af23fbe77b23
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -23,6 +23,14 @@ namespace NeonTea.Quakeball {
return Singleton; return Singleton;
} }
public static void Set(OptionsData options) {
Singleton = options;
}
public static string GetDirectory() {
return OptionsDirectory;
}
public static void Save(OptionsData options) { public static void Save(OptionsData options) {
XmlSerializer Serializer = new XmlSerializer(typeof(OptionsData)); XmlSerializer Serializer = new XmlSerializer(typeof(OptionsData));
Directory.CreateDirectory(OptionsDirectory); Directory.CreateDirectory(OptionsDirectory);
@ -31,16 +39,21 @@ namespace NeonTea.Quakeball {
OptionsFile.Close(); OptionsFile.Close();
} }
public static OptionsData Load() { public static OptionsData Load(bool nullOnNotFound = false) {
try { try {
XmlSerializer Serializer = new XmlSerializer(typeof(OptionsData)); XmlSerializer Serializer = new XmlSerializer(typeof(OptionsData));
FileStream OptionsFile = File.OpenRead(OptionsPath); FileStream OptionsFile = File.OpenRead(OptionsPath);
OptionsData Options = (OptionsData)Serializer.Deserialize(OptionsFile); OptionsData Options = (OptionsData)Serializer.Deserialize(OptionsFile);
OptionsFile.Close(); OptionsFile.Close();
return Options; return Options;
} catch (FileLoadException) { } catch (FileNotFoundException) {
} catch (Exception ex) { if (nullOnNotFound) {
Debug.LogWarning(ex); return null;
}
} catch (DirectoryNotFoundException) {
if (nullOnNotFound) {
return null;
}
} }
return new OptionsData(); return new OptionsData();
} }

View File

@ -26,17 +26,17 @@ namespace NeonTea.Quakeball.Util {
StartWaiting(); StartWaiting();
return true; return true;
} else { } else {
Terminal.Singleton.AddMessage($"<color={Terminal.ERROR_COLOR}>The 'read' command takes no arguments.</color>"); Terminal.Singleton.Println($"<color={Terminal.ERROR_COLOR}>The 'read' command takes no arguments.</color>");
return false; return false;
} }
}); }, "read - Waits for an input action, and then prints it.");
} }
private void StartWaiting() { private void StartWaiting() {
if (!InitializedFromTerminal) { if (!InitializedFromTerminal) {
Debug.Log("Waiting for InputAction to display..."); Debug.Log("Waiting for InputAction to display...");
} else { } else {
Terminal.Singleton.AddMessage("Waiting for InputAction to display..."); Terminal.Singleton.Println("Waiting for InputAction to display...");
} }
Rebinding = AnyAction.PerformInteractiveRebinding().Start(); Rebinding = AnyAction.PerformInteractiveRebinding().Start();
} }
@ -50,7 +50,7 @@ namespace NeonTea.Quakeball.Util {
if (!InitializedFromTerminal) { if (!InitializedFromTerminal) {
Debug.Log("Binding: " + Binding); Debug.Log("Binding: " + Binding);
} else { } else {
Terminal.Singleton.AddMessage("Binding: " + Binding); Terminal.Singleton.Println("Binding: " + Binding);
} }
Rebinding = null; Rebinding = null;
} }