From aed852122b6468e2aa201e5b7dc1510bf37cf08c Mon Sep 17 00:00:00 2001 From: blinry Date: Thu, 21 Jan 2021 15:08:59 +0100 Subject: [PATCH] Badges when you don't use cards --- images/cli-badge.svg | 134 ++++++++++++++++++++++++++++++++++++ images/cli-badge.svg.import | 34 +++++++++ scenes/card.gd | 1 + scenes/cli_badge.gd | 21 ++++++ scenes/cli_badge.tscn | 45 ++++++++++++ scenes/game.gd | 3 +- scenes/level_select.gd | 14 +++- scenes/level_select.tscn | 4 ++ scenes/main.gd | 12 +++- scenes/main.tscn | 22 ++++-- 10 files changed, 278 insertions(+), 12 deletions(-) create mode 100644 images/cli-badge.svg create mode 100644 images/cli-badge.svg.import create mode 100644 scenes/cli_badge.gd create mode 100644 scenes/cli_badge.tscn diff --git a/images/cli-badge.svg b/images/cli-badge.svg new file mode 100644 index 0000000..36cfd86 --- /dev/null +++ b/images/cli-badge.svg @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/images/cli-badge.svg.import b/images/cli-badge.svg.import new file mode 100644 index 0000000..53031f8 --- /dev/null +++ b/images/cli-badge.svg.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/cli-badge.svg-d681319a61408aabc3551843085f21db.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://images/cli-badge.svg" +dest_files=[ "res://.import/cli-badge.svg-d681319a61408aabc3551843085f21db.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/scenes/card.gd b/scenes/card.gd index 1e4d565..a06335a 100644 --- a/scenes/card.gd +++ b/scenes/card.gd @@ -136,6 +136,7 @@ func try_play(full_command): var terminal = $"../../../..".terminal terminal.send_command(full_command) #yield(terminal, "command_done") + game.used_cards = true $PlaySound.play() var particles = preload("res://scenes/card_particles.tscn").instance() particles.position = position diff --git a/scenes/cli_badge.gd b/scenes/cli_badge.gd new file mode 100644 index 0000000..4884444 --- /dev/null +++ b/scenes/cli_badge.gd @@ -0,0 +1,21 @@ +extends TextureRect + +export var active = true setget _set_active +export var sparkling = true setget _set_sparkling + + +func _ready(): + _set_sparkling(sparkling) + +func _set_active(new_active): + active = new_active + if active: + self.modulate = Color(1, 1, 1) + else: + self.modulate = Color(0.2, 0.2, 0.2) + sparkling = false + +func _set_sparkling(new_sparkling): + sparkling = new_sparkling + if $Particles2D: + $Particles2D.emitting = sparkling diff --git a/scenes/cli_badge.tscn b/scenes/cli_badge.tscn new file mode 100644 index 0000000..86347b8 --- /dev/null +++ b/scenes/cli_badge.tscn @@ -0,0 +1,45 @@ +[gd_scene load_steps=6 format=2] + +[ext_resource path="res://images/cli-badge.svg" type="Texture" id=1] +[ext_resource path="res://scenes/cli_badge.gd" type="Script" id=2] + +[sub_resource type="Curve" id=2] +_data = [ Vector2( 0, 1 ), 0.0, 0.0, 0, 0, Vector2( 1, 0 ), 0.0, 0.0, 0, 0 ] + +[sub_resource type="CurveTexture" id=3] +curve = SubResource( 2 ) + +[sub_resource type="ParticlesMaterial" id=1] +emission_shape = 2 +emission_box_extents = Vector3( 20, 20, 1 ) +flag_disable_z = true +spread = 180.0 +gravity = Vector3( 0, 0, 0 ) +initial_velocity = 75.0 +initial_velocity_random = 0.47 +orbit_velocity = 0.0 +orbit_velocity_random = 0.0 +scale = 7.25 +scale_curve = SubResource( 3 ) +color = Color( 0.913725, 0.913725, 0.447059, 1 ) + +[node name="CLIBadge" type="TextureRect"] +anchor_right = 1.0 +anchor_bottom = 1.0 +rect_min_size = Vector2( 45, 0 ) +size_flags_stretch_ratio = 0.0 +texture = ExtResource( 1 ) +expand = true +stretch_mode = 6 +script = ExtResource( 2 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Particles2D" type="Particles2D" parent="."] +show_behind_parent = true +position = Vector2( 21.7701, 14.5133 ) +z_index = 1 +amount = 3 +randomness = 0.34 +process_material = SubResource( 1 ) diff --git a/scenes/game.gd b/scenes/game.gd index 4261d20..aa68229 100644 --- a/scenes/game.gd +++ b/scenes/game.gd @@ -6,6 +6,7 @@ var fake_editor var dragged_object var energy = 2 +var used_cards = false var current_chapter = 0 var current_level = 0 @@ -28,7 +29,7 @@ func copy_script_to_game_env(name): global_shell.run("chmod u+x '%s'" % (tmp_prefix + name)) func _initial_state(): - return {"history": [], "solved_levels": [], "received_hints": []} + return {"history": [], "solved_levels": [], "received_hints": [], "cli_badge": []} func save_state(): var savegame = File.new() diff --git a/scenes/level_select.gd b/scenes/level_select.gd index 026a640..b4acec3 100644 --- a/scenes/level_select.gd +++ b/scenes/level_select.gd @@ -32,16 +32,28 @@ func reload(): level_list.add_child(l) for level in chapter.levels: + var hb = HBoxContainer.new() + var b = Button.new() b.text = level.title b.align = HALIGN_LEFT + b.size_flags_horizontal = SIZE_EXPAND_FILL + b.connect("pressed", self, "load", [chapter_id, level_id]) var slug = chapter.slug + "/" + level.slug if slug in game.state["solved_levels"]: b.set("custom_colors/font_color", Color(0.1, 0.8, 0.1, 1)) b.set("custom_colors/font_color_hover", Color(0.1, 0.8, 0.1, 1)) b.set("custom_colors/font_color_pressed", Color(0.1, 0.8, 0.1, 1)) - level_list.add_child(b) + + hb.add_child(b) +# + var badge = preload("res://scenes/cli_badge.tscn").instance() + hb.add_child(badge) + badge.active = slug in game.state["cli_badge"] + badge.sparkling = false + + level_list.add_child(hb) level_id += 1 chapter_id += 1 diff --git a/scenes/level_select.tscn b/scenes/level_select.tscn index 84f0834..dae7f6c 100644 --- a/scenes/level_select.tscn +++ b/scenes/level_select.tscn @@ -52,5 +52,9 @@ text = "Reload" __meta__ = { "_edit_use_anchors_": false } + +[node name="TextureRect" type="TextureRect" parent="Button2"] +margin_right = 40.0 +margin_bottom = 40.0 [connection signal="pressed" from="Button" to="." method="back"] [connection signal="pressed" from="Button2" to="." method="reload"] diff --git a/scenes/main.gd b/scenes/main.gd index 8ce76e2..de94ab2 100644 --- a/scenes/main.gd +++ b/scenes/main.gd @@ -50,7 +50,8 @@ func _process(delta): var length = _hint_client_connection.get_u32() var message = _hint_client_connection.get_string(length) game.notify(message) - + if game.used_cards: + $Menu/CLIBadge.active = false func load_chapter(id): game.current_chapter = id @@ -61,6 +62,9 @@ func load_level(level_id): level_congrats.hide() level_description.show() game.current_level = level_id + game.used_cards = false + $Menu/CLIBadge.active = true + $Menu/CLIBadge.sparkling = false AudioServer.set_bus_mute(AudioServer.get_bus_index("Master"), true) @@ -169,12 +173,14 @@ func show_win_status(win_states): level_description.hide() level_congrats.show() $SuccessSound.play() - if not game.state.has("solved_levels"): - game.state["solved_levels"] = [] var slug = levels.chapters[game.current_chapter].slug + "/" + level.slug if not slug in game.state["solved_levels"]: game.state["solved_levels"].push_back(slug) game.save_state() + if not game.used_cards and not slug in game.state["cli_badge"]: + game.state["cli_badge"].push_back(slug) + game.save_state() + $Menu/CLIBadge.sparkling = true #func repopulate_levels(): # levels.reload() diff --git a/scenes/main.tscn b/scenes/main.tscn index 2fee607..7db0420 100644 --- a/scenes/main.tscn +++ b/scenes/main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=12 format=2] +[gd_scene load_steps=13 format=2] [ext_resource path="res://scenes/terminal.tscn" type="PackedScene" id=1] [ext_resource path="res://scenes/main.gd" type="Script" id=2] @@ -9,11 +9,12 @@ [ext_resource path="res://fonts/big.tres" type="DynamicFont" id=7] [ext_resource path="res://sounds/success.wav" type="AudioStream" id=8] [ext_resource path="res://scenes/cursor.gd" type="Script" id=9] +[ext_resource path="res://scenes/cli_badge.tscn" type="PackedScene" id=10] -[sub_resource type="CircleShape2D" id=2] +[sub_resource type="CircleShape2D" id=1] radius = 1.0 -[sub_resource type="StyleBoxFlat" id=1] +[sub_resource type="StyleBoxFlat" id=2] content_margin_left = 10.0 content_margin_right = 10.0 content_margin_top = 5.0 @@ -189,7 +190,7 @@ collision_layer = 524288 collision_mask = 0 [node name="CollisionShape2D" type="CollisionShape2D" parent="Cursor/Area2D"] -shape = SubResource( 2 ) +shape = SubResource( 1 ) [node name="Menu" type="HBoxContainer" parent="."] margin_left = 3.86392 @@ -246,12 +247,19 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="NextLevelButton" type="Button" parent="Menu"] +[node name="CLIBadge" parent="Menu" instance=ExtResource( 10 )] +anchor_right = 0.0 +anchor_bottom = 0.0 margin_left = 169.0 -margin_right = 286.0 +margin_right = 214.0 +margin_bottom = 39.0 + +[node name="NextLevelButton" type="Button" parent="Menu"] +margin_left = 222.0 +margin_right = 339.0 margin_bottom = 39.0 focus_mode = 0 -custom_styles/hover = SubResource( 1 ) +custom_styles/hover = SubResource( 2 ) custom_styles/normal = ExtResource( 4 ) enabled_focus_mode = 0 text = "Next level"