Added import and export for the level designer

This commit is contained in:
2024-05-06 15:02:56 +01:00
parent ad2d467456
commit 031879cf46
18 changed files with 291 additions and 41 deletions

15
ExportPanel.gd Normal file
View File

@@ -0,0 +1,15 @@
extends PanelContainer
func _ready() -> void:
pass
func show_panel(ob : Dictionary) -> void:
var text = JSON.stringify(ob, " ")
var b64 = Marshalls.utf8_to_base64(text)
$VBoxContainer/ExportedCode.text = b64
visible = true
$VBoxContainer/ExportedCode.select_all()
$VBoxContainer/ExportedCode.copy()
func _on_close_pressed() -> void:
visible = false

BIN
Fonts/Ac437_Trident_8x8.ttf Normal file

Binary file not shown.

View File

@@ -0,0 +1,33 @@
[remap]
importer="font_data_dynamic"
type="FontFile"
uid="uid://c7hlot6dsm01s"
path="res://.godot/imported/Ac437_Trident_8x8.ttf-700703d9d4f422a555a6606f86fe6f3a.fontdata"
[deps]
source_file="res://Fonts/Ac437_Trident_8x8.ttf"
dest_files=["res://.godot/imported/Ac437_Trident_8x8.ttf-700703d9d4f422a555a6606f86fe6f3a.fontdata"]
[params]
Rendering=null
antialiasing=0
generate_mipmaps=false
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
allow_system_fallback=true
force_autohinter=false
hinting=1
subpixel_positioning=1
oversampling=0.0
Fallbacks=null
fallbacks=[]
Compress=null
compress=true
preload=[]
language_support={}
script_support={}
opentype_features={}

BIN
Icons/Internal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 593 B

View File

@@ -2,16 +2,16 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://yd2mphfafhah"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
uid="uid://cxjq8xhs0a7lg"
path="res://.godot/imported/Internal.png-271ce861b95dc4d3723bafb9fe9d4a5d.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
source_file="res://Icons/Internal.png"
dest_files=["res://.godot/imported/Internal.png-271ce861b95dc4d3723bafb9fe9d4a5d.ctex"]
[params]
@@ -32,6 +32,3 @@ process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

BIN
Icons/User.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 586 B

