Preload all textures

This commit is contained in:
2024-05-12 12:48:21 +01:00
parent 286d70e19c
commit 057cb42efe
13 changed files with 73 additions and 49 deletions

View File

@@ -6,24 +6,15 @@ func _ready() -> void:
func update_background_list() -> void: func update_background_list() -> void:
clear() clear()
var i : int = 0 var i : int = 0
for file in DirAccess.get_files_at("res://Backgrounds"): var keys = Global.Backgrounds.keys()
if file.ends_with(".png.import"): keys.sort()
add_item(file.left(-11), i) for bg in keys:
set_item_metadata(i, "res://Backgrounds/%s" % file.left(-7)) add_item(bg)
i += 1
for file in DirAccess.get_files_at("user://Backgrounds"):
if file.ends_with(".png"):
add_item(file.left(-11), i)
set_item_metadata(i, "user://Backgrounds/%s" % file)
i += 1
func select_by_name(name : String) -> void: func select_by_name(name : String) -> void:
for i in item_count: for i in item_count:
if get_item_text(i) == name: if get_item_text(i) == name:
selected = i selected = i
func get_selected_filename() -> String:
return get_item_metadata(selected)
func get_selected_text() -> String: func get_selected_text() -> String:
return get_item_text(selected) return get_item_text(selected)

View File

@@ -55,22 +55,22 @@ func type(base : int, color : Color) -> void:
original_color = color original_color = color
match base: match base:
NORMAL: NORMAL:
$TextureRect.texture = load("res://Brick/BaseBrick.png") $TextureRect.texture = Global.Bricks["base"]
$TextureRect.modulate = color $TextureRect.modulate = color
hits = 1 hits = 1
value = 100 value = 100
SILVER: SILVER:
$TextureRect.texture = load("res://Brick/ShinyBrick.png") $TextureRect.texture = Global.Bricks["shiny"]
$TextureRect.modulate = color $TextureRect.modulate = color
hits = 2 hits = 2
value = 200 value = 200
GOLD: GOLD:
$TextureRect.texture = load("res://Brick/ShinyBrick.png") $TextureRect.texture = Global.Bricks["shiny"]
$TextureRect.modulate = color $TextureRect.modulate = color
hits = 3 hits = 3
value = 500 value = 500
INVULNERABLE: INVULNERABLE:
$TextureRect.texture = load("res://Brick/InvulBrick.png") $TextureRect.texture = Global.Bricks["invul"]
$TextureRect.modulate = color $TextureRect.modulate = color
hits = 2 hits = 2
value = 0 value = 0

View File

@@ -160,7 +160,7 @@ func new_level() -> void:
BestTimeNode.text = format_time(Global.get_best_time(level_data.name)) BestTimeNode.text = format_time(Global.get_best_time(level_data.name))
StartTitleNode.text = level StartTitleNode.text = level
StartRoundNode.text = "ROUND %3d" % [chr] StartRoundNode.text = "ROUND %3d" % [chr]
BackgroundNode.texture = load("res://Backgrounds/%s.png" % level_data.background) BackgroundNode.texture = Global.Backgrounds.get(level_data.background, null)
BackgroundNode.modulate = Color("#%s" % level_data.get("tint", "FFFFFF")) BackgroundNode.modulate = Color("#%s" % level_data.get("tint", "FFFFFF"))
load_level(level_data.data) load_level(level_data.data)
var ball = _Ball.instantiate() var ball = _Ball.instantiate()

View File

