Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

63 support multiple sprites with codegen #71

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions godot/.godot/global_script_class_cache.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
list=Array[Dictionary]([{
"base": &"VBoxContainer",
"class": &"AutoRefresh",
"icon": "",
"language": &"GDScript",
"path": "res://src/widgets/AutoRefresh/auto_refresh.gd"
}, {
"base": &"EditorPlugin",
"class": &"FormatOnSave",
"icon": "",
Expand Down
2 changes: 1 addition & 1 deletion godot/src/project_selector/project_selector.gd
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func _on_project_name_line_edit_text_changed(new_text):


func _on_new_project_button_pressed(_id: int):
get_tree().change_scene_to_file("res://src/sprite_selector/add_sprite.tscn")
get_tree().change_scene_to_file("res://src/sprite_selector/main.tscn")


func _on_your_projects_menu_button_pressed():
Expand Down
21 changes: 0 additions & 21 deletions godot/src/script_editor/add_move_fragment.tscn

This file was deleted.

17 changes: 17 additions & 0 deletions godot/src/script_editor/auto_refresh_fragments.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
extends AutoRefresh

const MoveFragmentLabel: Resource = preload("res://src/script_editor/code_fragment_move.tscn")


func _refresh_contents():
var ast = Api.get_ast()
render_ast(ast)


func render_ast(ast):
var code_container := $Code
for old in code_container.get_children():
code_container.remove_child(old)

for fragment in ast:
code_container.add_child(MoveFragmentLabel.instantiate())
5 changes: 5 additions & 0 deletions godot/src/script_editor/button_add.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extends Button


func _on_pressed():
API.insert(200)
5 changes: 5 additions & 0 deletions godot/src/script_editor/button_run.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extends Button


func _on_pressed():
get_tree().change_scene_to_file("res://src/runtime/runtime.tscn")
54 changes: 54 additions & 0 deletions godot/src/script_editor/main.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[gd_scene load_steps=4 format=3 uid="uid://rsvepepjglmt"]

[ext_resource type="Script" path="res://src/script_editor/button_run.gd" id="1_2l7lb"]
[ext_resource type="Script" path="res://src/script_editor/button_add.gd" id="2_vfewj"]
[ext_resource type="Script" path="res://src/script_editor/auto_refresh_fragments.gd" id="3_6u76r"]

[node name="ScriptEditor" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2

[node name="RunButton" type="Button" parent="VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "Run"
script = ExtResource("1_2l7lb")

[node name="AddButton" type="Button" parent="VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "Add Move"
script = ExtResource("2_vfewj")

[node name="VScrollContainer" type="ScrollContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="AutoRefresh" type="VBoxContainer" parent="VBoxContainer/VScrollContainer"]
layout_mode = 2
script = ExtResource("3_6u76r")

[node name="Code" type="VBoxContainer" parent="VBoxContainer/VScrollContainer/AutoRefresh"]
layout_mode = 2
size_flags_horizontal = 3

[connection signal="pressed" from="VBoxContainer/HBoxContainer/RunButton" to="VBoxContainer/HBoxContainer/RunButton" method="_on_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/AddButton" to="VBoxContainer/HBoxContainer/AddButton" method="_on_pressed"]
17 changes: 0 additions & 17 deletions godot/src/script_editor/move_fragment.gd

This file was deleted.

21 changes: 0 additions & 21 deletions godot/src/script_editor/move_fragment.tscn

This file was deleted.

34 changes: 0 additions & 34 deletions godot/src/script_editor/script_fragment.gd

This file was deleted.

44 changes: 0 additions & 44 deletions godot/src/script_editor/script_fragment.tscn

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@ extends Control
var Sprites: Resource = preload("res://src/sprite_selector/sprite.tscn")


# Called when the node enters the scene tree for the first time.
func _ready():
pass


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
pass


func _on_add_sprite_button_pressed():
$FileDialog.popup_centered()

Expand All @@ -27,4 +17,3 @@ func _on_file_dialog_file_selected(path):
margin_container.add_theme_constant_override("margin_bottom", margin_value / 2)
margin_container.add_theme_constant_override("margin_right", margin_value)
get_node("VBoxContainer2/VBox/ScrollContainer/VBoxIntems").add_child(sprite)
print_tree_pretty()
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[gd_scene load_steps=4 format=3 uid="uid://bs2465qtho3bu"]
[gd_scene load_steps=5 format=3 uid="uid://bs2465qtho3bu"]

[ext_resource type="Script" path="res://src/sprite_selector/add_sprite.gd" id="1_w6ncu"]
[ext_resource type="Script" path="res://src/sprite_selector/main.gd" id="1_w6ncu"]
[ext_resource type="Script" path="res://src/sprite_selector/sprite_list.gd" id="2_y3h1p"]

[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_kefq6"]

Expand Down Expand Up @@ -75,6 +76,7 @@ size_flags_vertical = 3
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
script = ExtResource("2_y3h1p")

[connection signal="file_selected" from="FileDialog" to="." method="_on_file_dialog_file_selected"]
[connection signal="pressed" from="VBoxContainer2/HBoxContainer/MarginContainer/AddSpriteButton" to="." method="_on_add_sprite_button_pressed"]
2 changes: 1 addition & 1 deletion godot/src/sprite_selector/sprite.gd
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ func _drop_data(_at_position, data):


func _on_pressed():
get_tree().change_scene_to_file("res://src/script_editor/script_fragment.tscn")
get_tree().change_scene_to_file("res://src/script_editor/main.tscn")
12 changes: 12 additions & 0 deletions godot/src/sprite_selector/sprite_list.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extends VBoxContainer

const Sprite: Resource = preload("res://src/sprite_selector/sprite.tscn")


func render_ast(ast):
var code_container := get_tree()
for old in code_container.get_children():
code_container.remove_child(old)

for fragment in ast:
code_container.add_child(Sprite.instantiate())
15 changes: 15 additions & 0 deletions godot/src/widgets/AutoRefresh/auto_refresh.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class_name AutoRefresh
extends VBoxContainer


func _ready():
# get a signal when underlying data changed
GlobalSignals.script_updated.connect(_refresh_contents)

# initial rendering
_refresh_contents()


func _refresh_contents():
# update children of this node here!
assert(false, "_refresh_contents not implemented")
Loading