Remove console.
This commit is contained in:
1073
Assets/Console.unity
1073
Assets/Console.unity
File diff suppressed because it is too large
Load Diff
@@ -1,8 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 8a36c371ab6077d43ac28fe09b0fe675
|
|
||||||
timeCreated: 1620725915
|
|
||||||
licenseType: Free
|
|
||||||
DefaultImporter:
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -1,157 +0,0 @@
|
|||||||
using Cryville.Common.Network.Http11;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.SceneManagement;
|
|
||||||
using UnityEngine.UI;
|
|
||||||
using Logger = Cryville.Common.Logging.Logger;
|
|
||||||
using unity = UnityEngine;
|
|
||||||
|
|
||||||
namespace Cryville.Crtr {
|
|
||||||
public class Console : MonoBehaviour {
|
|
||||||
public Text Logs;
|
|
||||||
public InputField InputBox;
|
|
||||||
CommandWorker worker;
|
|
||||||
readonly Queue<string> _fallbackQueue = new Queue<string>();
|
|
||||||
|
|
||||||
~Console() {
|
|
||||||
worker.Deactivate();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Start() {
|
|
||||||
Game.Init();
|
|
||||||
InputBox.Select();
|
|
||||||
|
|
||||||
worker = new CommandWorker(MainThreadFallback);
|
|
||||||
worker.Activate();
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnApplicationQuit() {
|
|
||||||
Game.Shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Submit() {
|
|
||||||
worker.Issue(InputBox.text);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Update() {
|
|
||||||
if (
|
|
||||||
unity::Input.GetKeyDown(KeyCode.Return)
|
|
||||||
|| unity::Input.GetKeyDown(KeyCode.KeypadEnter)
|
|
||||||
) {
|
|
||||||
Submit();
|
|
||||||
InputBox.text = "";
|
|
||||||
InputBox.Select();
|
|
||||||
InputBox.ActivateInputField();
|
|
||||||
}
|
|
||||||
if (_fallbackQueue.Count > 0) {
|
|
||||||
switch (_fallbackQueue.Dequeue()) {
|
|
||||||
case "play":
|
|
||||||
SceneManager.LoadScene("Play");
|
|
||||||
break;
|
|
||||||
case "quit":
|
|
||||||
Application.Quit();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Logger.Log("main", 4, "Console", "Unknown command. Type \"help\" for help");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
string _logs = Logs.text;
|
|
||||||
Game.MainLogger.Enumerate((level, module, msg) => {
|
|
||||||
string color;
|
|
||||||
switch (level) {
|
|
||||||
case 0: color = "#888888"; break;
|
|
||||||
case 1: color = "#bbbbbb"; break;
|
|
||||||
case 2: color = "#0088ff"; break;
|
|
||||||
case 3: color = "#ffff00"; break;
|
|
||||||
case 4: color = "#ff0000"; break;
|
|
||||||
case 5: color = "#bb0000"; break;
|
|
||||||
default: color = "#ff00ff"; break;
|
|
||||||
}
|
|
||||||
_logs += string.Format(
|
|
||||||
"\r\n\x02<color={1}ff>[{0}] <{2}> {3}</color>",
|
|
||||||
DateTime.UtcNow.ToString("s"), color, module, msg
|
|
||||||
);
|
|
||||||
});
|
|
||||||
Logs.text = _logs.Substring(Mathf.Max(0, _logs.IndexOf('\x02', Mathf.Max(0, _logs.Length - 8192))));
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainThreadFallback(string cmd) {
|
|
||||||
_fallbackQueue.Enqueue(cmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CommandWorker {
|
|
||||||
readonly Action<string> _fallback;
|
|
||||||
Thread _thread;
|
|
||||||
readonly Queue<string> _queue = new Queue<string>();
|
|
||||||
|
|
||||||
public CommandWorker(Action<string> fallback) {
|
|
||||||
_fallback = fallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Activate() {
|
|
||||||
_thread = new Thread(ThreadLoop);
|
|
||||||
_thread.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Deactivate() {
|
|
||||||
_thread.Abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Issue(string cmd) {
|
|
||||||
lock (_queue) {
|
|
||||||
_queue.Enqueue(cmd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ThreadLoop() {
|
|
||||||
while (true) {
|
|
||||||
string cmd = null;
|
|
||||||
lock (_queue) {
|
|
||||||
if (_queue.Count > 0) cmd = _queue.Dequeue();
|
|
||||||
}
|
|
||||||
if (cmd != null) ProcessCommand(cmd);
|
|
||||||
else Thread.Sleep(20);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProcessCommand(string cmd) {
|
|
||||||
Logger.Log("main", 2, "Console", "Command processing: {0}", cmd);
|
|
||||||
var p = cmd.Split(' ');
|
|
||||||
try {
|
|
||||||
switch (p[0]) {
|
|
||||||
case "!http":
|
|
||||||
var httpcl = new Http11Client(new Uri(p[1]));
|
|
||||||
httpcl.Connect();
|
|
||||||
httpcl.Request("GET", new Uri(p[1])).MessageBody.ReadToEnd();
|
|
||||||
httpcl.Close();
|
|
||||||
break;
|
|
||||||
case "!https":
|
|
||||||
var httpscl = new Https11Client(new Uri(p[1]));
|
|
||||||
httpscl.Connect();
|
|
||||||
httpscl.Request("GET", new Uri(p[1])).MessageBody.ReadToEnd();
|
|
||||||
httpscl.Close();
|
|
||||||
break;
|
|
||||||
case "help": case "?":
|
|
||||||
Logger.Log(
|
|
||||||
"main", 1, "Console",
|
|
||||||
"\n\thelp" +
|
|
||||||
"\n\tplay" +
|
|
||||||
"\n\tquit"
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
_fallback.Invoke(cmd);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
Logger.Log("main", 4, "Console", "{0}", ex);
|
|
||||||
}
|
|
||||||
Logger.Log("main", 2, "Console", "Command done: {0}", cmd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 069c1a41e65819549b4dfcda4e619b76
|
|
||||||
timeCreated: 1620726427
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
Reference in New Issue
Block a user