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.
Babushka/scripts/CSharp/GameEntity/Entities/LoadedScenesEntity.cs

32 lines
988 B

using System;
using System.Collections.Generic;
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();
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);
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>>()!;
}
}