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:
clear()
var i : int = 0
for file in DirAccess.get_files_at("res://Backgrounds"):
if file.ends_with(".png.import"):
add_item(file.left(-11), i)
set_item_metadata(i, "res://Backgrounds/%s" % file.left(-7))
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
var keys = Global.Backgrounds.keys()
keys.sort()
for bg in keys:
add_item(bg)
func select_by_name(name : String) -> void:
for i in item_count:
if get_item_text(i) == name:
selected = i
func get_selected_filename() -> String:
return get_item_metadata(selected)
func get_selected_text() -> String:
return get_item_text(selected)

View File

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

View File

@@ -160,7 +160,7 @@ func new_level() -> void:
BestTimeNode.text = format_time(Global.get_best_time(level_data.name))
StartTitleNode.text = level
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"))
load_level(level_data.data)
var ball = _Ball.instantiate()

View File

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

View File

@@ -80,13 +80,21 @@ var laser_autofire : int = 0 :
_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 _loading : bool = false
func _ready() -> void:
_loading = true
load_backgrounds()
if FileAccess.file_exists("user://data.json"):
var data = JSON.parse_string(FileAccess.get_file_as_string("user://data.json"))
for s in _settings:
@@ -162,3 +170,20 @@ func format_powerup_percent() -> String:
func format_ball_split() -> String:
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"]
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_parameter/rect_global_position = Vector2(0, 0)
shader_parameter/rect_size = Vector2(150, 25)
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_parameter/rect_global_position = Vector2(0, 0)
shader_parameter/rect_size = Vector2(242, 25)
@@ -70,7 +70,7 @@ size_flags_horizontal = 3
theme = ExtResource("3_8d2ix")
[node name="ArkaLabel" type="Label" parent="VBoxContainer/HBoxContainer"]
material = SubResource("ShaderMaterial_6jl2f")
material = SubResource("ShaderMaterial_coeve")
layout_mode = 2
theme = ExtResource("3_8d2ix")
theme_type_variation = &"Arkanoid"
@@ -91,7 +91,7 @@ size_flags_horizontal = 3
theme = ExtResource("3_8d2ix")
[node name="Revenge" type="Label" parent="VBoxContainer/HBoxContainer2"]
material = SubResource("ShaderMaterial_1smc2")
material = SubResource("ShaderMaterial_04r5o")
layout_mode = 2
theme = ExtResource("3_8d2ix")
theme_type_variation = &"Arkanoid"

View File

@@ -64,7 +64,7 @@ func load_from_file(filename : String) -> void:
func load_from_data(data : Dictionary) -> void:
purge_bricks()
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"))
for y in level_data.data.size():
var line : String = level_data.data[y]
@@ -107,8 +107,8 @@ func load_from_data(data : Dictionary) -> void:
func purge_bricks() -> void:
for brick in bricks:
BricksNode.call_deferred("remove_child", brick)
brick.call_deferred("queue_free")
BricksNode.remove_child(brick)
brick.queue_free()
bricks.clear()
func _brick_destroyed(brick : Node2D) -> void:

View File

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

View File

@@ -7,7 +7,7 @@ func _ready() -> void:
Music.pause()
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:
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/Right.select_by_name(data.get("right", "DUNKANOID"))
$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")
$Background.modulate = Color("#%s" % $VBoxContainer/Tint.text)
for row in 18:

View File

@@ -1,6 +1,7 @@
extends Node2D
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/Absolute.button_pressed = !Global.relative_mouse
$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_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"]
layout_mode = 2
size_flags_vertical = 3

View File

@@ -18,7 +18,7 @@ point_count = 2
[sub_resource type="Gradient" id="Gradient_ucorl"]
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_parameter/rect_global_position = Vector2(8, 8)
shader_parameter/rect_size = Vector2(127, 25)
@@ -76,7 +76,7 @@ autoplay = "default"
centered = false
[node name="ArkaLabel" type="Label" parent="VBoxContainer"]
material = SubResource("ShaderMaterial_v7t7t")
material = SubResource("ShaderMaterial_0g7aw")
layout_mode = 2
size_flags_vertical = 6
theme = ExtResource("1_rv7oa")

View File

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