Files
Babushka/scripts/CSharp/GameEntity/Entities/LoadedScenesEntity.cs
T

32 lines
988 B
C#
Raw Normal View History

2026-02-03 17:30:35 +01:00
using System;
using System.Collections.Generic;
2026-02-03 17:30:35 +01:00
using System.Linq;
using System.Transactions;
using Newtonsoft.Json.Linq;
namespace Babushka.scripts.CSharp.GameEntity.Entities;
public class LoadedScenesEntity : Entity
{
private HashSet<string> _loadedScenes = new();
2026-02-03 17:30:35 +01:00
public override string EntityType => OWN_TYPE_NAME;
public const string OWN_TYPE_NAME = "LoadedScenesEntity";
public void AddScene(string sceneName) => _loadedScenes.Add(sceneName);
public bool WasSceneLoaded(string sceneName) => _loadedScenes.Contains(sceneName);
2026-02-03 17:30:35 +01:00
public override void SaveEntity(JObject json)
{
base.SaveEntity(json);
json["scenes"] = new JArray(_loadedScenes);
}
public override void LoadEntity(JObject json)
{
base.LoadEntity(json);
JArray array = (JArray?) json["scenes"] ?? throw new Exception("No scenes found in LoadedScenesEntity.");
_loadedScenes = array.ToObject<HashSet<string>>()!;
}
}