Console Fix

Console now properly trims non alphanumeric characters from arguments before running the command
spawn command is working
This commit is contained in:
hyperion51 2020-04-28 04:21:04 +01:00
commit e9b32dec0b
5 changed files with 80 additions and 37 deletions

View file

@ -8307,9 +8307,9 @@ RectTransform:
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: -17, y: 20}
m_SizeDelta: {x: 0, y: 20}
m_Pivot: {x: 0, y: 0}
--- !u!114 &412194189
MonoBehaviour:
@ -9014,7 +9014,7 @@ RectTransform:
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 0.99999976}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 20, y: 20}
m_Pivot: {x: 0.5, y: 0.5}
@ -10323,7 +10323,7 @@ RectTransform:
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: -73.03003}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 1}
--- !u!114 &519035862
MonoBehaviour:
@ -19986,7 +19986,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!224 &907710631
RectTransform:
m_ObjectHideFlags: 0
@ -20005,9 +20005,9 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 8}
m_SizeDelta: {x: 0, y: 16}
m_Pivot: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 1}
--- !u!114 &907710632
MonoBehaviour:
m_ObjectHideFlags: 0
@ -20803,9 +20803,9 @@ RectTransform:
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: -17, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 1}
--- !u!114 &953390098
MonoBehaviour:
@ -24594,10 +24594,10 @@ RectTransform:
m_Father: {fileID: 519035861}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 943.50006, y: -263.485}
m_SizeDelta: {x: 1887.0001, y: 526.97}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 943.50006, y: 0}
m_SizeDelta: {x: 1887.0001, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1101630447
MonoBehaviour:
@ -34335,10 +34335,10 @@ RectTransform:
m_Father: {fileID: 323746067}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMin: {x: 0, y: 0.5}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 600}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 1}
--- !u!114 &1551320372
MonoBehaviour:
@ -35948,7 +35948,7 @@ MonoBehaviour:
m_HandleRect: {fileID: 456371628}
m_Direction: 2
m_Value: 0
m_Size: 0.9999998
m_Size: 1
m_NumberOfSteps: 0
m_OnValueChanged:
m_PersistentCalls:
@ -37097,8 +37097,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 8, y: -8}
m_SizeDelta: {x: -16, y: -16}
m_AnchoredPosition: {x: 8, y: 0}
m_SizeDelta: {x: -16, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1663644542
MonoBehaviour:
@ -43752,7 +43752,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1935781035}
m_Enabled: 0
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 058cba836c1846c3aa1c5fd2e28aea77, type: 3}
m_Name:

View file

@ -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;
}
}

View file

@ -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()

View file

@ -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