@@ -43,13 +43,13 @@ distance = -432.0
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_48dqy"] [sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_48dqy"]
distance = -360.0 distance = -360.0
[sub_resource type="ShaderMaterial" id="ShaderMaterial_mnwco"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_bxn44"]
shader = ExtResource("12_ljnes") shader = ExtResource("12_ljnes")
shader_parameter/rect_global_position = Vector2(0, 0.226471) shader_parameter/rect_global_position = Vector2(0, 0)
shader_parameter/rect_size = Vector2(448, 25) shader_parameter/rect_size = Vector2(150, 25)
shader_parameter/ColourTexture = ExtResource("13_u52d1") shader_parameter/ColourTexture = ExtResource("13_u52d1")
[sub_resource type="ShaderMaterial" id="ShaderMaterial_xsw3b"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_37u5t"]
shader = ExtResource("12_ljnes") shader = ExtResource("12_ljnes")
shader_parameter/rect_global_position = Vector2(0, 0) shader_parameter/rect_global_position = Vector2(0, 0)
shader_parameter/rect_size = Vector2(89, 25) shader_parameter/rect_size = Vector2(89, 25)
@@ -323,7 +323,7 @@ theme_type_variation = &"RoundStart"
layout_mode = 2 layout_mode = 2
[node name="Title" type="Label" parent="Start/VBoxContainer/PanelContainer/VBoxContainer"] [node name="Title" type="Label" parent="Start/VBoxContainer/PanelContainer/VBoxContainer"]
material = SubResource("ShaderMaterial_mnwco") material = SubResource("ShaderMaterial_bxn44")
layout_mode = 2 layout_mode = 2
theme = ExtResource("8_wcf7g") theme = ExtResource("8_wcf7g")
theme_type_variation = &"Arkanoid" theme_type_variation = &"Arkanoid"
@@ -371,7 +371,7 @@ size_flags_vertical = 3
theme = ExtResource("8_wcf7g") theme = ExtResource("8_wcf7g")
[node name="Label" type="Label" parent="Paused/VBoxContainer"] [node name="Label" type="Label" parent="Paused/VBoxContainer"]
material = SubResource("ShaderMaterial_xsw3b") material = SubResource("ShaderMaterial_37u5t")
layout_mode = 2 layout_mode = 2
theme = ExtResource("8_wcf7g") theme = ExtResource("8_wcf7g")
theme_type_variation = &"Arkanoid" theme_type_variation = &"Arkanoid"

View File

@@ -80,13 +80,21 @@ var laser_autofire : int = 0 :
_save() _save()
# Textures and other resources
var Backgrounds : Dictionary = {}
var Bricks : Dictionary = {
"blank": preload("res://Brick/BlankBrick.png"),
"base": preload("res://Brick/BaseBrick.png"),
"shiny": preload("res://Brick/ShinyBrick.png"),
"invul": preload("res://Brick/InvulBrick.png")
}
var start_level : String = "DUNKANOID" var start_level : String = "DUNKANOID"
var _loading : bool = false var _loading : bool = false
func _ready() -> void: func _ready() -> void:
_loading = true _loading = true
load_backgrounds()
if FileAccess.file_exists("user://data.json"): if FileAccess.file_exists("user://data.json"):
var data = JSON.parse_string(FileAccess.get_file_as_string("user://data.json")) var data = JSON.parse_string(FileAccess.get_file_as_string("user://data.json"))
for s in _settings: for s in _settings:
@@ -162,3 +170,20 @@ func format_powerup_percent() -> String:
func format_ball_split() -> String: func format_ball_split() -> String:
return "%d balls" % get_num_balls() return "%d balls" % get_num_balls()
func load_backgrounds() -> void:
for bg in Backgrounds.values():
bg.free()
Backgrounds.clear()
if DirAccess.dir_exists_absolute("user://Backgrounds"):
for file in DirAccess.get_files_at("user://Backgrounds"):
if file.ends_with(".png") or file.ends_with(".jpg"):
var bgname = file.left(-4)
Backgrounds[bgname] = load("user://Backgrounds/%s" % file)
for file in DirAccess.get_files_at("res://Backgrounds"):
if file.ends_with(".png.import") or file.ends_with(".jpg.import"):
var bgname = file.left(-11)
if not Backgrounds.has(bgname):
Backgrounds[bgname] = load("res://Backgrounds/%s" % file.left(-7))

View File

@@ -20,13 +20,13 @@ point_count = 2
[sub_resource type="Gradient" id="Gradient_431mb"] [sub_resource type="Gradient" id="Gradient_431mb"]
colors = PackedColorArray(0, 0, 0, 0, 1, 1, 1, 1) colors = PackedColorArray(0, 0, 0, 0, 1, 1, 1, 1)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_6jl2f"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_coeve"]
shader = ExtResource("3_eo4f3") shader = ExtResource("3_eo4f3")
shader_parameter/rect_global_position = Vector2(0, 0) shader_parameter/rect_global_position = Vector2(0, 0)
shader_parameter/rect_size = Vector2(150, 25) shader_parameter/rect_size = Vector2(150, 25)
shader_parameter/ColourTexture = ExtResource("4_v8i0c") shader_parameter/ColourTexture = ExtResource("4_v8i0c")
[sub_resource type="ShaderMaterial" id="ShaderMaterial_1smc2"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_04r5o"]
shader = ExtResource("3_eo4f3") shader = ExtResource("3_eo4f3")
shader_parameter/rect_global_position = Vector2(0, 0) shader_parameter/rect_global_position = Vector2(0, 0)
shader_parameter/rect_size = Vector2(242, 25) shader_parameter/rect_size = Vector2(242, 25)
@@ -70,7 +70,7 @@ size_flags_horizontal = 3
theme = ExtResource("3_8d2ix") theme = ExtResource("3_8d2ix")
[node name="ArkaLabel" type="Label" parent="VBoxContainer/HBoxContainer"] [node name="ArkaLabel" type="Label" parent="VBoxContainer/HBoxContainer"]
material = SubResource("ShaderMaterial_6jl2f") material = SubResource("ShaderMaterial_coeve")
layout_mode = 2 layout_mode = 2
theme = ExtResource("3_8d2ix") theme = ExtResource("3_8d2ix")
theme_type_variation = &"Arkanoid" theme_type_variation = &"Arkanoid"
@@ -91,7 +91,7 @@ size_flags_horizontal = 3
theme = ExtResource("3_8d2ix") theme = ExtResource("3_8d2ix")
[node name="Revenge" type="Label" parent="VBoxContainer/HBoxContainer2"] [node name="Revenge" type="Label" parent="VBoxContainer/HBoxContainer2"]
material = SubResource("ShaderMaterial_1smc2") material = SubResource("ShaderMaterial_04r5o")
layout_mode = 2 layout_mode = 2
theme = ExtResource("3_8d2ix") theme = ExtResource("3_8d2ix")
theme_type_variation = &"Arkanoid" theme_type_variation = &"Arkanoid"

View File

@@ -64,7 +64,7 @@ func load_from_file(filename : String) -> void:
func load_from_data(data : Dictionary) -> void: func load_from_data(data : Dictionary) -> void:
purge_bricks() purge_bricks()
level_data = data level_data = data
Background.texture = load("res://Backgrounds/%s.png" % level_data.background) Background.texture = Global.Backgrounds.get(level_data.background, null)
Background.modulate = Color("#%s" % level_data.get("tint", "FFFFFF")) Background.modulate = Color("#%s" % level_data.get("tint", "FFFFFF"))
for y in level_data.data.size(): for y in level_data.data.size():
var line : String = level_data.data[y] var line : String = level_data.data[y]
@@ -107,8 +107,8 @@ func load_from_data(data : Dictionary) -> void:
func purge_bricks() -> void: func purge_bricks() -> void:
for brick in bricks: for brick in bricks:
BricksNode.call_deferred("remove_child", brick) BricksNode.remove_child(brick)
brick.call_deferred("queue_free") brick.queue_free()
bricks.clear() bricks.clear()
func _brick_destroyed(brick : Node2D) -> void: func _brick_destroyed(brick : Node2D) -> void:

View File

@@ -35,50 +35,50 @@ func _input(event : InputEvent) -> void:
func set_brick_type(t : String) -> void: func set_brick_type(t : String) -> void:
match t: match t:
"R": "R":
texture = load("res://Brick/BaseBrick.png") texture = Global.Bricks["base"]
modulate = Color.RED modulate = Color.RED
type = "R" type = "R"
"Y": "Y":
texture = load("res://Brick/BaseBrick.png") texture = Global.Bricks["base"]
modulate = Color.YELLOW modulate = Color.YELLOW
type = "Y" type = "Y"
"G": "G":
texture = load("res://Brick/BaseBrick.png") texture = Global.Bricks["base"]
modulate = Color.GREEN modulate = Color.GREEN
type = "G" type = "G"
"B": "B":
texture = load("res://Brick/BaseBrick.png") texture = Global.Bricks["base"]
modulate = Color.ROYAL_BLUE modulate = Color.ROYAL_BLUE
type = "B" type = "B"
"M": "M":
texture = load("res://Brick/BaseBrick.png") texture = Global.Bricks["base"]
modulate = Color.MAGENTA modulate = Color.MAGENTA
type = "M" type = "M"
"C": "C":
texture = load("res://Brick/BaseBrick.png") texture = Global.Bricks["base"]
modulate = Color.CYAN modulate = Color.CYAN
type = "C" type = "C"
"O": "O":
texture = load("res://Brick/BaseBrick.png") texture = Global.Bricks["base"]
modulate = Color.ORANGE modulate = Color.ORANGE
type = "O" type = "O"
"W": "W":
texture = load("res://Brick/BaseBrick.png") texture = Global.Bricks["base"]
modulate = Color.WHITE modulate = Color.WHITE
type = "W" type = "W"
"s": "s":
texture = load("res://Brick/ShinyBrick.png") texture = Global.Bricks["shiny"]
modulate = Color.SILVER modulate = Color.SILVER
type = "s" type = "s"
"g": "g":
texture = load("res://Brick/ShinyBrick.png") texture = Global.Bricks["shiny"]
modulate = Color.GOLD modulate = Color.GOLD
type = "g" type = "g"
"i": "i":
texture = load("res://Brick/InvulBrick.png") texture = Global.Bricks["invul"]
modulate = Color.GRAY modulate = Color.GRAY
type = "i" type = "i"
" ": " ":
texture = load("res://Brick/BlankBrick.png") texture = Global.Bricks["blank"]
modulate = Color.WHITE modulate = Color.WHITE
type = " " type = " "

View File

@@ -7,7 +7,7 @@ func _ready() -> void:
Music.pause() Music.pause()
func _on_background_item_selected(index: int) -> void: func _on_background_item_selected(index: int) -> void:
$Background.texture = load($VBoxContainer/Background.get_item_metadata(index)) $Background.texture = Global.Backgrounds.get($VBoxContainer/Background.get_selected_text(), null)
func get_level_object() -> Dictionary: func get_level_object() -> Dictionary:
var data : Dictionary = { var data : Dictionary = {
@@ -61,7 +61,7 @@ func load_level_from_object(data : Dictionary) -> void:
$VBoxContainer/Left.select_by_name(data.get("left", "DUNKANOID")) $VBoxContainer/Left.select_by_name(data.get("left", "DUNKANOID"))
$VBoxContainer/Right.select_by_name(data.get("right", "DUNKANOID")) $VBoxContainer/Right.select_by_name(data.get("right", "DUNKANOID"))
$VBoxContainer/Background.select_by_name(data.get("background", "BlueSlash")) $VBoxContainer/Background.select_by_name(data.get("background", "BlueSlash"))
$Background.texture = load($VBoxContainer/Background.get_selected_filename()) $Background.texture = Global.Backgrounds.get($VBoxContainer/Background.get_selected_text())
$VBoxContainer/Tint.text = data.get("tint", "FFFFFF") $VBoxContainer/Tint.text = data.get("tint", "FFFFFF")
$Background.modulate = Color("#%s" % $VBoxContainer/Tint.text) $Background.modulate = Color("#%s" % $VBoxContainer/Tint.text)
for row in 18: for row in 18:

View File

@@ -1,6 +1,7 @@
extends Node2D extends Node2D
func _ready() -> void: func _ready() -> void:
$VBoxContainer/Version.text = "Version %s" % ProjectSettings.get_setting("application/config/version")
$VBoxContainer/HBoxContainer/LeftPanel/Relative.button_pressed = Global.relative_mouse $VBoxContainer/HBoxContainer/LeftPanel/Relative.button_pressed = Global.relative_mouse
$VBoxContainer/HBoxContainer/LeftPanel/Absolute.button_pressed = !Global.relative_mouse $VBoxContainer/HBoxContainer/LeftPanel/Absolute.button_pressed = !Global.relative_mouse
$VBoxContainer/HBoxContainer/RightPanel/Music.set_value_no_signal(Global.music_volume) $VBoxContainer/HBoxContainer/RightPanel/Music.set_value_no_signal(Global.music_volume)

View File

@@ -14,6 +14,13 @@ offset_top = 32.0
offset_right = 608.0 offset_right = 608.0
offset_bottom = 328.0 offset_bottom = 328.0
[node name="Version" type="Label" parent="VBoxContainer"]
layout_mode = 2
theme = ExtResource("1_lirja")
text = "0.0.0"
horizontal_alignment = 2
vertical_alignment = 1
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] [node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2 layout_mode = 2
size_flags_vertical = 3 size_flags_vertical = 3

View File

@@ -18,7 +18,7 @@ point_count = 2
[sub_resource type="Gradient" id="Gradient_ucorl"] [sub_resource type="Gradient" id="Gradient_ucorl"]
colors = PackedColorArray(0, 0, 0, 0, 1, 1, 1, 1) colors = PackedColorArray(0, 0, 0, 0, 1, 1, 1, 1)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_v7t7t"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_0g7aw"]
shader = ExtResource("4_waenw") shader = ExtResource("4_waenw")
shader_parameter/rect_global_position = Vector2(8, 8) shader_parameter/rect_global_position = Vector2(8, 8)
shader_parameter/rect_size = Vector2(127, 25) shader_parameter/rect_size = Vector2(127, 25)
@@ -76,7 +76,7 @@ autoplay = "default"
centered = false centered = false
[node name="ArkaLabel" type="Label" parent="VBoxContainer"] [node name="ArkaLabel" type="Label" parent="VBoxContainer"]
material = SubResource("ShaderMaterial_v7t7t") material = SubResource("ShaderMaterial_0g7aw")
layout_mode = 2 layout_mode = 2
size_flags_vertical = 6 size_flags_vertical = 6
theme = ExtResource("1_rv7oa") theme = ExtResource("1_rv7oa")

View File

@@ -11,7 +11,7 @@ config_version=5
[application] [application]
config/name="Dunkanoid" config/name="Dunkanoid"
config/version="0.9.4" config/version="0.9.6"
run/main_scene="res://Intro.tscn" run/main_scene="res://Intro.tscn"
config/features=PackedStringArray("4.2", "Forward Plus") config/features=PackedStringArray("4.2", "Forward Plus")
run/max_fps=30 run/max_fps=30