Console Fix
Console now properly trims non alphanumeric characters from arguments before running the command spawn command is working
This commit is contained in:
parent
cfdacd10cf
commit
e9b32dec0b
5 changed files with 80 additions and 37 deletions
|
|
@ -9,12 +9,14 @@ using System.Linq;
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
public class ConsoleController
|
||||
{
|
||||
private static ConsoleController instance;
|
||||
private static Regex permittedCharacters = new Regex("[^a-zA-Z0-9 -]");
|
||||
|
||||
private ConsoleController()
|
||||
{
|
||||
|
|
@ -105,6 +107,11 @@ public class ConsoleController
|
|||
}
|
||||
char[] parmCharsArr = new char[parmChars.Count];
|
||||
parmChars.CopyTo(parmCharsArr, 0);
|
||||
return (new string(parmCharsArr)).Split(new char[] {'\n'}, StringSplitOptions.RemoveEmptyEntries);
|
||||
var args = new string(parmCharsArr).Split(new[] {'\n'}, StringSplitOptions.RemoveEmptyEntries);
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
{
|
||||
args[i] = permittedCharacters.Replace(args[i], "");
|
||||
}
|
||||
return args;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ public class StrategyGameManager : MonoBehaviour
|
|||
|
||||
// Parse first argument as hull name, default to Fighter if argument missing
|
||||
HullData hullData;
|
||||
if (args.Length > 0)
|
||||
if (args.Length > 1)
|
||||
{
|
||||
hullData = _cache.GetAll<HullData>().FirstOrDefault(h => h.Name == args[0]);
|
||||
if (hullData == null)
|
||||
|
|
@ -169,9 +169,9 @@ public class StrategyGameManager : MonoBehaviour
|
|||
var hull = _context.CreateInstance(hullData.ID, .9f) as Gear;
|
||||
|
||||
List<Gear> gear = new List<Gear>();
|
||||
if (args.Length > 1)
|
||||
if (args.Length > 2)
|
||||
{
|
||||
foreach (string arg in args.Skip(1))
|
||||
foreach (string arg in args.Skip(2))
|
||||
{
|
||||
var gearData = _cache.GetAll<GearData>().FirstOrDefault(h => h.Name == arg);
|
||||
if (gearData == null)
|
||||
|
|
@ -184,21 +184,33 @@ public class StrategyGameManager : MonoBehaviour
|
|||
}
|
||||
else
|
||||
{
|
||||
var thrusterData = _cache.GetAll<GearData>().FirstOrDefault(g => g.Behaviors.Any(b => b is ThrusterData));
|
||||
var thruster = _context.CreateInstance(thrusterData.ID, .9f) as Gear;
|
||||
gear.Add(thruster);
|
||||
// If no gear arguments supplied and we're spawning a ship, get the first thruster and put it in
|
||||
if (args[0] == "ship")
|
||||
{
|
||||
var thrusterData = _cache.GetAll<GearData>().FirstOrDefault(g => g.Behaviors.Any(b => b is ThrusterData));
|
||||
var thruster = _context.CreateInstance(thrusterData.ID, .9f) as Gear;
|
||||
gear.Add(thruster);
|
||||
}
|
||||
}
|
||||
var entity = new Ship(_context, hull, gear, Enumerable.Empty<ItemInstance>());
|
||||
var shipData = new ShipData // TODO: Better database entry for ships?
|
||||
|
||||
if (args[0] == "ship")
|
||||
{
|
||||
ID = Guid.NewGuid()
|
||||
};
|
||||
_cache.Add(shipData);
|
||||
_context.ZoneContents[zoneData][shipData] = entity;
|
||||
_context.Agents.Add(new AgentController(_context, zoneData, entity));
|
||||
var zoneShip = Instantiate(ZoneShipPrefab, ZoneRoot);
|
||||
zoneShip.Label.text = $"Ship {_zoneShips.Count}";
|
||||
_zoneShips[entity] = zoneShip;
|
||||
var entity = new Ship(_context, hull, gear, Enumerable.Empty<ItemInstance>());
|
||||
var shipData = new ShipData // TODO: Better database entry for ships?
|
||||
{
|
||||
ID = Guid.NewGuid()
|
||||
};
|
||||
_cache.Add(shipData);
|
||||
_context.ZoneContents[zoneData][shipData] = entity;
|
||||
_context.Agents.Add(new AgentController(_context, zoneData, entity));
|
||||
var zoneShip = Instantiate(ZoneShipPrefab, ZoneRoot);
|
||||
zoneShip.Label.text = $"Ship {_zoneShips.Count}";
|
||||
_zoneShips[entity] = zoneShip;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"Unknown entity type: \"{args[0]}\"");
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
|
|
|
|||
|
|
@ -13,10 +13,20 @@ using static Unity.Mathematics.math;
|
|||
|
||||
public static class UnityExtensions
|
||||
{
|
||||
public static void BroadcastAll(string fun, System.Object msg) {
|
||||
GameObject[] gos = (GameObject[])GameObject.FindObjectsOfType(typeof(GameObject));
|
||||
foreach (GameObject go in gos) {
|
||||
if (go && go.transform.parent == null) {
|
||||
go.gameObject.BroadcastMessageExt<MonoBehaviour>(fun, msg, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void BroadcastMessageExt<T>(this GameObject go, string methodName, object value = null, SendMessageOptions options = SendMessageOptions.RequireReceiver)
|
||||
{
|
||||
var monoList = new List<T>();
|
||||
go.GetComponentsInChildren(true, monoList);
|
||||
//monoList.Add();
|
||||
foreach (var component in monoList)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
Loading…
Reference in a new issue