Skip to content

Commit

Permalink
Patched skin save bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Killarexe committed Mar 4, 2023
1 parent 283a699 commit b68653e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 24 deletions.
4 changes: 2 additions & 2 deletions animations/splash_animation.tres
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.5 ),
"transitions": PoolRealArray( 1, 1 ),
"transitions": PoolRealArray( 0.75, 0.75 ),
"update": 0,
"values": [ Vector2( 0.5, 0.5 ), Vector2( 1, 1 ) ]
"values": [ Vector2( 0.5, 0.5 ), Vector2( 0.8, 0.8 ) ]
}
19 changes: 17 additions & 2 deletions default.tres
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_resource type="Theme" load_steps=6 format=2]
[gd_resource type="Theme" load_steps=7 format=2]

[ext_resource path="res://fonts/default.tres" type="DynamicFont" id=1]

Expand All @@ -17,6 +17,21 @@ shadow_color = Color( 0, 0, 0, 0.67451 )
shadow_size = 1
shadow_offset = Vector2( 15, 15 )

[sub_resource type="StyleBoxFlat" id=5]
bg_color = Color( 0.886275, 0.262745, 0.262745, 1 )
border_width_left = 6
border_width_top = 6
border_width_right = 6
border_width_bottom = 6
border_color = Color( 1, 1, 1, 1 )
corner_radius_top_left = 12
corner_radius_top_right = 12
corner_radius_bottom_right = 12
corner_radius_bottom_left = 12
shadow_color = Color( 0, 0, 0, 0.67451 )
shadow_size = 1
shadow_offset = Vector2( 12, 12 )

