From 3c1974099495b7a7fd92effc4769be9f3e554119 Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Thu, 15 Oct 2020 15:22:38 +0200 Subject: [PATCH] Cards have an energy value --- card.gd | 21 ++++++++++----- card.tscn | 22 ++++++++++++++- cardgame.gd | 77 ++++++++++++++++++++++++++++++++++++++++++++++------- game.gd | 1 + 4 files changed, 104 insertions(+), 17 deletions(-) diff --git a/card.gd b/card.gd index 1ae4073..d3b0816 100644 --- a/card.gd +++ b/card.gd @@ -7,15 +7,25 @@ var drag_offset export var arg_number = 0 export var command = "" setget set_command export var description = "" setget set_description +export var energy = 0 setget set_energy var _first_argument = null var _home_position = null var _home_rotation = null +onready var energy_label = $Sprite/Energy + func _ready(): set_process_unhandled_input(true) + set_energy(energy) func _process(delta): + if game.energy >= energy: + energy_label.modulate = Color(0.5, 1, 0.5) + else: + energy_label.modulate = Color(1, 1, 1) + modulate = Color(1, 0.5, 0.5) + if dragged: var mousepos = get_viewport().get_mouse_position() global_position = mousepos - drag_offset @@ -78,6 +88,11 @@ func set_description(new_description): description = new_description $Description.text = description +func set_energy(new_energy): + energy = new_energy + if energy_label: + energy_label.text = str(energy) + func move_back(): position = _home_position rotation_degrees = _home_rotation @@ -104,9 +119,3 @@ func dropped_on(other): # buuurn() # else: # _first_argument = other.id - - - - - - diff --git a/card.tscn b/card.tscn index 6a91316..2636092 100644 --- a/card.tscn +++ b/card.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://card.gd" type="Script" id=1] [ext_resource path="res://fonts/default.tres" type="DynamicFont" id=2] +[ext_resource path="res://nodes/blob.svg" type="Texture" id=3] [sub_resource type="StyleBoxFlat" id=1] bg_color = Color( 0.45098, 0.584314, 0.843137, 1 ) @@ -96,5 +97,24 @@ autowrap = true __meta__ = { "_edit_use_anchors_": false } + +[node name="Sprite" type="Sprite" parent="."] +position = Vector2( -103.288, -287.778 ) +scale = Vector2( 0.542341, 0.542341 ) +texture = ExtResource( 3 ) + +[node name="Energy" type="Label" parent="Sprite"] +margin_left = -51.1637 +margin_top = -47.4558 +margin_right = -17.1637 +margin_bottom = -16.4558 +rect_scale = Vector2( 3, 3 ) +custom_fonts/font = ExtResource( 2 ) +text = "0" +align = 1 +valign = 1 +__meta__ = { +"_edit_use_anchors_": false +} [connection signal="mouse_entered" from="Area2D" to="." method="_mouse_entered"] [connection signal="mouse_exited" from="Area2D" to="." method="_mouse_exited"] diff --git a/cardgame.gd b/cardgame.gd index fc9de58..1ecfdf4 100644 --- a/cardgame.gd +++ b/cardgame.gd @@ -1,16 +1,72 @@ extends Control var cards = [ - {"command": 'git add .', "arg_number": 0, "description": "Add all files in the working directory to the index."}, - {"command": 'git checkout', "arg_number": 1, "description": "Point HEAD to a branch or commit, and update the index and the working directory."}, - {"command": 'touch "file$RANDOM"', "arg_number": 0, "description": "Create a new file."}, - {"command": 'git commit --allow-empty -m "$RANDOM"', "arg_number": 0, "description": "Add a new commit under HEAD."}, - {"command": 'git checkout -b "$RANDOM"', "arg_number": 0, "description": "Create a new branch and switch to it."}, - {"command": 'git merge', "arg_number": 1, "description": "Merge specified commit into HEAD."}, - {"command": 'git update-ref -d', "arg_number": 1, "description": "Delete a ref."}, - {"command": 'git reflog expire --expire=now --all; git prune', "arg_number": 0, "description": "Delete all unreferenced objects."}, - {"command": 'git rebase', "arg_number": 1, "description": "Rebase current branch on top of specified commit."}, - {"command": 'git push -f', "arg_number": 0, "description": "Push current branch to the remote. Will make everyone angry."}, + { + "command": 'git add .', + "arg_number": 0, + "description": "Add all files in the working directory to the index.", + "energy": 1 + }, + { + "command": 'git checkout', + "arg_number": 1, + "description": "Point HEAD to a branch or commit, and update the index and the working directory.", + "energy": 1 + }, + { + "command": 'touch "file$RANDOM"', + "arg_number": 0, + "description": "Create a new file.", + "energy": 2 + }, + { + "command": 'git commit --allow-empty -m "$RANDOM"', + "arg_number": 0, + "description": "Add a new commit under HEAD.", + "energy": 1 + }, + { + "command": 'git checkout -b "$RANDOM"', + "arg_number": 0, + "description": "Create a new branch and switch to it.", + "energy": 2 + }, + { + "command": 'git merge', + "arg_number": 1, + "description": "Merge specified commit into HEAD.", + "energy": 1 + }, + { + "command": 'git update-ref -d', + "arg_number": 1, + "description": "Delete a ref.", + "energy": 1 + }, + { + "command": 'git reflog expire --expire=now --all; git prune', + "arg_number": 0, + "description": "Delete all unreferenced objects.", + "energy": 1 + }, + { + "command": 'git rebase', + "arg_number": 1, + "description": "Rebase current branch on top of specified commit.", + "energy": 1 + }, + { + "command": 'git push -f', + "arg_number": 0, + "description": "Push current branch to the remote, overwriting existing commits. Will make everyone angry.", + "energy": 3 + }, + { + "command": 'git pull', + "arg_number": 0, + "description": "Pull current branch from the remote.", + "energy": 2 + }, ] func _ready(): @@ -46,6 +102,7 @@ func draw_rand_card(): new_card.command = card.command new_card.arg_number = card.arg_number new_card.description = card.description + new_card.energy = card.energy new_card.position = Vector2(rect_size.x, rect_size.y*2) add_child(new_card) arrange_cards() diff --git a/game.gd b/game.gd index 54a0320..aeaf293 100644 --- a/game.gd +++ b/game.gd @@ -6,6 +6,7 @@ var global_shell var fake_editor var dragged_object +var energy = 2 var _file = "user://savegame.json" var state = {}