mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-24 16:20:08 +01:00
Simple card game prototype in the Cardgame scene
This commit is contained in:
parent
72d9ec692b
commit
36759f2909
10 changed files with 154 additions and 30 deletions
23
card.gd
23
card.gd
|
@ -1,5 +1,6 @@
|
|||
extends Node2D
|
||||
|
||||
var hovered = false
|
||||
var dragged = false
|
||||
var drag_offset
|
||||
|
||||
|
@ -12,10 +13,28 @@ func _process(delta):
|
|||
position = mousepos - drag_offset
|
||||
|
||||
func _unhandled_input(event):
|
||||
print("input event!")
|
||||
if event is InputEventMouseButton:
|
||||
if event.button_index == BUTTON_LEFT and event.pressed:
|
||||
if event.button_index == BUTTON_LEFT and event.pressed and hovered:
|
||||
dragged = true
|
||||
game.dragged_object = self
|
||||
drag_offset = get_viewport().get_mouse_position() - global_position
|
||||
get_tree().set_input_as_handled()
|
||||
modulate.a = 0.5
|
||||
elif event.button_index == BUTTON_LEFT and !event.pressed:
|
||||
dragged = false
|
||||
game.dragged_object = null
|
||||
modulate.a = 1
|
||||
|
||||
|
||||
func _mouse_entered():
|
||||
hovered = true
|
||||
|
||||
func _mouse_exited():
|
||||
hovered = false
|
||||
|
||||
func dropped_on(other):
|
||||
#print("I have been dropped on "+str(other.id))
|
||||
print("Running " + $Label.text + " " + other.id)
|
||||
var command = $Label.text + " " + other.id
|
||||
$"../Terminal".send_command(command)
|
||||
queue_free()
|
||||
|
|
41
card.tscn
41
card.tscn
|
@ -1,6 +1,7 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://card.gd" type="Script" id=1]
|
||||
[ext_resource path="res://fonts/default.tres" type="DynamicFont" id=2]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=1]
|
||||
extents = Vector2( 105.74, 143.46 )
|
||||
|
@ -8,20 +9,34 @@ extents = Vector2( 105.74, 143.46 )
|
|||
[node name="Card" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="KinematicBody2D" type="KinematicBody2D" parent="."]
|
||||
position = Vector2( 536.216, 510.56 )
|
||||
input_pickable = true
|
||||
|
||||
[node name="Panel" type="Panel" parent="KinematicBody2D"]
|
||||
visible = false
|
||||
margin_left = -104.0
|
||||
margin_top = -143.0
|
||||
margin_right = 106.0
|
||||
margin_bottom = 141.0
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
margin_left = -103.0
|
||||
margin_top = -145.0
|
||||
margin_right = 103.0
|
||||
margin_bottom = 144.0
|
||||
mouse_filter = 2
|
||||
color = Color( 0.105882, 0.67451, 0.847059, 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="KinematicBody2D"]
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
position = Vector2( 0, 6.10352e-05 )
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
position = Vector2( -6.10352e-05, 0.00012207 )
|
||||
shape = SubResource( 1 )
|
||||
[connection signal="input_event" from="KinematicBody2D" to="." method="_input_event"]
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
margin_left = -89.1555
|
||||
margin_top = -131.488
|
||||
margin_right = -38.1555
|
||||
margin_bottom = -117.488
|
||||
custom_fonts/font = ExtResource( 2 )
|
||||
custom_colors/font_color = Color( 0, 0, 0, 1 )
|
||||
text = "git checkout"
|
||||
__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"]
|
||||
|
|
19
cardgame.gd
Normal file
19
cardgame.gd
Normal file
|
@ -0,0 +1,19 @@
|
|||
extends Node2D
|
||||
|
||||
func _ready():
|
||||
|
||||
var path = game.tmp_prefix_inside+"/repos/sandbox/"
|
||||
helpers.careful_delete(path)
|
||||
|
||||
game.global_shell.run("mkdir " + path)
|
||||
game.global_shell.cd(path)
|
||||
game.global_shell.run("git init")
|
||||
game.global_shell.run("git symbolic-ref HEAD refs/heads/main")
|
||||
game.global_shell.run("git commit --allow-empty -m 'Initial commit'")
|
||||
|
||||
$Repository.path = path
|
||||
|
||||
$Terminal.repository = $Repository
|
||||
|
||||
func _update_repo():
|
||||
$Repository.update_everything()
|
|
@ -1,13 +1,32 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
[gd_scene load_steps=6 format=2]
|
||||
|
||||
[ext_resource path="res://card.tscn" type="PackedScene" id=1]
|
||||
[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://cardgame.gd" type="Script" id=4]
|
||||
[ext_resource path="res://terminal.tscn" type="PackedScene" id=5]
|
||||
|
||||
[node name="Cardgame" type="Node2D"]
|
||||
script = ExtResource( 4 )
|
||||
|
||||
[node name="Card" parent="." instance=ExtResource( 1 )]
|
||||
[node name="Repository" parent="." instance=ExtResource( 3 )]
|
||||
margin_right = 1481.0
|
||||
margin_bottom = 592.0
|
||||
|
||||
[node name="DropArea" parent="." instance=ExtResource( 2 )]
|
||||
|
||||
[node name="Card2" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 118.019, -91.0798 )
|
||||
position = Vector2( 948.833, 814.382 )
|
||||
|
||||
[node name="Card3" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 474.641, 118.019 )
|
||||
position = Vector2( 1348, 830.017 )
|
||||
|
||||
[node name="Card" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 558.857, 824.539 )
|
||||
|
||||
[node name="Terminal" parent="." instance=ExtResource( 5 )]
|
||||
margin_left = 1488.0
|
||||
margin_top = 5.0
|
||||
margin_right = 1914.0
|
||||
margin_bottom = 586.0
|
||||
[connection signal="command_done" from="Terminal" to="." method="_update_repo"]
|
||||
|
|
19
drop_area.gd
Normal file
19
drop_area.gd
Normal file
|
@ -0,0 +1,19 @@
|
|||
extends Node2D
|
||||
|
||||
var hovered = false
|
||||
|
||||
func _ready():
|
||||
pass
|
||||
|
||||
func _mouse_entered():
|
||||
hovered = true
|
||||
|
||||
func _mouse_exited():
|
||||
hovered = false
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventMouseButton:
|
||||
if event.button_index == BUTTON_LEFT and !event.pressed and hovered:
|
||||
if game.dragged_object:
|
||||
print(game.dragged_object)
|
||||
game.dragged_object.dropped_on($"..")
|
17
drop_area.tscn
Normal file
17
drop_area.tscn
Normal file
|
@ -0,0 +1,17 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://drop_area.gd" type="Script" id=1]
|
||||
|
||||
[sub_resource type="CircleShape2D" id=1]
|
||||
radius = 23.5871
|
||||
|
||||
[node name="DropArea" type="Node2D"]
|
||||
position = Vector2( -0.197731, 0.0673599 )
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
shape = SubResource( 1 )
|
||||
[connection signal="mouse_entered" from="Area2D" to="." method="_mouse_entered"]
|
||||
[connection signal="mouse_exited" from="Area2D" to="." method="_mouse_exited"]
|
2
game.gd
2
game.gd
|
@ -5,6 +5,8 @@ var tmp_prefix_inside = _tmp_prefix_inside()
|
|||
var global_shell
|
||||
var fake_editor
|
||||
|
||||
var dragged_object
|
||||
|
||||
var _file = "user://savegame.json"
|
||||
var state = {}
|
||||
|
||||
|
|
18
node.tscn
18
node.tscn
|
@ -1,9 +1,10 @@
|
|||
[gd_scene load_steps=6 format=2]
|
||||
[gd_scene load_steps=8 format=2]
|
||||
|
||||
[ext_resource path="res://node.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]
|
||||
[ext_resource path="res://nodes/pop.wav" type="AudioStream" id=4]
|
||||
[ext_resource path="res://drop_area.tscn" type="PackedScene" id=5]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id=1]
|
||||
content_margin_left = 5.0
|
||||
|
@ -16,17 +17,21 @@ corner_radius_top_right = 5
|
|||
corner_radius_bottom_right = 5
|
||||
corner_radius_bottom_left = 5
|
||||
|
||||
[sub_resource type="CircleShape2D" id=2]
|
||||
radius = 23.6295
|
||||
|
||||
[node name="Node" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Arrows" type="Node2D" parent="."]
|
||||
|
||||
[node name="Rect" type="ColorRect" parent="."]
|
||||
visible = false
|
||||
margin_left = -29.0
|
||||
margin_top = -28.0
|
||||
margin_right = 29.0
|
||||
margin_bottom = 29.0
|
||||
mouse_filter = 1
|
||||
mouse_filter = 2
|
||||
color = Color( 1, 1, 1, 0 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
|
@ -64,5 +69,14 @@ custom_colors/font_color = Color( 1, 1, 1, 1 )
|
|||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="DropArea" parent="." instance=ExtResource( 5 )]
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
shape = SubResource( 2 )
|
||||
[connection signal="mouse_entered" from="Rect" to="." method="_on_hover"]
|
||||
[connection signal="mouse_exited" from="Rect" to="." method="_on_unhover"]
|
||||
[connection signal="mouse_entered" from="Area2D" to="." method="_on_hover"]
|
||||
[connection signal="mouse_exited" from="Area2D" to="." method="_on_unhover"]
|
||||
|
|
|
@ -40,12 +40,12 @@ func _process(_delta):
|
|||
if path:
|
||||
apply_forces()
|
||||
|
||||
func _input(event):
|
||||
if mouse_inside:
|
||||
if event.is_action_pressed("zoom_out") and nodes.rect_scale.x > 0.3:
|
||||
nodes.rect_scale -= Vector2(0.05, 0.05)
|
||||
if event.is_action_pressed("zoom_in") and nodes.rect_scale.x < 2:
|
||||
nodes.rect_scale += Vector2(0.05, 0.05)
|
||||
#func _input(event):
|
||||
# if mouse_inside:
|
||||
# if event.is_action_pressed("zoom_out") and nodes.rect_scale.x > 0.3:
|
||||
# nodes.rect_scale -= Vector2(0.05, 0.05)
|
||||
# if event.is_action_pressed("zoom_in") and nodes.rect_scale.x < 2:
|
||||
# nodes.rect_scale += Vector2(0.05, 0.05)
|
||||
|
||||
func there_is_a_git():
|
||||
return shell.run("test -d .git && echo yes || echo no") == "yes\n"
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
[node name="Repository" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
mouse_filter = 1
|
||||
mouse_filter = 2
|
||||
theme = ExtResource( 2 )
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
|
@ -18,7 +18,7 @@ __meta__ = {
|
|||
[node name="Rows" type="VSplitContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
mouse_filter = 1
|
||||
mouse_filter = 2
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ __meta__ = {
|
|||
[node name="RepoVis" type="Control" parent="Rows"]
|
||||
margin_right = 1920.0
|
||||
margin_bottom = 925.0
|
||||
mouse_filter = 1
|
||||
mouse_filter = 2
|
||||
size_flags_vertical = 3
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
|
|
Loading…
Reference in a new issue