2020-10-13 13:04:12 +02:00
|
|
|
extends Node2D
|
|
|
|
|
2020-10-13 14:16:36 +02:00
|
|
|
var hovered = false
|
2020-10-13 13:04:12 +02:00
|
|
|
var dragged = false
|
|
|
|
var drag_offset
|
2020-10-14 00:27:37 +02:00
|
|
|
|
2020-10-27 13:14:07 +01:00
|
|
|
export var id = "" setget set_id
|
2020-10-13 17:08:37 +02:00
|
|
|
export var command = "" setget set_command
|
2020-10-14 00:27:37 +02:00
|
|
|
export var description = "" setget set_description
|
2020-10-15 15:22:38 +02:00
|
|
|
export var energy = 0 setget set_energy
|
2020-10-14 00:27:37 +02:00
|
|
|
|
2020-10-13 17:08:37 +02:00
|
|
|
var _first_argument = null
|
|
|
|
var _home_position = null
|
2020-10-15 15:02:43 +02:00
|
|
|
var _home_rotation = null
|
2020-10-13 17:08:37 +02:00
|
|
|
|
2020-10-15 15:22:38 +02:00
|
|
|
onready var energy_label = $Sprite/Energy
|
|
|
|
|
2020-10-13 13:04:12 +02:00
|
|
|
func _ready():
|
|
|
|
set_process_unhandled_input(true)
|
2020-10-15 15:22:38 +02:00
|
|
|
set_energy(energy)
|
2020-10-13 13:04:12 +02:00
|
|
|
|
|
|
|
func _process(delta):
|
2020-10-15 15:22:38 +02:00
|
|
|
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)
|
|
|
|
|
2020-10-13 13:04:12 +02:00
|
|
|
if dragged:
|
|
|
|
var mousepos = get_viewport().get_mouse_position()
|
2020-10-14 14:48:38 +02:00
|
|
|
global_position = mousepos - drag_offset
|
2020-10-15 15:02:43 +02:00
|
|
|
|
|
|
|
var target_scale = 1
|
|
|
|
|
|
|
|
if hovered and not dragged:
|
|
|
|
target_scale = 1.5
|
|
|
|
|
|
|
|
scale = lerp(scale, Vector2(target_scale, target_scale), 10*delta)
|
2020-10-13 13:04:12 +02:00
|
|
|
|
|
|
|
func _unhandled_input(event):
|
|
|
|
if event is InputEventMouseButton:
|
2020-10-13 14:16:36 +02:00
|
|
|
if event.button_index == BUTTON_LEFT and event.pressed and hovered:
|
2020-10-13 13:04:12 +02:00
|
|
|
dragged = true
|
2020-10-13 14:16:36 +02:00
|
|
|
game.dragged_object = self
|
2020-11-03 12:39:40 +01:00
|
|
|
_turn_on_highlights()
|
2020-10-22 16:19:22 +02:00
|
|
|
$PickupSound.play()
|
2020-10-13 13:04:12 +02:00
|
|
|
drag_offset = get_viewport().get_mouse_position() - global_position
|
2020-10-13 14:16:36 +02:00
|
|
|
get_tree().set_input_as_handled()
|
|
|
|
modulate.a = 0.5
|
2020-10-13 17:08:37 +02:00
|
|
|
elif event.button_index == BUTTON_LEFT and !event.pressed and dragged:
|
2020-10-13 13:04:12 +02:00
|
|
|
dragged = false
|
2020-10-13 14:16:36 +02:00
|
|
|
game.dragged_object = null
|
2020-11-03 12:39:40 +01:00
|
|
|
_turn_off_highlights()
|
2020-10-13 14:16:36 +02:00
|
|
|
modulate.a = 1
|
2020-10-13 17:29:24 +02:00
|
|
|
|
2020-11-10 22:20:40 +01:00
|
|
|
if "[string]" in command:
|
|
|
|
var dialog = preload("res://scenes/input_dialog.tscn").instance()
|
|
|
|
add_child(dialog)
|
|
|
|
dialog.popup_centered()
|
|
|
|
dialog.connect("entered", self, "entered_string")
|
|
|
|
dialog.connect("popup_hide", self, "move_back")
|
|
|
|
hide()
|
|
|
|
elif "[" in command:
|
2020-10-14 00:04:47 +02:00
|
|
|
move_back()
|
2020-11-03 13:08:07 +01:00
|
|
|
else:
|
|
|
|
try_play(command)
|
|
|
|
|
2020-11-03 12:39:40 +01:00
|
|
|
func _turn_on_highlights():
|
|
|
|
var arg_regex = RegEx.new()
|
|
|
|
arg_regex.compile("\\[(.*)\\]")
|
|
|
|
var m = arg_regex.search(command)
|
|
|
|
if m:
|
|
|
|
var types = Array(m.get_string(1).split(","))
|
|
|
|
for type in types:
|
|
|
|
for area in get_tree().get_nodes_in_group("drop_areas"):
|
|
|
|
area.highlight(type.strip_edges())
|
|
|
|
|
|
|
|
func _turn_off_highlights():
|
|
|
|
for area in get_tree().get_nodes_in_group("drop_areas"):
|
|
|
|
area.highlighted = false
|
|
|
|
|
2020-10-13 14:16:36 +02:00
|
|
|
func _mouse_entered():
|
|
|
|
hovered = true
|
2020-10-15 15:02:43 +02:00
|
|
|
z_index = 1
|
2020-10-13 14:16:36 +02:00
|
|
|
|
|
|
|
func _mouse_exited():
|
|
|
|
hovered = false
|
2020-10-15 15:02:43 +02:00
|
|
|
z_index = 0
|
2020-10-13 17:08:37 +02:00
|
|
|
|
|
|
|
func set_command(new_command):
|
|
|
|
command = new_command
|
2021-02-18 16:47:39 +01:00
|
|
|
var commands = new_command.split("[", true, 1)
|
|
|
|
var args = ''
|
|
|
|
if commands.size() > 1:
|
|
|
|
args = commands[1].replace("]", "")
|
|
|
|
args = args.replace(", ", "/")
|
|
|
|
args = args.replace("ref", " [img=20]images/ref.svg[/img] ")
|
|
|
|
args = args.replace("commit", " [img=20]images/commit.svg[/img] ")
|
|
|
|
args = args.replace("string", " [img=20]images/string.svg[/img] ")
|
|
|
|
args = args.replace("head", " [img=20]images/head.svg[/img] ")
|
|
|
|
args = args.replace("file", " [img=20]images/file.svg[/img] ")
|
|
|
|
args = args.replace("remote", " [img=20]images/remote.svg[/img] ")
|
|
|
|
$Label.bbcode_text = commands[0] + args
|
|
|
|
#$Label.text = command
|
2020-10-14 00:27:37 +02:00
|
|
|
|
|
|
|
func set_description(new_description):
|
|
|
|
description = new_description
|
|
|
|
$Description.text = description
|
2020-10-13 17:08:37 +02:00
|
|
|
|
2020-10-15 15:22:38 +02:00
|
|
|
func set_energy(new_energy):
|
|
|
|
energy = new_energy
|
|
|
|
if energy_label:
|
|
|
|
energy_label.text = str(energy)
|
2020-10-27 13:14:07 +01:00
|
|
|
|
|
|
|
func set_id(new_id):
|
|
|
|
id = new_id
|
2020-11-10 22:37:10 +01:00
|
|
|
var art_path = "res://cards/%s.svg" % new_id
|
2023-05-16 13:59:21 +02:00
|
|
|
#var file = File.new()
|
2021-01-18 14:14:08 +01:00
|
|
|
#if file.file_exists(art_path):
|
|
|
|
var texture = load(art_path)
|
|
|
|
if texture:
|
|
|
|
$Image.texture = texture
|
2021-02-18 18:06:17 +01:00
|
|
|
$Panel/Glow.visible = not id in game.state["played_cards"]
|
2020-10-15 15:22:38 +02:00
|
|
|
|
2020-10-13 17:08:37 +02:00
|
|
|
func move_back():
|
|
|
|
position = _home_position
|
2020-10-15 15:02:43 +02:00
|
|
|
rotation_degrees = _home_rotation
|
2020-10-22 16:19:22 +02:00
|
|
|
$ReturnSound.play()
|
2020-11-10 22:20:40 +01:00
|
|
|
show()
|
2020-10-13 14:16:36 +02:00
|
|
|
|
|
|
|
func dropped_on(other):
|
2020-11-03 13:08:07 +01:00
|
|
|
if "[" in command:
|
2020-11-07 13:59:47 +01:00
|
|
|
var argument
|
2021-01-07 17:35:08 +01:00
|
|
|
if other.type == "file" or other.type == "remote":
|
2020-11-07 13:59:47 +01:00
|
|
|
argument = other.label
|
|
|
|
else:
|
|
|
|
argument = other.id
|
|
|
|
|
2020-11-13 12:27:15 +01:00
|
|
|
if (command.begins_with("git checkout") or command.begins_with("git rebase") or command.begins_with("git branch -D")) and argument.begins_with("refs/heads"):
|
2020-11-07 13:59:47 +01:00
|
|
|
argument = Array(argument.split("/")).pop_back()
|
2020-11-03 13:08:07 +01:00
|
|
|
|
|
|
|
var arg_regex = RegEx.new()
|
|
|
|
arg_regex.compile("\\[(.*)\\]")
|
|
|
|
var full_command = arg_regex.sub(command, argument)
|
|
|
|
try_play(full_command)
|
2020-10-15 15:53:23 +02:00
|
|
|
|
2020-10-26 19:56:52 +01:00
|
|
|
func try_play(full_command):
|
2020-10-15 15:53:23 +02:00
|
|
|
if game.energy >= energy:
|
2020-10-29 15:55:10 +01:00
|
|
|
var terminal = $"../../../..".terminal
|
|
|
|
terminal.send_command(full_command)
|
|
|
|
#yield(terminal, "command_done")
|
2021-01-21 15:08:59 +01:00
|
|
|
game.used_cards = true
|
2020-10-22 16:19:22 +02:00
|
|
|
$PlaySound.play()
|
2020-10-26 19:15:47 +01:00
|
|
|
var particles = preload("res://scenes/card_particles.tscn").instance()
|
2020-10-22 16:19:22 +02:00
|
|
|
particles.position = position
|
|
|
|
get_parent().add_child(particles)
|
2020-11-03 12:39:40 +01:00
|
|
|
move_back()
|
2020-10-15 15:53:23 +02:00
|
|
|
game.energy -= energy
|
2021-02-18 18:06:17 +01:00
|
|
|
if not id in game.state["played_cards"]:
|
|
|
|
game.state["played_cards"].push_back(id)
|
|
|
|
game.save_state()
|
|
|
|
$Panel/Glow.hide()
|
2020-10-15 15:53:23 +02:00
|
|
|
else:
|
|
|
|
move_back()
|
2020-11-10 22:20:40 +01:00
|
|
|
|
|
|
|
func entered_string(string):
|
|
|
|
try_play(command.replace("[string]", "'"+string+"'"))
|