34
Icons/User.png.import Normal file
View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bhp4jjlq62fmu"
path="res://.godot/imported/User.png-6910c28b928ba74ae97b734bee82a7d1.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Icons/User.png"
dest_files=["res://.godot/imported/User.png-6910c28b928ba74ae97b734bee82a7d1.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

18
ImportPanel.gd Normal file
View File

@@ -0,0 +1,18 @@
extends PanelContainer
signal object_imported(data : Dictionary)
func show_panel() -> void:
$VBoxContainer/ImportedCode.text = ""
$VBoxContainer/ImportedCode.grab_focus()
visible = true
func _on_import_pressed() -> void:
var text = Marshalls.base64_to_utf8($VBoxContainer/ImportedCode.text)
var ob = JSON.parse_string(text)
if ob != null:
object_imported.emit(ob)
visible = false
func _on_cancel_pressed() -> void:
visible = false

View File

@@ -4,10 +4,7 @@ extends Node2D
func _on_background_item_selected(index: int) -> void:
$Background.texture = load($VBoxContainer/Background.get_item_metadata(index))
func _on_save_pressed() -> void:
if $VBoxContainer/Name.text == "":
return
func get_level_object() -> Dictionary:
var data : Dictionary = {
"name": $VBoxContainer/Name.text,
"left": $VBoxContainer/Left.get_selected_text(),
@@ -21,6 +18,12 @@ func _on_save_pressed() -> void:
var brick = get_node("Bricks/Row%d/Col%d" % [row, col])
s += brick.type
data.data.push_back(s)
return data
func _on_save_pressed() -> void:
if $VBoxContainer/Name.text == "":
return
var data : Dictionary = get_level_object()
DirAccess.make_dir_recursive_absolute("user://Levels")
var f = FileAccess.open("user://Levels/%s.json" % data.name, FileAccess.WRITE)
f.store_string(JSON.stringify(data, " "))
@@ -43,17 +46,20 @@ func _on_load_pressed() -> void:
func _on_load_panel_load_file(filename: String) -> void:
if FileAccess.file_exists(filename):
var data = JSON.parse_string(FileAccess.get_file_as_string(filename))
if data != null:
$VBoxContainer/Name.text = data.name
$VBoxContainer/Left.select_by_name(data.left)
$VBoxContainer/Right.select_by_name(data.right)
$VBoxContainer/Background.select_by_name(data.background)
$Background.texture = load($VBoxContainer/Background.get_selected_filename())
for row in 18:
for col in 13:
var brick = get_node("Bricks/Row%d/Col%d" % [row, col])
var c = data.data[row].substr(col, 1)
brick.set_brick_type(c)
load_level_from_object(data)
func load_level_from_object(data : Dictionary) -> void:
if data != null:
$VBoxContainer/Name.text = data.name
$VBoxContainer/Left.select_by_name(data.left)
$VBoxContainer/Right.select_by_name(data.right)
$VBoxContainer/Background.select_by_name(data.background)
$Background.texture = load($VBoxContainer/Background.get_selected_filename())
for row in 18:
for col in 13:
var brick = get_node("Bricks/Row%d/Col%d" % [row, col])
var c = data.data[row].substr(col, 1)
brick.set_brick_type(c)
func _on_new_pressed() -> void:
@@ -66,3 +72,16 @@ func _on_new_pressed() -> void:
for col in 13:
var brick = get_node("Bricks/Row%d/Col%d" % [row, col])
brick.set_brick_type(" ")
func _on_export_pressed() -> void:
$ExportPanel.show_panel(get_level_object())
func _on_import_pressed() -> void:
$ImportPanel.show_panel()
func _on_import_panel_object_imported(data: Dictionary) -> void:
load_level_from_object(data)
pass # Replace with function body.

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=9 format=3 uid="uid://bxkneahqum6hb"]
[gd_scene load_steps=11 format=3 uid="uid://bxkneahqum6hb"]
[ext_resource type="Script" path="res://LevelEditor.gd" id="1_p7hit"]
[ext_resource type="Script" path="res://LevelEditCell.gd" id="2_ayd4g"]
@@ -8,6 +8,8 @@
[ext_resource type="Script" path="res://LevelSelector.gd" id="6_brm2b"]
[ext_resource type="Script" path="res://BackgroundSelector.gd" id="7_x1vot"]
[ext_resource type="Script" path="res://LoadPanel.gd" id="8_0o6x4"]
[ext_resource type="Script" path="res://ExportPanel.gd" id="9_nmcps"]
[ext_resource type="Script" path="res://ImportPanel.gd" id="10_q6s0l"]
[node name="LevelEditor" type="Node2D"]
texture_filter = 1
@@ -2027,6 +2029,23 @@ focus_mode = 0
theme = ExtResource("4_usb0o")
text = "SAVE"
[node name="HBoxContainer3" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
[node name="Import" type="Button" parent="VBoxContainer/HBoxContainer3"]
layout_mode = 2
size_flags_horizontal = 3
focus_mode = 0
theme = ExtResource("4_usb0o")
text = "IMPORT"
[node name="Export" type="Button" parent="VBoxContainer/HBoxContainer3"]
layout_mode = 2
size_flags_horizontal = 3
focus_mode = 0
theme = ExtResource("4_usb0o")
text = "EXPORT"
[node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
@@ -2075,10 +2094,77 @@ focus_mode = 0
theme = ExtResource("4_usb0o")
text = "CANCEL"
[node name="ExportPanel" type="PanelContainer" parent="."]
visible = false
offset_left = 464.0
offset_top = 16.0
offset_right = 624.0
offset_bottom = 344.0
theme = ExtResource("4_usb0o")
script = ExtResource("9_nmcps")
[node name="VBoxContainer" type="VBoxContainer" parent="ExportPanel"]
layout_mode = 2
[node name="ExportedCode" type="TextEdit" parent="ExportPanel/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme = ExtResource("4_usb0o")
text = "ewogICJiYWNrZ3JvdW5kIjogIlJlZEJveGVzIiwKICAiZGF0YSI6IFsKICAgICIgICAgICAgICAgICAgIiwKICAgICIgICAgICAgICAgICAgIiwKICAgICIgICAgICAgICAgICAgIiwKICAgICIgICAgICAgICAgICAgIiwKICAgICIgICAgIHNzcyAgICAgIiwKICAgICIgICAgIENDQyAgICAgIiwKICAgICIgICAgIEdHRyAgICAgIiwKICAgICIgICAgIFJSUiAgICAgIiwKICAgICIgICAgIEJCQiAgICAgIiwKICAgICIgICAgIE1NTSAgICAgIiwKICAgICIgICAgIHNzcyAgICAgIiwKICAgICIgICAgICAgICAgICAgIiwKICAgICIgIGcgICBnICAgZyAgIiwKICAgICIgICAgICAgICAgICAgIiwKICAgICIgICAgICAgICAgICAgIiwKICAgICIgICAgICAgICAgICAgIiwKICAgICIgICAgICAgICAgICAgIiwKICAgICIgICAgICAgICAgICAgIgogIF0sCiAgImxlZnQiOiAiRFVOS0FOT0lEIiwKICAibmFtZSI6ICJUT1dFUiIsCiAgInJpZ2h0IjogIkRVTktBTk9JRCIKfQ=="
editable = false
wrap_mode = 1
autowrap_mode = 1
[node name="Close" type="Button" parent="ExportPanel/VBoxContainer"]
layout_mode = 2
theme = ExtResource("4_usb0o")
text = "CLOSE"
[node name="ImportPanel" type="PanelContainer" parent="."]
visible = false
offset_left = 464.0
offset_top = 16.0
offset_right = 624.0
offset_bottom = 344.0
theme = ExtResource("4_usb0o")
script = ExtResource("10_q6s0l")
[node name="VBoxContainer" type="VBoxContainer" parent="ImportPanel"]
layout_mode = 2
[node name="ImportedCode" type="TextEdit" parent="ImportPanel/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme = ExtResource("4_usb0o")
placeholder_text = "Paste code here"
wrap_mode = 1
autowrap_mode = 1
[node name="HBoxContainer" type="HBoxContainer" parent="ImportPanel/VBoxContainer"]
layout_mode = 2
[node name="Import" type="Button" parent="ImportPanel/VBoxContainer/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
theme = ExtResource("4_usb0o")
text = "IMPORT"
[node name="Cancel" type="Button" parent="ImportPanel/VBoxContainer/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
theme = ExtResource("4_usb0o")
text = "CANCEL"
[connection signal="item_selected" from="VBoxContainer/Background" to="." method="_on_background_item_selected"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Load" to="." method="_on_load_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Save" to="." method="_on_save_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer3/Import" to="." method="_on_import_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer3/Export" to="." method="_on_export_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer2/New" to="." method="_on_new_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer2/Exit" to="." method="_on_exit_pressed"]
[connection signal="load_file" from="LoadPanel" to="." method="_on_load_panel_load_file"]
[connection signal="pressed" from="LoadPanel/VBoxContainer/HBoxContainer/Cancel" to="LoadPanel" method="_on_cancel_pressed"]
[connection signal="pressed" from="ExportPanel/VBoxContainer/Close" to="ExportPanel" method="_on_close_pressed"]
[connection signal="object_imported" from="ImportPanel" to="." method="_on_import_panel_object_imported"]
[connection signal="pressed" from="ImportPanel/VBoxContainer/HBoxContainer/Import" to="ImportPanel" method="_on_import_pressed"]
[connection signal="pressed" from="ImportPanel/VBoxContainer/HBoxContainer/Cancel" to="ImportPanel" method="_on_cancel_pressed"]

View File

@@ -9,26 +9,31 @@ func update_level_list() -> void:
vb.remove_child(k)
k.queue_free()
for file in DirAccess.get_files_at("res://Levels"):
if file.ends_with(".json"):
var data = JSON.parse_string(FileAccess.get_file_as_string("res://Levels/%s" % file))
var b = Button.new()
b.theme = load("res://MainTheme.tres")
b.text = data.name
b.size_flags_horizontal = Control.SIZE_EXPAND_FILL
b.pressed.connect(_on_load_file_pressed.bind(b))
b.set_meta("filename", "res://Levels/%s" % file)
vb.add_child(b)
for file in DirAccess.get_files_at("user://Levels"):
if file.ends_with(".json"):
var data = JSON.parse_string(FileAccess.get_file_as_string("user://Levels/%s" % file))
var b = Button.new()
b.theme = load("res://MainTheme.tres")
b.text = data.name
b.theme_type_variation = "UserFile"
b.size_flags_horizontal = Control.SIZE_EXPAND_FILL
b.pressed.connect(_on_load_file_pressed.bind(b))
b.set_meta("filename", "user://Levels/%s" % file)
b.icon = load("res://Icons/User.png")
vb.add_child(b)
for file in DirAccess.get_files_at("res://Levels"):
if file.ends_with(".json"):
var data = JSON.parse_string(FileAccess.get_file_as_string("res://Levels/%s" % file))
var b = Button.new()
b.theme = load("res://MainTheme.tres")
b.theme_type_variation = "InternalFile"
b.text = data.name
b.size_flags_horizontal = Control.SIZE_EXPAND_FILL
b.pressed.connect(_on_load_file_pressed.bind(b))
b.set_meta("filename", "res://Levels/%s" % file)
b.icon = load("res://Icons/Internal.png")
vb.add_child(b)
func show_panel() -> void:
update_level_list()

View File

@@ -1,8 +1,9 @@
[gd_resource type="Theme" load_steps=14 format=3 uid="uid://cfvww0geatnnk"]
[gd_resource type="Theme" load_steps=15 format=3 uid="uid://cfvww0geatnnk"]
[ext_resource type="FontFile" uid="uid://dfkm2dibf0c3b" path="res://Fonts/fonts-DSEG_v046/DSEG7-Classic-MINI/DSEG7ClassicMini-Italic.ttf" id="1_17to7"]
[ext_resource type="FontFile" uid="uid://bx41ej4o03nbx" path="res://Fonts/arkanoid/Arka_solid.ttf" id="1_s07ae"]
[ext_resource type="FontFile" uid="uid://by778rb8miy2e" path="res://Fonts/Ac437_Trident_9x16.ttf" id="2_7inlg"]
[ext_resource type="FontFile" uid="uid://c7hlot6dsm01s" path="res://Fonts/Ac437_Trident_8x8.ttf" id="4_btndm"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_tyvdl"]
content_margin_left = 3.0
@@ -102,6 +103,8 @@ Button/styles/hover = SubResource("StyleBoxFlat_l4f7v")
Button/styles/normal = SubResource("StyleBoxFlat_ibocc")
Button/styles/pressed = SubResource("StyleBoxFlat_ebwwv")
HSeparator/styles/separator = SubResource("StyleBoxEmpty_y3y82")
InternalFile/base_type = &"Button"
InternalFile/colors/font_color = Color(0.670588, 0.458824, 0.52549, 1)
Label/font_sizes/font_size = 20
Label/fonts/font = ExtResource("2_7inlg")
LineEdit/font_sizes/font_size = 20
@@ -120,8 +123,12 @@ Numbers/constants/shadow_outline_size = 3
Numbers/font_sizes/font_size = 18
Numbers/fonts/font = ExtResource("1_17to7")
PanelContainer/styles/panel = SubResource("StyleBoxFlat_sf0ln")
TextEdit/font_sizes/font_size = 9
TextEdit/fonts/font = ExtResource("4_btndm")
Upgrade/base_type = &"Label"
Upgrade/colors/font_color = Color(0, 0, 0, 1)
Upgrade/font_sizes/font_size = 16
Upgrade/fonts/font = ExtResource("2_7inlg")
UserFile/base_type = &"Button"
UserFile/colors/font_color = Color(0.439216, 0.603922, 0.529412, 1)
VSeparator/styles/separator = SubResource("StyleBoxEmpty_m7r63")

View File

@@ -109,16 +109,16 @@ codesign/timestamp_server_url=""
codesign/digest_algorithm=1
codesign/description=""
codesign/custom_options=PackedStringArray()
application/modify_resources=false
application/icon=""
application/console_wrapper_icon=""
application/modify_resources=true
application/icon="res://icon.ico"
application/console_wrapper_icon="res://icon.ico"
application/icon_interpolation=4
application/file_version=""
application/product_version=""
application/company_name="Majenko Technologies"
application/product_name="Dunkanoid"
application/file_description=""
application/copyright=""
application/file_description="Dunkanoid"
application/copyright="2024 Majenko Technologies"
application/trademarks=""
application/export_angle=0
ssh_remote_deploy/enabled=false

BIN
icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

34
icon.png.import Normal file
View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c1lw7q41h1m8f"
path="res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.png"
dest_files=["res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@@ -1 +0,0 @@
<svg height="128" width="128" xmlns="http://www.w3.org/2000/svg"><rect x="2" y="2" width="124" height="124" rx="14" fill="#363d52" stroke="#212532" stroke-width="4"/><g transform="scale(.101) translate(122 122)"><g fill="#fff"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 813 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H447l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c3 34 55 34 58 0v-86c-3-34-55-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></g></svg>

Before

Width:  |  Height:  |  Size: 950 B

View File

@@ -11,11 +11,14 @@ config_version=5
[application]
config/name="Dunkanoid"
config/version="0.5.2"
run/main_scene="res://Intro.tscn"
config/features=PackedStringArray("4.2", "Forward Plus")
run/max_fps=30
boot_splash/show_image=false
config/icon="res://icon.svg"
config/icon="res://icon.png"
config/macos_native_icon="res://icon.png"
config/windows_native_icon="res://icon.ico"
[autoload]