Play button in editor
This commit is contained in:
parent
ad56c6f61f
commit
285b90f503
6 changed files with 38 additions and 5 deletions
1
addons/pvzadventure/.gitignore
vendored
Normal file
1
addons/pvzadventure/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
cache/
|
||||
|
|
@ -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"]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
19
addons/pvzadventure/scripts/AdventurePlayer.cs
Normal file
19
addons/pvzadventure/scripts/AdventurePlayer.cs
Normal 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));
|
||||
}
|
||||
}
|
||||
1
addons/pvzadventure/scripts/AdventurePlayer.cs.uid
Normal file
1
addons/pvzadventure/scripts/AdventurePlayer.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bbkfrk07l6kev
|
||||
|
|
@ -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])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue