Add help, and add client to netchaperone
This commit is contained in:
parent
f2e872e7aa
commit
6756bf7d26
File diff suppressed because one or more lines are too long
@ -21,6 +21,7 @@ namespace NeonTea.Quakeball.Interface {
|
||||
private bool IsOpen = false;
|
||||
|
||||
private Dictionary<string, Func<string[], bool>> Commands = new Dictionary<string, Func<string[], bool>>();
|
||||
private Dictionary<string, string> Helps = new Dictionary<string, string>();
|
||||
|
||||
private List<string> Messages = new List<string>();
|
||||
private string Text = "";
|
||||
@ -58,7 +59,22 @@ namespace NeonTea.Quakeball.Interface {
|
||||
CurrentScroll = -1;
|
||||
});
|
||||
|
||||
AddMessage($"<color={INFO_COLOR}>Welcome to Quakeball!</color>");
|
||||
RegisterCommand("help", args => {
|
||||
if (args.Length == 0) {
|
||||
Println($"<color={ERROR_COLOR}>Need at least 1 command to give help for</color>");
|
||||
return false;
|
||||
}
|
||||
foreach (string command in args) {
|
||||
if (Helps.ContainsKey(command)) {
|
||||
Println($"help {command}: {Helps[command]}");
|
||||
} else {
|
||||
Println($"<color={ERROR_COLOR}>command {command} not found.</color>");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
Println($"<color={INFO_COLOR}>Welcome to Quakeball!</color>");
|
||||
}
|
||||
|
||||
public void ToggleTerminal(InputAction.CallbackContext context) {
|
||||
@ -92,6 +108,14 @@ namespace NeonTea.Quakeball.Interface {
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool RegisterCommand(string name, Func<string[], bool> command, string help) {
|
||||
if (RegisterCommand(name, command)) {
|
||||
Helps.Add(name, help);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Run(string command) {
|
||||
string[] parts = command.Split(new char[] { ' ' });
|
||||
string name = parts[0];
|
||||
@ -99,22 +123,31 @@ namespace NeonTea.Quakeball.Interface {
|
||||
Func<string[], bool> func = Commands[name];
|
||||
string[] args = new string[parts.Length - 1];
|
||||
Array.Copy(parts, 1, args, 0, parts.Length - 1);
|
||||
if (func(args)) {
|
||||
AddMessage(command);
|
||||
} else {
|
||||
AddMessage($"<color={ERROR_COLOR}>{command}</color>");
|
||||
int message = Println($"> {command}");
|
||||
if (!func(args)) {
|
||||
EditPrintln(message, $"<color={ERROR_COLOR}>> {command}</color>");
|
||||
}
|
||||
} else {
|
||||
AddMessage($"<color={ERROR_COLOR}>{command}</color>");
|
||||
AddMessage("No such command exists!");
|
||||
Println($"<color={ERROR_COLOR}>> {command}</color>");
|
||||
Println("No such command exists!");
|
||||
}
|
||||
PreviousRuns.Insert(0, command);
|
||||
}
|
||||
|
||||
public void AddMessage(string message) {
|
||||
public int Println(string message) {
|
||||
Messages.Add(message);
|
||||
Text = String.Join("\n", Messages.ToArray());
|
||||
TextField.text = Text;
|
||||
return Messages.Count - 1;
|
||||
}
|
||||
|
||||
public void EditPrintln(int idx, string message) {
|
||||
if (0 > idx || idx >= Messages.Count) {
|
||||
return;
|
||||
}
|
||||
Messages[idx] = message;
|
||||
Text = String.Join("\n", Messages.ToArray());
|
||||
TextField.text = Text;
|
||||
}
|
||||
|
||||
private void Scroll(int amount) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using NeonTea.Quakeball.Interface;
|
||||
using NeonTea.Quakeball.TeaNet.Peers;
|
||||
|
||||
@ -8,25 +9,36 @@ namespace NeonTea.Quakeball.Net {
|
||||
|
||||
private Terminal Terminal;
|
||||
|
||||
private Queue<string> MessageQueue = new Queue<string>();
|
||||
|
||||
private void Start() {
|
||||
if (Terminal.Singleton != null) {
|
||||
Terminal = Terminal.Singleton;
|
||||
Terminal.RegisterCommand("host", Host);
|
||||
Terminal.RegisterCommand("host", Host, "host [<port>] [<address>] - Hosts server at given address and port.");
|
||||
Terminal.RegisterCommand("join", Join, "join [<address>] [<port>] - Tries to join a server at given address and port.");
|
||||
}
|
||||
}
|
||||
|
||||
private void Update() {
|
||||
if (Terminal != null && Terminal.isActiveAndEnabled) {
|
||||
while (MessageQueue.Count > 0) {
|
||||
Terminal.Println(MessageQueue.Dequeue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool Host(string[] args) {
|
||||
if (args.Length > 2) {
|
||||
Terminal.AddMessage($"<color={Terminal.ERROR_COLOR}>Can't accept more than 2 arguments.</color>");
|
||||
Terminal.Println($"<color={Terminal.ERROR_COLOR}>Can't accept more than 2 arguments.</color>");
|
||||
return false;
|
||||
}
|
||||
string addr = "0.0.0.0";
|
||||
string portstr = "8080";
|
||||
if (args.Length == 1) {
|
||||
if (args.Length > 0) {
|
||||
portstr = args[0];
|
||||
} else if (args.Length == 2) {
|
||||
addr = args[0];
|
||||
portstr = args[1];
|
||||
}
|
||||
if (args.Length > 1) {
|
||||
addr = args[1];
|
||||
}
|
||||
int port;
|
||||
if (!Int32.TryParse(portstr, out port)) {
|
||||
@ -36,8 +48,29 @@ namespace NeonTea.Quakeball.Net {
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool Join(string[] args) {
|
||||
if (args.Length > 2) {
|
||||
Terminal.Println($"<color={Terminal.ERROR_COLOR}>Can't accept more than 2 arguments.</color>");
|
||||
return false;
|
||||
}
|
||||
string addr = "127.0.0.1";
|
||||
string portstr = "8080";
|
||||
if (args.Length > 0) {
|
||||
addr = args[0];
|
||||
}
|
||||
if (args.Length > 1) {
|
||||
portstr = args[1];
|
||||
}
|
||||
int port;
|
||||
if (!Int32.TryParse(portstr, out port)) {
|
||||
return false;
|
||||
}
|
||||
Net.Singleton.StartClient(addr, port, this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Message(string msg) {
|
||||
Terminal.AddMessage(msg);
|
||||
MessageQueue.Enqueue(msg);
|
||||
}
|
||||
|
||||
public void Err(string err) { }
|
||||
|
@ -130,6 +130,7 @@ PlayerSettings:
|
||||
- {fileID: 0}
|
||||
- {fileID: 0}
|
||||
- {fileID: 0}
|
||||
- {fileID: 11400000, guid: 93ab183751ff48144819df32f8ac6a93, type: 2}
|
||||
metroInputSource: 0
|
||||
wsaTransparentSwapchain: 0
|
||||
m_HolographicPauseOnTrackingLoss: 1
|
||||
|
Loading…
Reference in New Issue
Block a user