-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
208 additions
and
42 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,41 @@ | ||
extends Node | ||
|
||
var piece = load("res://Piece.tscn") | ||
const TILE_OFFSET := Vector2(32,32) | ||
|
||
var turnID = 0 | ||
var nTurns = 0 | ||
signal turn_updated | ||
|
||
func _ready(): | ||
load_turn(0) | ||
nTurns = len($FileParser.turns) | ||
|
||
func _input(event: InputEvent) -> void: | ||
if event.is_action_pressed('ui_right'): | ||
self.next_turn() | ||
if event.is_action_pressed("ui_left"): | ||
self.prev_turn() | ||
|
||
func next_turn(): | ||
turnID = clamp(turnID+1, 0, nTurns-1) | ||
load_turn(turnID) | ||
|
||
func prev_turn(): | ||
turnID = clamp(turnID-1, 0, nTurns-1) | ||
load_turn(turnID) | ||
|
||
func load_turn(turn: int): | ||
self.turnID = turn | ||
var currTurn = $FileParser.turns[turn] | ||
for child in $Board.get_children(): # Clear old children | ||
child.queue_free() | ||
for pos in currTurn.positions: | ||
var currPiece = piece.instance() | ||
var loc = $Board.map_to_world(currTurn.positions[pos]) | ||
currPiece.frame = "KQBNRP".find(pos[1]) | ||
currPiece.name = pos | ||
if pos[0] == "B": | ||
currPiece.frame+=6 | ||
currPiece.position = loc | ||
add_child(currPiece) | ||
currPiece.position = loc + TILE_OFFSET | ||
$Board.add_child(currPiece) | ||
emit_signal("turn_updated", self.turnID) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
extends Control | ||
|
||
onready var game = $ViewportContainer/Viewport/MainGame | ||
onready var parser = $ViewportContainer/Viewport/MainGame/FileParser | ||
onready var turnsList = $PanelContainer/VBoxContainer/Turns/VBoxContainer | ||
var lastTurn = 0 | ||
|
||
func _ready() -> void: | ||
$PanelContainer/VBoxContainer/GameDetails.text = parser.path+"\n" | ||
for data in parser.data: | ||
$PanelContainer/VBoxContainer/GameDetails.text += data+" : "+parser.data[data]+"\n" | ||
|
||
var i = 0 | ||
for turn in parser.turns: | ||
var button = Button.new() | ||
button.text = turn.ID | ||
button.name = "Button"+str(i) | ||
button.connect('pressed', self, 'set_turn', [i]) | ||
turnsList.add_child(button) | ||
i += 1 | ||
game.load_turn(0) | ||
|
||
func update_turn(newTurn): | ||
turnsList.get_child(lastTurn).disabled = false | ||
turnsList.get_child(newTurn).disabled = true | ||
self.lastTurn = newTurn | ||
$PanelContainer/VBoxContainer/HBoxContainer/TurnNo.text = str(newTurn) | ||
|
||
func set_turn(turn: int): | ||
self.game.load_turn(turn) | ||
|
||
func _on_prevTurn_button_up() -> void: | ||
self.game.prev_turn() | ||
|
||
func _on_nextTurn_button_up() -> void: | ||
self.game.next_turn() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
[gd_scene load_steps=3 format=2] | ||
|
||
[ext_resource path="res://MainGame.tscn" type="PackedScene" id=1] | ||
[ext_resource path="res://UI.gd" type="Script" id=2] | ||
|
||
[node name="UI" type="Control"] | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
script = ExtResource( 2 ) | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="ViewportContainer" type="ViewportContainer" parent="."] | ||
anchor_bottom = 1.0 | ||
margin_right = 880.0 | ||
stretch = true | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="Viewport" type="Viewport" parent="ViewportContainer"] | ||
size = Vector2( 880, 600 ) | ||
handle_input_locally = false | ||
render_target_update_mode = 3 | ||
|
||
[node name="MainGame" parent="ViewportContainer/Viewport" instance=ExtResource( 1 )] | ||
|
||
[node name="PanelContainer" type="PanelContainer" parent="."] | ||
anchor_left = 1.0 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
margin_left = -143.0 | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer"] | ||
margin_left = 7.0 | ||
margin_top = 7.0 | ||
margin_right = 136.0 | ||
margin_bottom = 593.0 | ||
|
||
[node name="GameDetails" type="Label" parent="PanelContainer/VBoxContainer"] | ||
margin_right = 129.0 | ||
margin_bottom = 14.0 | ||
|
||
[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/VBoxContainer"] | ||
margin_top = 18.0 | ||
margin_right = 129.0 | ||
margin_bottom = 32.0 | ||
|
||
[node name="TurnLabel" type="Label" parent="PanelContainer/VBoxContainer/HBoxContainer"] | ||
margin_right = 36.0 | ||
margin_bottom = 14.0 | ||
text = "Turn: " | ||
|
||
[node name="TurnNo" type="Label" parent="PanelContainer/VBoxContainer/HBoxContainer"] | ||
margin_left = 40.0 | ||
margin_right = 40.0 | ||
margin_bottom = 14.0 | ||
|
||
[node name="Turns" type="ScrollContainer" parent="PanelContainer/VBoxContainer"] | ||
margin_top = 36.0 | ||
margin_right = 129.0 | ||
margin_bottom = 336.0 | ||
rect_min_size = Vector2( 129, 300 ) | ||
scroll_horizontal_enabled = false | ||
|
||
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/VBoxContainer/Turns"] | ||
|
||
[node name="VBoxContainer2" type="HBoxContainer" parent="PanelContainer/VBoxContainer"] | ||
margin_top = 340.0 | ||
margin_right = 129.0 | ||
margin_bottom = 360.0 | ||
alignment = 1 | ||
|
||
[node name="prevTurn" type="Button" parent="PanelContainer/VBoxContainer/VBoxContainer2"] | ||
margin_left = 37.0 | ||
margin_right = 62.0 | ||
margin_bottom = 20.0 | ||
text = "<-" | ||
|
||
[node name="nextTurn" type="Button" parent="PanelContainer/VBoxContainer/VBoxContainer2"] | ||
margin_left = 66.0 | ||
margin_right = 91.0 | ||
margin_bottom = 20.0 | ||
text = "->" | ||
[connection signal="turn_updated" from="ViewportContainer/Viewport/MainGame" to="." method="update_turn"] | ||
[connection signal="button_up" from="PanelContainer/VBoxContainer/VBoxContainer2/prevTurn" to="." method="_on_prevTurn_button_up"] | ||
[connection signal="button_up" from="PanelContainer/VBoxContainer/VBoxContainer2/nextTurn" to="." method="_on_nextTurn_button_up"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters