quantum-space-buddies/QSB/QuantumSync/WorldObjects/QSBMultiStateQuantumObject.cs

50 lines
1.3 KiB
C#
Raw Normal View History

2022-01-29 04:49:07 +00:00
using Cysharp.Threading.Tasks;
using QSB.Utility;
using QSB.WorldSync;
2021-12-28 18:06:34 +00:00
using System;
2021-12-07 15:56:08 +00:00
using System.Collections.Generic;
using System.Linq;
2022-01-29 04:49:07 +00:00
using System.Threading;
2020-12-23 22:43:05 +00:00
2022-03-03 03:46:33 +00:00
namespace QSB.QuantumSync.WorldObjects;
2023-07-28 18:30:57 +00:00
public class QSBMultiStateQuantumObject : QSBQuantumObject<MultiStateQuantumObject>
2020-12-23 11:26:47 +00:00
{
2022-03-03 03:46:33 +00:00
public List<QSBQuantumState> QuantumStates { get; private set; }
public int CurrentState => AttachedObject._stateIndex;
2022-03-03 03:46:33 +00:00
public override async UniTask Init(CancellationToken ct)
{
await base.Init(ct);
2022-03-03 03:46:33 +00:00
await UniTask.WaitUntil(() => QSBWorldSync.AllObjectsAdded, cancellationToken: ct);
2022-03-03 03:46:33 +00:00
QuantumStates = AttachedObject._states.Select(QSBWorldSync.GetWorldObject<QSBQuantumState>).ToList();
2022-03-03 03:46:33 +00:00
if (QuantumStates.Any(x => x == null))
{
DebugLog.ToConsole($"Error - {AttachedObject.name} has one or more null QSBQuantumStates assigned!", OWML.Common.MessageType.Error);
}
2022-03-03 03:46:33 +00:00
}
2022-03-03 03:46:33 +00:00
public override string ReturnLabel()
2022-03-07 20:34:35 +00:00
=> $"{base.ReturnLabel()}StateIndex:{AttachedObject._stateIndex}";
2021-12-28 18:06:34 +00:00
2022-03-03 03:46:33 +00:00
public override void SendInitialState(uint to)
{
base.SendInitialState(to);
2022-03-03 03:46:33 +00:00
// todo SendInitialState
}
2022-03-03 03:46:33 +00:00
public void ChangeState(int newStateIndex)
{
if (CurrentState != -1)
2021-01-26 14:07:17 +00:00
{
2022-03-03 03:46:33 +00:00
QuantumStates[CurrentState].SetVisible(false);
}
2022-03-03 03:46:33 +00:00
QuantumStates[newStateIndex].SetVisible(true);
AttachedObject._stateIndex = newStateIndex;
2020-12-23 11:26:47 +00:00
}
}