[sub_resource type="StyleBoxFlat" id=2]
bg_color = Color( 0.886275, 0.262745, 0.262745, 1 )
border_width_left = 6
Expand Down Expand Up @@ -66,7 +81,7 @@ shadow_offset = Vector2( 15, 15 )
resource_name = "Default"
default_font = ExtResource( 1 )
Button/styles/disabled = SubResource( 3 )
Button/styles/focus = SubResource( 2 )
Button/styles/focus = SubResource( 5 )
Button/styles/hover = SubResource( 2 )
Button/styles/normal = SubResource( 1 )
Button/styles/pressed = SubResource( 4 )
Expand Down
14 changes: 4 additions & 10 deletions scenes/ui/MainMenu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ __meta__ = {
[node name="ShopButton" type="Button" parent="Buttons"]
anchor_top = 1.0
anchor_bottom = 1.0
margin_top = -70.0
margin_top = -76.0
margin_right = 268.0
theme = ExtResource( 8 )
text = "Shop"
Expand All @@ -195,7 +195,7 @@ anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = -524.0
margin_top = -70.0
margin_top = -76.0
theme = ExtResource( 8 )
text = "Settings"

Expand Down Expand Up @@ -253,9 +253,6 @@ custom_fonts/font = ExtResource( 3 )
text = "Little Rage"
align = 1
valign = 1
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Splash" type="Label" parent="CanvasLayer"]
margin_left = 180.457
Expand All @@ -265,7 +262,7 @@ margin_bottom = 434.863
grow_horizontal = 2
grow_vertical = 2
rect_rotation = -15.0
rect_scale = Vector2( 0.574571, 0.574571 )
rect_scale = Vector2( 0.507826, 0.507826 )
size_flags_horizontal = 0
size_flags_vertical = 0
custom_colors/font_color = Color( 1, 1, 0, 1 )
Expand All @@ -274,9 +271,6 @@ text = "Splash Text"
align = 1
valign = 1
autowrap = true
__meta__ = {
"_edit_use_anchors_": false
}

[node name="AnimationPlayer" type="AnimationPlayer" parent="CanvasLayer/Splash"]
anims/splash_animation = ExtResource( 2 )
Expand Down Expand Up @@ -309,7 +303,7 @@ valign = 1
scale = Vector2( 1e-05, 1e-05 )
offset = Vector2( 960, 540 )
smoothing_enabled = true
smoothing_speed = 3.0
smoothing_speed = 4.0

[node name="AnimationPlayer" type="AnimationPlayer" parent="Camera2D"]
anims/RESET = SubResource( 36 )
Expand Down
13 changes: 8 additions & 5 deletions scripts/Global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ var levels: Array = [
]

var coins: int = 0
var currentLevel: int;
var currentSkin = skins[0]
var currentLevel: int
var currentSkin: int = 0
var ableToPause: bool = true
var unlocked_hats: Array = [0]
var unlockedSkins: Array = [0]
Expand All @@ -40,8 +40,7 @@ var editor_playing: bool = false
const saveFilePath = "user://player_save.save"

func _ready():
if OS.is_debug_build():
Global.currentSkin = Global.skins[7]
loadGame()

func wait(sec: int, node: Node):
var t = Timer.new()
Expand Down Expand Up @@ -95,6 +94,7 @@ func saveGame():
var data ={
"coins": coins,
#"hats": unlocked_hats,
"current_skin": currentSkin,
"music_volume": AudioServer.get_bus_volume_db(AudioServer.get_bus_index("Music")),
"sfxs_volume": AudioServer.get_bus_volume_db(AudioServer.get_bus_index("SFXS")),
"skins": unlockedSkins,
Expand All @@ -103,7 +103,7 @@ func saveGame():
saveFile.store_var(data)
saveFile.close()

func get_save_data(data, name, default_value):
func get_save_data(data: Dictionary, name: String, default_value):
if(data.has(name)):
return data[name]
return default_value
Expand All @@ -119,6 +119,7 @@ func loadGame():
saveGame()
return
coins = get_save_data(data, "coins", 0)
currentSkin = get_save_data(data, "current_skin", 0)
unlocked_hats = get_save_data(data, "hats", [0])
unlockedSkins =get_save_data(data, "skins", [0])
unlockedLevels = get_save_data(data, "levels", [0])
Expand All @@ -131,6 +132,8 @@ func loadGame():
get_save_data(data, "sfxs_volume", 0)
)
saveFile.close()
if OS.is_debug_build() && Global.currentSkin == 0:
Global.currentSkin = 7

func resetGame():
var saveFile = File.new()
Expand Down
2 changes: 1 addition & 1 deletion scripts/level/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func _ready():
$GUI/RightButton.visible = false
$GUI/JumpButton.visible = false
$Camera2D.current = enable_camera
$Sprite.texture = Global.currentSkin[0]
$Sprite.texture = Global.skins[Global.currentSkin][0]

func _process(delta):
if !enable_camera:
Expand Down
9 changes: 5 additions & 4 deletions scripts/ui/MainMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var images = [load("res://textures/backgrounds/Image1.png"), load("res://texture
onready var splash = $CanvasLayer/Splash

func _ready():
Global.loadGame()
Global.play_music(1)
var random = RandomNumberGenerator.new()
random.randomize()
Expand Down Expand Up @@ -47,6 +46,7 @@ func show_shop(show: bool) -> void:
$Buttons/NextButton.visible = show
$Buttons/PreviousButton.visible = show
if(show):
selectedSkin = Global.currentSkin
updateSprite()

func updateSprite():
Expand All @@ -56,10 +56,10 @@ func updateSprite():
$Buttons/BuyButton.text = "Buy"
if(Global.unlockedSkins.has(selectedSkin)):
$Buttons/BuyButton.text = "Equip"
if(Global.currentSkin == Global.skins[selectedSkin]):
if(Global.currentSkin == selectedSkin):
$Buttons/BuyButton.text = "Equiped"

if(Global.skins[selectedSkin][1] > Global.coins && !Global.unlockedSkins.has(selectedSkin)) || Global.currentSkin == Global.skins[selectedSkin]:
if(Global.skins[selectedSkin][1] > Global.coins && !Global.unlockedSkins.has(selectedSkin)) || Global.currentSkin == selectedSkin:
$Buttons/BuyButton.disabled = true
else:
$Buttons/BuyButton.disabled = false
Expand All @@ -75,7 +75,8 @@ func _on_BuyButton_pressed():
if(!Global.unlockedSkins.has(selectedSkin)):
Global.unlockSkin(selectedSkin)
else:
Global.currentSkin = Global.skins[selectedSkin]
Global.currentSkin = selectedSkin
Global.saveGame()
updateSprite()

func _on_PreviousButton_pressed():
Expand Down

0 comments on commit b68653e

Please sign in to comment.