2using MPewsey.Common.Serialization;
5using System.Threading.Tasks;
20 [Export]
public bool EditId {
get => _editId;
set => SetValidatedField(ref _editId, value); }
45 [ExportGroup(
"Serialized Text")]
46 [Export(PropertyHint.MultilineText)]
public string SerializedText {
get;
set; }
48 private void SetValidatedField<T>(ref T field, T value)
51 NotifyPropertyListChanged();
54 public override void _ValidateProperty(Godot.Collections.Dictionary property)
56 base._ValidateProperty(property);
57 var name =
property[
"name"].AsStringName();
59 if (name == PropertyName.ScenePath || name == PropertyName.SceneUidPath || name == PropertyName.SerializedText)
61 property[
"usage"] = (int)(property[
"usage"].As<PropertyUsageFlags>() | PropertyUsageFlags.ReadOnly);
63 else if (name == PropertyName.Id)
65 var flag =
EditId ? PropertyUsageFlags.None : PropertyUsageFlags.ReadOnly;
66 property[
"usage"] = (int)(PropertyUsageFlags.Default | flag);
76 var node = (Node)room;
77 var scenePath = node.SceneFilePath;
78 var sceneUidPath = ResourceUid.IdToText(ResourceLoader.GetResourceUid(scenePath));
81 SerializedText = JsonSerialization.GetJsonString(
template,
new JsonWriterSettings());
95 return JsonSerialization.LoadJsonString<RoomTemplate>(
SerializedText);
115 throw new PathDoesNotExistException($
"Scene paths do not exist: (SceneUidPath = {SceneUidPath}, ScenePath = {ScenePath})");
123 return ResourceLoader.Load<PackedScene>(
GetScenePath());
Contains methods for loading Resources asynchronously.
Raised if a path does not exist.
Raised if a room template has not been initialized.
Contains the random number generator used for ID and random seed assignments.
static int GetRandomId()
Returns a random positive integer ID.
Provides a reference to a room scene and information for the room required by the procedural generato...
string SceneUidPath
The associated scene's uid:// path.
void Initialize(IRoomNode room)
Sets the scene paths and serialized text to the room template based on the specified room.
string GetScenePath()
Returns the controlling associated scene path. The uid:// path is prioritized first,...
string SerializedText
The serialized text for the ManiaMap room template.
string ScenePath
The associated scene's path.
string TemplateName
The template name.
RoomTemplate GetMMRoomTemplate()
Returns the ManiaMap room template used by the procedural generator.
PackedScene LoadScene()
Loads and returns the referenced scene.
bool EditId
If true, the Id property becomes editable in the inspector.
Task< PackedScene > LoadSceneAsync(bool useSubThreads=false)
Asynchronously loads and returns the referenced scene.
int Id
The room template's unique ID.
The interface for a room node.