using Godot; #if TOOLS [Tool] public partial class AdventureEditor : MarginContainer { public AdventureLevelResource editedResource; public string editedPath; [Signal] public delegate void ResourceChangedEventHandler(AdventureLevelResource to); [Signal] public delegate void ReloadRequestedEventHandler(); [Signal] public delegate void HardReloadRequestedEventHandler(); public override void _Ready() { EditorInterface.Singleton.GetInspector().PropertyEdited += OnInspectorPropertyChanged; EditorInterface.Singleton.GetInspector().EditedObjectChanged += OnResourceChanged; } public void Reload() { EmitSignal(SignalName.ReloadRequested); } public void HardReload() { editedResource = ResourceLoader.Load(editedPath); EmitSignal(SignalName.ResourceChanged, editedResource); EmitSignal(SignalName.HardReloadRequested); Reload(); } public void Save() { if (editedPath.EndsWith(".tres") == false) { editedPath += ".tres"; } ResourceSaver.Save(editedResource, editedPath); } public void OnInspectorPropertyChanged(string property) { if (EditorInterface.Singleton.GetInspector().GetEditedObject() is AdventureLevelResource resource && resource.ResourcePath == editedPath) { HardReload(); } } public void OnResourceChanged() { if (EditorInterface.Singleton.GetInspector().GetEditedObject() is AdventureLevelResource resource) { editedPath = resource.ResourcePath; HardReload(); } } public override void _ExitTree() { EditorInterface.Singleton.GetInspector().PropertyEdited -= OnInspectorPropertyChanged; EditorInterface.Singleton.GetInspector().EditedObjectChanged -= OnResourceChanged; } } #endif