Added terrain and robot prototypes
This commit is contained in:
54
nodes/coding/code_runner.gd
Normal file
54
nodes/coding/code_runner.gd
Normal file
@@ -0,0 +1,54 @@
|
||||
extends Node
|
||||
|
||||
@onready var code_editor := $%Code as CodeEdit
|
||||
@onready var memory := $%Memory as VBoxContainer
|
||||
@onready var memory_entry := load("uid://dqwi5rekytyds") as PackedScene
|
||||
var cobor_vm := CoborVirtualMachine.new()
|
||||
|
||||
func _ready() -> void:
|
||||
cobor_vm.set_registers(8,[])
|
||||
for i in range(8):
|
||||
var entry := memory_entry.instantiate() as Control
|
||||
(entry.get_node("address") as Label).text = "/" + str(i) + " = "
|
||||
(entry.get_node("value") as SpinBox).value = 0
|
||||
memory.add_child(entry)
|
||||
|
||||
func _tick() -> void:
|
||||
if code_editor.editable: return
|
||||
for line in code_editor.get_executing_lines():
|
||||
code_editor.set_line_as_executing(line, false)
|
||||
code_editor.set_line_as_executing(cobor_vm.get_program_counter(), true)
|
||||
var err := cobor_vm.run_step()
|
||||
if not err.is_empty():
|
||||
print(err);
|
||||
var registers := cobor_vm.get_registers()
|
||||
for i in range(8):
|
||||
var entry := memory.get_child(i) as Control
|
||||
(entry.get_node("value") as SpinBox).value = registers[i]
|
||||
|
||||
func _on_compile_button_pressed() -> void:
|
||||
var text := code_editor.text
|
||||
var errors := cobor_vm.parse_source_code(text)
|
||||
if errors.is_empty():
|
||||
print("Compiling Ok!")
|
||||
else:
|
||||
for error in errors:
|
||||
print(error)
|
||||
|
||||
func _on_stop_button_pressed() -> void:
|
||||
code_editor.editable = true
|
||||
$Timer.stop()
|
||||
cobor_vm.set_registers(8,[])
|
||||
|
||||
func _on_play_button_pressed() -> void:
|
||||
code_editor.editable = false
|
||||
_on_compile_button_pressed();
|
||||
$Timer.start()
|
||||
|
||||
func _on_pause_button_pressed() -> void:
|
||||
$Timer.stop()
|
||||
|
||||
|
||||
func _on_step_button_pressed() -> void:
|
||||
code_editor.editable = false
|
||||
_tick()
|
||||
1
nodes/coding/code_runner.gd.uid
Normal file
1
nodes/coding/code_runner.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://brnfd6h7eh0n7
|
||||
87
nodes/coding/code_runner.tscn
Normal file
87
nodes/coding/code_runner.tscn
Normal file
@@ -0,0 +1,87 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://7q00x01xdsal"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://brnfd6h7eh0n7" path="res://nodes/coding/code_runner.gd" id="1_mphwn"]
|
||||
|
||||
[node name="CodeRunner" type="Node"]
|
||||
script = ExtResource("1_mphwn")
|
||||
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
|
||||
[node name="ProgrammerUI" type="PanelContainer" parent="."]
|
||||
anchors_preset = 9
|
||||
anchor_bottom = 1.0
|
||||
offset_right = 314.0
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="ProgrammerUI"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 10
|
||||
|
||||
[node name="Label" type="Label" parent="ProgrammerUI/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Programming"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="ProgrammerUI/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="ProgrammerUI/VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="ProgrammerUI/VBoxContainer/HBoxContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = " Source Code "
|
||||
|
||||
[node name="Code" type="CodeEdit" parent="ProgrammerUI/VBoxContainer/HBoxContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(200, 0)
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
text = "Set 1 /2
|
||||
Cpy /2 /3
|
||||
Add /2 /3 /3
|
||||
|
||||
"
|
||||
placeholder_text = "Code here"
|
||||
symbol_tooltip_on_hover = true
|
||||
line_length_guidelines = Array[int]([5, 7, 9, 11])
|
||||
gutters_draw_executing_lines = true
|
||||
gutters_draw_line_numbers = true
|
||||
gutters_zero_pad_line_numbers = true
|
||||
|
||||
[node name="Memory" type="VBoxContainer" parent="ProgrammerUI/VBoxContainer/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
[node name="HBoxContainer2" type="HBoxContainer" parent="ProgrammerUI/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 10
|
||||
alignment = 1
|
||||
|
||||
[node name="compileButton" type="Button" parent="ProgrammerUI/VBoxContainer/HBoxContainer2"]
|
||||
layout_mode = 2
|
||||
text = "[C]"
|
||||
|
||||
[node name="StopButton" type="Button" parent="ProgrammerUI/VBoxContainer/HBoxContainer2"]
|
||||
layout_mode = 2
|
||||
text = "[ ]"
|
||||
|
||||
[node name="PlayButton" type="Button" parent="ProgrammerUI/VBoxContainer/HBoxContainer2"]
|
||||
layout_mode = 2
|
||||
text = ">"
|
||||
|
||||
[node name="PauseButton" type="Button" parent="ProgrammerUI/VBoxContainer/HBoxContainer2"]
|
||||
layout_mode = 2
|
||||
text = "||"
|
||||
|
||||
[node name="StepButton" type="Button" parent="ProgrammerUI/VBoxContainer/HBoxContainer2"]
|
||||
layout_mode = 2
|
||||
text = ">|"
|
||||
|
||||
[connection signal="timeout" from="Timer" to="." method="_tick"]
|
||||
[connection signal="pressed" from="ProgrammerUI/VBoxContainer/HBoxContainer2/compileButton" to="." method="_on_compile_button_pressed"]
|
||||
[connection signal="pressed" from="ProgrammerUI/VBoxContainer/HBoxContainer2/StopButton" to="." method="_on_stop_button_pressed"]
|
||||
[connection signal="pressed" from="ProgrammerUI/VBoxContainer/HBoxContainer2/PlayButton" to="." method="_on_play_button_pressed"]
|
||||
[connection signal="pressed" from="ProgrammerUI/VBoxContainer/HBoxContainer2/PauseButton" to="." method="_on_pause_button_pressed"]
|
||||
[connection signal="pressed" from="ProgrammerUI/VBoxContainer/HBoxContainer2/StepButton" to="." method="_on_step_button_pressed"]
|
||||
16
nodes/coding/memory_entry.tscn
Normal file
16
nodes/coding/memory_entry.tscn
Normal file
@@ -0,0 +1,16 @@
|
||||
[gd_scene format=3 uid="uid://dqwi5rekytyds"]
|
||||
|
||||
[node name="memory_entry" type="HBoxContainer"]
|
||||
|
||||
[node name="address" type="Label" parent="."]
|
||||
layout_mode = 2
|
||||
text = "/0 = "
|
||||
|
||||
[node name="value" type="SpinBox" parent="."]
|
||||
layout_mode = 2
|
||||
value = 4.0
|
||||
rounded = true
|
||||
allow_greater = true
|
||||
allow_lesser = true
|
||||
alignment = 1
|
||||
editable = false
|
||||
Reference in New Issue
Block a user