Purge Newtonsoft state annotations
This commit is contained in:
parent
639e701d63
commit
b0d2aa1156
92 changed files with 891 additions and 1684 deletions
|
|
@ -4,8 +4,6 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using TMPro;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
|
|
@ -53,7 +51,7 @@ public class InputDisplayLayout : MonoBehaviour
|
|||
private ButtonMapping _previewButton;
|
||||
private ActionMapping _previewOriginalAction;
|
||||
private bool _previewOriginallyActionBar;
|
||||
|
||||
|
||||
public InputActionAsset Input { get; set; }
|
||||
|
||||
private class ButtonMapping
|
||||
|
|
@ -77,11 +75,11 @@ public class InputDisplayLayout : MonoBehaviour
|
|||
public List<ButtonMapping> ButtonMappings = new List<ButtonMapping>();
|
||||
public Rect LabelRect => Label.GetComponent<RectTransform>().ScreenSpaceRect();
|
||||
}
|
||||
|
||||
|
||||
private Dictionary<string, ButtonMapping> _bindButtons = new Dictionary<string, ButtonMapping>();
|
||||
private List<ButtonMapping> _buttonMappings = new List<ButtonMapping>();
|
||||
private List<ActionMapping> _actionMappings = new List<ActionMapping>();
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
_canvas = transform.root.GetComponent<Canvas>();
|
||||
|
|
@ -89,22 +87,21 @@ public class InputDisplayLayout : MonoBehaviour
|
|||
// _inputLayout = ParseJson(LayoutFile.text);
|
||||
RegisterResolver.Register();
|
||||
_inputLayout = MessagePackSerializer.Deserialize<InputLayout>(File.ReadAllBytes(path));
|
||||
// _inputLayout = JsonConvert.DeserializeObject<InputLayout>(File.ReadAllText(path));
|
||||
// SaveLayout();
|
||||
DisplayLayout(_inputLayout);
|
||||
|
||||
|
||||
_buttonMappings.Add(MapMouseButton(MouseLeft, "<Mouse>/leftButton"));
|
||||
_buttonMappings.Add(MapMouseButton(MouseRight, "<Mouse>/rightButton"));
|
||||
_buttonMappings.Add(MapMouseButton(MouseMiddle, "<Mouse>/middleButton"));
|
||||
_buttonMappings.Add(MapMouseButton(MouseForward, "<Mouse>/forwardButton"));
|
||||
_buttonMappings.Add(MapMouseButton(MouseBack, "<Mouse>/backButton"));
|
||||
|
||||
|
||||
Canvas.ForceUpdateCanvases();
|
||||
|
||||
foreach (var buttonMapping in _buttonMappings)
|
||||
{
|
||||
_bindButtons[buttonMapping.Button.InputSystemPath] = buttonMapping;
|
||||
|
||||
|
||||
buttonMapping.TestAction = new InputAction(binding: buttonMapping.Button.InputSystemPath);
|
||||
buttonMapping.TestAction.started += context =>
|
||||
{
|
||||
|
|
@ -118,7 +115,7 @@ public class InputDisplayLayout : MonoBehaviour
|
|||
buttonMapping.TestAction.canceled += context => AssignColor(buttonMapping);
|
||||
buttonMapping.TestAction.Enable();
|
||||
}
|
||||
|
||||
|
||||
foreach(var actionBarInput in ActionGameManager.PlayerSettings.InputSettings.ActionBarInputs)
|
||||
{
|
||||
if (!_bindButtons.ContainsKey(actionBarInput)) Debug.LogError($"Unable to find input button for \"{actionBarInput}\"");
|
||||
|
|
@ -128,7 +125,7 @@ public class InputDisplayLayout : MonoBehaviour
|
|||
AssignColor(_bindButtons[actionBarInput]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(Input==null)
|
||||
{
|
||||
var input = new AetheriaInput();
|
||||
|
|
@ -185,7 +182,7 @@ public class InputDisplayLayout : MonoBehaviour
|
|||
: frac(GlobalHue + GlobalHueRange + (float) i / (bindableActions.Length - 1) * (1 - GlobalHueRange * 2))
|
||||
};
|
||||
_actionMappings.Add(actionMapping);
|
||||
|
||||
|
||||
var buttonMapping = _bindButtons[binding.effectivePath];
|
||||
buttonMapping.ActionMapping = actionMapping;
|
||||
AssignColor(buttonMapping);
|
||||
|
|
@ -310,7 +307,7 @@ public class InputDisplayLayout : MonoBehaviour
|
|||
|
||||
private ActionMapping[] OverlappingLabels(Rect rect) => _actionMappings
|
||||
.Where(a => a.LabelRect.Overlaps(rect)).ToArray();
|
||||
|
||||
|
||||
private Rect[] Overlap(Rect rect) => _buttonMappings
|
||||
.Where(b=>b.IsActionBarButton || b.ActionMapping!=null)
|
||||
.Select(b=>b.ButtonRect)
|
||||
|
|
@ -345,7 +342,7 @@ public class InputDisplayLayout : MonoBehaviour
|
|||
{
|
||||
var buttonMapping = new ButtonMapping
|
||||
{
|
||||
Button = key,
|
||||
Button = key,
|
||||
DisplayButton = displayKey
|
||||
};
|
||||
_bindButtons[key.InputSystemPath] = buttonMapping;
|
||||
|
|
@ -390,11 +387,11 @@ public class InputDisplayLayout : MonoBehaviour
|
|||
var nextWidth = 1f;
|
||||
var nextHeight = 1;
|
||||
var reader = new JsonTextReader(new StringReader(layout));
|
||||
|
||||
|
||||
reader.Read();
|
||||
if (reader.TokenType != JsonToken.StartArray)
|
||||
throw new JsonReaderException($"Unexpected JSON format in line {reader.LineNumber}:{reader.LinePosition}, expected: StartArray, received: {Enum.GetName(typeof(JsonToken), reader.TokenType)}");
|
||||
|
||||
|
||||
while(reader.Read() && reader.TokenType != JsonToken.EndArray)
|
||||
{
|
||||
if (reader.TokenType != JsonToken.StartArray)
|
||||
|
|
@ -475,12 +472,12 @@ public class InputDisplayLayout : MonoBehaviour
|
|||
fillColor *= FillMultiplier;
|
||||
fillColor.a = FillAlpha;
|
||||
button.DisplayButton.Fill.color = fillColor;
|
||||
|
||||
|
||||
path = "";
|
||||
while (string.IsNullOrEmpty(path)) yield return null;
|
||||
button.Button.InputSystemPath = path;
|
||||
//Debug.Log($"Bound \"{path}\" to \"{bindableKey.MainLabel}\"");
|
||||
|
||||
|
||||
button.DisplayButton.Outline.color = DefaultColor;
|
||||
fillColor = DefaultColor;
|
||||
fillColor *= FillMultiplier;
|
||||
|
|
@ -623,7 +620,7 @@ public class InputDisplayLayout : MonoBehaviour
|
|||
.Where(_ => _dragAction != null)
|
||||
.Subscribe(EndDrag);
|
||||
}
|
||||
|
||||
|
||||
foreach (var actionMapping in _actionMappings)
|
||||
{
|
||||
actionMapping.Label.BeginDragTrigger.OnBeginDragAsObservable().Subscribe(_ =>
|
||||
|
|
|
|||
|
|
@ -1,18 +1,16 @@
|
|||
using System.Collections.Generic;
|
||||
using JsonKnownTypes;using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
using MessagePack;
|
||||
[MessagePackObject]
|
||||
public class InputLayout
|
||||
{
|
||||
[Key(0), JsonProperty("rows")] public InputLayoutRow[] Rows;
|
||||
[Key(0)] public InputLayoutRow[] Rows;
|
||||
|
||||
public IEnumerable<InputLayoutBindableKey> GetBindableKeys()
|
||||
{
|
||||
foreach (var row in Rows)
|
||||
{
|
||||
if (!(row is InputLayoutKeyRow keyRow)) continue;
|
||||
|
||||
|
||||
foreach (var column in keyRow.Columns)
|
||||
{
|
||||
if (column is InputLayoutBindableKey bindableKey)
|
||||
|
|
@ -24,27 +22,25 @@ public class InputLayout
|
|||
}
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(JsonKnownTypesConverter<InputLayoutRow>)),
|
||||
MessagePackObject,
|
||||
[MessagePackObject,
|
||||
Union(0, typeof(InputLayoutRowSpacer)),
|
||||
Union(1, typeof(InputLayoutKeyRow))
|
||||
]
|
||||
public abstract class InputLayoutRow { }
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
[MessagePackObject]
|
||||
public class InputLayoutRowSpacer : InputLayoutRow
|
||||
{
|
||||
[Key(0), JsonProperty("height")] public float Height;
|
||||
[Key(0)] public float Height;
|
||||
}
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
[MessagePackObject]
|
||||
public class InputLayoutKeyRow : InputLayoutRow
|
||||
{
|
||||
[Key(0), JsonProperty("columns")] public InputLayoutColumn[] Columns;
|
||||
[Key(0)] public InputLayoutColumn[] Columns;
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(JsonKnownTypesConverter<InputLayoutColumn>)),
|
||||
MessagePackObject,
|
||||
[MessagePackObject,
|
||||
Union(0, typeof(InputLayoutColumnSpacer)),
|
||||
Union(1, typeof(InputLayoutKey)),
|
||||
Union(2, typeof(InputLayoutBindableKey)),
|
||||
|
|
@ -52,21 +48,21 @@ public class InputLayoutKeyRow : InputLayoutRow
|
|||
]
|
||||
public abstract class InputLayoutColumn
|
||||
{
|
||||
[Key(0), JsonProperty("width")] public float Width;
|
||||
[Key(0)] public float Width;
|
||||
}
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
[MessagePackObject]
|
||||
public class InputLayoutColumnSpacer : InputLayoutColumn { }
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
[MessagePackObject]
|
||||
public class InputLayoutKey : InputLayoutColumn { }
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
[MessagePackObject]
|
||||
public class InputLayoutBindableKey : InputLayoutKey, IBindableButton
|
||||
{
|
||||
[Key(1), JsonProperty("mainLabel")] public string MainLabel;
|
||||
[Key(2), JsonProperty("altLabel")] public string AltLabel;
|
||||
[Key(3), JsonProperty("path")] public string ShortPath;
|
||||
[Key(1)] public string MainLabel;
|
||||
[Key(2)] public string AltLabel;
|
||||
[Key(3)] public string ShortPath;
|
||||
|
||||
[IgnoreMember]
|
||||
public string InputSystemPath
|
||||
|
|
@ -84,7 +80,7 @@ public class InputLayoutBindableKey : InputLayoutKey, IBindableButton
|
|||
|
||||
public class InputLayoutMultiRowKey : InputLayoutBindableKey
|
||||
{
|
||||
[Key(4), JsonProperty("height")] public int Height;
|
||||
[Key(4)] public int Height;
|
||||
}
|
||||
|
||||
public class InputLayoutMouseButton : IBindableButton
|
||||
|
|
|
|||
Loading…
Reference in a new issue