Play button in editor

This commit is contained in:
Rendo 2025-07-29 00:42:29 +05:00
commit 285b90f503
6 changed files with 38 additions and 5 deletions

1
addons/pvzadventure/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
cache/

View file

@ -41,7 +41,7 @@ script = ExtResource("2_d5hwn")
[node name="FileDialog" type="FileDialog" parent="Editor/StatusBar/HBoxContainer/FileButton"]
[node name="Button" type="Button" parent="Editor/StatusBar/HBoxContainer"]
[node name="PlayButton" type="Button" parent="Editor/StatusBar/HBoxContainer"]
layout_mode = 2
text = "Play"
flat = true
@ -84,6 +84,7 @@ text = "New"
[connection signal="HardReloadRequested" from="." to="Editor/WorkArea/PanelContainer" method="ClearChildren"]
[connection signal="ResourceChanged" from="." to="Editor/WorkArea/Inspector/ResourceInspector" method="Refresh"]
[connection signal="pressed" from="Editor/StatusBar/HBoxContainer/PlayButton" to="." method="Play"]
[connection signal="Refreshed" from="Editor/WorkArea/Inspector/ResourceInspector" to="." method="Save"]
[connection signal="button_clicked" from="Editor/WorkArea/Inspector/ResourceInspector/Tree" to="Editor/WorkArea/Inspector/ResourceInspector" method="OnTreeButtonClicked"]
[connection signal="item_edited" from="Editor/WorkArea/Inspector/ResourceInspector/Tree" to="Editor/WorkArea/Inspector/ResourceInspector" method="OnItemEdited"]

View file

@ -55,11 +55,21 @@ public partial class AdventureEditor : MarginContainer
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

View file

@ -0,0 +1,19 @@
using Godot;
using Newlon;
[Tool]
public partial class AdventurePlayer : Node
{
const string tilesetUID = "uid://dd3yegl1xo44m";
[Export] public string pathToLevel;
public override void _Ready()
{
if (Engine.IsEditorHint()) return;
CallDeferred("InitLevel");
}
private void InitLevel()
{
LevelController.Instance.StartLevel(ResourceLoader.Load<PackedScene>(tilesetUID), ResourceLoader.Load<AdventureLevelResource>(pathToLevel));
}
}

View file

@ -0,0 +1 @@
uid://bbkfrk07l6kev

View file

@ -38,5 +38,6 @@ wavePercentage = 0.0
standardWaveDelay = 20.0
initialWaveDelay = 10.0
reward = ExtResource("1_sw8bw")
forbiddenPlants = []
waves = [SubResource("Resource_swlbc"), SubResource("Resource_pkoaj")]
initialScenes = Array[PackedScene]([null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null])