Can only play cards until energy is used up

This commit is contained in:
Sebastian Morr 2020-10-15 15:53:23 +02:00
parent 3c19740994
commit 01bc31b210
4 changed files with 67 additions and 18 deletions

19
card.gd
View file

@ -62,11 +62,9 @@ func _unhandled_input(event):
game.dragged_object = null game.dragged_object = null
modulate.a = 1 modulate.a = 1
if get_viewport().get_mouse_position().y < get_viewport().size.y/3*2: if get_viewport().get_mouse_position().y < get_viewport().size.y/3*2:
if arg_number == 0 : if arg_number == 0 :
$"../../..".terminal.send_command($Label.text) try_play($Label.text)
buuurn()
else: else:
move_back() move_back()
else: else:
@ -99,8 +97,8 @@ func move_back():
func buuurn(): func buuurn():
queue_free() queue_free()
$"..".draw_rand_card() #$"..".draw_rand_card()
#$"..".arrange_cards() $"..".arrange_cards()
func dropped_on(other): func dropped_on(other):
var full_command = "" var full_command = ""
@ -110,8 +108,7 @@ func dropped_on(other):
if ($Label.text.begins_with("git checkout") or $Label.text.begins_with("git rebase")) and other.id.begins_with("refs/heads"): if ($Label.text.begins_with("git checkout") or $Label.text.begins_with("git rebase")) and other.id.begins_with("refs/heads"):
argument = Array(other.id.split("/")).pop_back() argument = Array(other.id.split("/")).pop_back()
full_command = $Label.text + " " + argument full_command = $Label.text + " " + argument
$"../../..".terminal.send_command(full_command) try_play(full_command)
buuurn()
# 2: # 2:
# if _first_argument: # if _first_argument:
# full_command = $Label.text + " " + _first_argument + " " + other.id # full_command = $Label.text + " " + _first_argument + " " + other.id
@ -119,3 +116,11 @@ func dropped_on(other):
# buuurn() # buuurn()
# else: # else:
# _first_argument = other.id # _first_argument = other.id
func try_play(command):
if game.energy >= energy:
$"../../..".terminal.send_command(command)
buuurn()
game.energy -= energy
else:
move_back()

View file

@ -2,9 +2,9 @@ extends Control
var cards = [ var cards = [
{ {
"command": 'git add .', "command": 'git commit --allow-empty -m "$RANDOM"',
"arg_number": 0, "arg_number": 0,
"description": "Add all files in the working directory to the index.", "description": "Add a new commit under HEAD.",
"energy": 1 "energy": 1
}, },
{ {
@ -13,18 +13,19 @@ var cards = [
"description": "Point HEAD to a branch or commit, and update the index and the working directory.", "description": "Point HEAD to a branch or commit, and update the index and the working directory.",
"energy": 1 "energy": 1
}, },
{
"command": 'git add .',
"arg_number": 0,
"description": "Add all files in the working directory to the index.",
"energy": 1
},
{ {
"command": 'touch "file$RANDOM"', "command": 'touch "file$RANDOM"',
"arg_number": 0, "arg_number": 0,
"description": "Create a new file.", "description": "Create a new file.",
"energy": 2 "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"', "command": 'git checkout -b "$RANDOM"',
"arg_number": 0, "arg_number": 0,
@ -92,13 +93,27 @@ func _ready():
redraw_all_cards() redraw_all_cards()
arrange_cards() arrange_cards()
func _process(delta):
if $Energy:
$Energy.text = str(game.energy)
#func _update_repo(): #func _update_repo():
# $Repository.update_everything() # $Repository.update_everything()
# $RepositoryRemote.update_everything() # $RepositoryRemote.update_everything()
func draw_rand_card(): func draw_rand_card():
var deck = []
for card in cards:
deck.push_back(card)
# We want a lot of commit and checkout cards!
for i in range(5):
deck.push_back(cards[0])
deck.push_back(cards[1])
var new_card = preload("res://card.tscn").instance() var new_card = preload("res://card.tscn").instance()
var card = cards[randi() % cards.size()] var card = deck[randi() % deck.size()]
new_card.command = card.command new_card.command = card.command
new_card.arg_number = card.arg_number new_card.arg_number = card.arg_number
new_card.description = card.description new_card.description = card.description
@ -137,6 +152,7 @@ func arrange_cards():
tween.start() tween.start()
func redraw_all_cards(): func redraw_all_cards():
game.energy = 5
for card in get_tree().get_nodes_in_group("cards"): for card in get_tree().get_nodes_in_group("cards"):
card.queue_free() card.queue_free()
for i in range(7): for i in range(7):

View file

@ -1,10 +1,11 @@
[gd_scene load_steps=6 format=2] [gd_scene load_steps=7 format=2]
[ext_resource path="res://fonts/default.tres" type="DynamicFont" id=1] [ext_resource path="res://fonts/default.tres" type="DynamicFont" id=1]
[ext_resource path="res://drop_area.tscn" type="PackedScene" id=2] [ext_resource path="res://drop_area.tscn" type="PackedScene" id=2]
[ext_resource path="res://repository.tscn" type="PackedScene" id=3] [ext_resource path="res://repository.tscn" type="PackedScene" id=3]
[ext_resource path="res://cardgame.gd" type="Script" id=4] [ext_resource path="res://cardgame.gd" type="Script" id=4]
[ext_resource path="res://terminal.tscn" type="PackedScene" id=5] [ext_resource path="res://terminal.tscn" type="PackedScene" id=5]
[ext_resource path="res://fonts/big.tres" type="DynamicFont" id=6]
[node name="Cardgame" type="Node2D"] [node name="Cardgame" type="Node2D"]
script = ExtResource( 4 ) script = ExtResource( 4 )
@ -49,5 +50,18 @@ text = "Draw new cards"
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="Energy" type="Label" parent="."]
modulate = Color( 0.431373, 0.792157, 0.423529, 1 )
margin_left = 35.3364
margin_top = 796.429
margin_right = 75.3364
margin_bottom = 845.429
rect_scale = Vector2( 2, 2 )
custom_fonts/font = ExtResource( 6 )
text = "3"
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="command_done" from="Terminal" to="." method="_update_repo"] [connection signal="command_done" from="Terminal" to="." method="_update_repo"]
[connection signal="pressed" from="Button" to="." method="redraw_all_cards"] [connection signal="pressed" from="Button" to="." method="redraw_all_cards"]

View file

@ -1,6 +1,7 @@
[gd_scene load_steps=3 format=2] [gd_scene load_steps=4 format=2]
[ext_resource path="res://fonts/default.tres" type="DynamicFont" id=1] [ext_resource path="res://fonts/default.tres" type="DynamicFont" id=1]
[ext_resource path="res://fonts/big.tres" type="DynamicFont" id=2]
[ext_resource path="res://cardgame.gd" type="Script" id=3] [ext_resource path="res://cardgame.gd" type="Script" id=3]
[node name="Cards" type="Control"] [node name="Cards" type="Control"]
@ -24,4 +25,17 @@ text = "Draw new cards"
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="Energy" type="Label" parent="."]
modulate = Color( 0.431373, 0.792157, 0.423529, 1 )
margin_left = 28.2219
margin_top = 16.6766
margin_right = 68.2219
margin_bottom = 65.6766
rect_scale = Vector2( 2, 2 )
custom_fonts/font = ExtResource( 2 )
text = "3"
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="pressed" from="Button" to="." method="redraw_all_cards"] [connection signal="pressed" from="Button" to="." method="redraw_all_cards"]