You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.1 KiB
71 lines
2.1 KiB
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Newtonsoft.Json;
|
|
using UnityEngine;
|
|
|
|
namespace UltraCombos
|
|
{
|
|
public class GroundControl : MonoBehaviour
|
|
{
|
|
[System.Serializable]
|
|
public class Component
|
|
{
|
|
[JsonProperty("key")] public string Key { get; set; }
|
|
[JsonProperty("order")] public int Order { get; set; }
|
|
[JsonProperty("width")] public float? Width { get; set; }
|
|
}
|
|
|
|
[System.Serializable]
|
|
public class Message
|
|
{
|
|
[JsonProperty("id")] public string Id { get; set; }
|
|
[JsonProperty("step")] public int Step { get; set; }
|
|
[JsonProperty("stepName")] public string StepName { get; set; }
|
|
[JsonProperty("character")] public string Character { get; set; }
|
|
[JsonProperty("components")] public List<Component> Components { get; set; } = new();
|
|
[JsonProperty("title")] public string Title { get; set; }
|
|
[JsonProperty("result")] public string Result { get; set; }
|
|
[JsonProperty("updatedAt")] public long UpdatedAt { get; set; }
|
|
}
|
|
|
|
public Dictionary<string, Message> messages = new();
|
|
public string Station1 => GetSummary(0);
|
|
public string Station2 => GetSummary(1);
|
|
public string Station3 => GetSummary(2);
|
|
|
|
private void Start()
|
|
{
|
|
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
|
|
}
|
|
|
|
public void OnMQTT(string topic, string payload)
|
|
{
|
|
var parts = topic.Split("/");
|
|
if (parts.Length != 3)
|
|
{
|
|
return;
|
|
}
|
|
var id = parts[1];
|
|
var msg = JsonConvert.DeserializeObject<Message>(payload);
|
|
messages[id] = msg;
|
|
}
|
|
|
|
private string GetSummary(int index)
|
|
{
|
|
var keys = messages.Keys.ToArray();
|
|
if (keys.Length <= index)
|
|
{
|
|
return "No messages";
|
|
}
|
|
var id = keys[index];
|
|
var msg = messages[id];
|
|
return $"{id} #{msg.Step} {msg.Character}";
|
|
}
|
|
}
|
|
}
|
|
|
|
|