Editor slight refactor

This commit is contained in:
Rendo 2025-07-29 00:53:29 +05:00
commit 8cfbad01cf
23 changed files with 9 additions and 8 deletions

View file

@ -1,75 +0,0 @@
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<AdventureLevelResource>(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 void Play()
{
var player = new AdventurePlayer();
var packed = new PackedScene();
player.pathToLevel = editedPath;
packed.Pack(player);
ResourceSaver.Save(packed, "res://addons/pvzadventure/cache/player.tscn");
EditorInterface.Singleton.PlayCustomScene("res://addons/pvzadventure/cache/player.tscn");
}
public override void _ExitTree()
{
EditorInterface.Singleton.GetInspector().PropertyEdited -= OnInspectorPropertyChanged;
EditorInterface.Singleton.GetInspector().EditedObjectChanged -= OnResourceChanged;
}
}
#endif