Added advancing time
parent
7492d96cee
commit
56c993e856
|
|
@ -0,0 +1,10 @@
|
||||||
|
extends Sprite2D
|
||||||
|
|
||||||
|
@export var mover: Mover
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
mover.started_moving.connect(_on_mover_started_moving)
|
||||||
|
|
||||||
|
func _on_mover_started_moving(_from: Vector2i, dir: Vector2i):
|
||||||
|
if dir.x != 0:
|
||||||
|
flip_h = dir.x < 0
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
uid://swwas6oe75sc
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
[gd_scene load_steps=5 format=3 uid="uid://drs6h7ks4r2ta"]
|
[gd_scene load_steps=6 format=3 uid="uid://drs6h7ks4r2ta"]
|
||||||
|
|
||||||
[ext_resource type="Texture2D" uid="uid://doscvutq8uqmd" path="res://sprites/sheet.png" id="1_72ieh"]
|
[ext_resource type="Texture2D" uid="uid://doscvutq8uqmd" path="res://sprites/sheet.png" id="1_72ieh"]
|
||||||
[ext_resource type="Script" uid="uid://cvviym6gdlod8" path="res://prefabs/player/player.gd" id="1_wv1mm"]
|
[ext_resource type="Script" uid="uid://cvviym6gdlod8" path="res://prefabs/player/player.gd" id="1_wv1mm"]
|
||||||
[ext_resource type="Script" uid="uid://sxo578w2yds2" path="res://prefabs/player/player_input.gd" id="2_rdx4y"]
|
[ext_resource type="Script" uid="uid://sxo578w2yds2" path="res://prefabs/player/player_input.gd" id="2_rdx4y"]
|
||||||
|
[ext_resource type="Script" uid="uid://swwas6oe75sc" path="res://nodes/mover_sprite_flipper.gd" id="3_klv5p"]
|
||||||
[ext_resource type="Inventory" uid="uid://dm71wjetr4e52" path="res://prefabs/player/player_inventory.tres" id="4_binfn"]
|
[ext_resource type="Inventory" uid="uid://dm71wjetr4e52" path="res://prefabs/player/player_inventory.tres" id="4_binfn"]
|
||||||
|
|
||||||
[node name="Player" type="GridPosition" node_paths=PackedStringArray("gatherer", "entity_inventory")]
|
[node name="Player" type="GridPosition" node_paths=PackedStringArray("gatherer", "entity_inventory")]
|
||||||
|
|
@ -10,11 +11,13 @@ script = ExtResource("1_wv1mm")
|
||||||
gatherer = NodePath("Gatherer")
|
gatherer = NodePath("Gatherer")
|
||||||
entity_inventory = NodePath("EntityInventory")
|
entity_inventory = NodePath("EntityInventory")
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
[node name="Sprite2D" type="Sprite2D" parent="." node_paths=PackedStringArray("mover")]
|
||||||
texture = ExtResource("1_72ieh")
|
texture = ExtResource("1_72ieh")
|
||||||
hframes = 8
|
hframes = 8
|
||||||
vframes = 8
|
vframes = 8
|
||||||
frame = 1
|
frame = 1
|
||||||
|
script = ExtResource("3_klv5p")
|
||||||
|
mover = NodePath("../Mover")
|
||||||
|
|
||||||
[node name="Camera2D" type="Camera2D" parent="."]
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
zoom = Vector2(2, 2)
|
zoom = Vector2(2, 2)
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,28 @@ extends Node
|
||||||
@export var player: Player
|
@export var player: Player
|
||||||
|
|
||||||
@onready var inventory_ui: InventoryUI = %Inventory
|
@onready var inventory_ui: InventoryUI = %Inventory
|
||||||
|
@onready var clock_hand: TextureRect = %Hand
|
||||||
|
|
||||||
|
var manager: GameManager
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
manager = GameManager.from_node(self)
|
||||||
|
manager.time().time_advanced.connect(_on_time_advance)
|
||||||
player.entity_inventory.inventory.changed.connect(_on_player_inventory_changed)
|
player.entity_inventory.inventory.changed.connect(_on_player_inventory_changed)
|
||||||
update_inventory_ui()
|
update_inventory_ui()
|
||||||
|
update_clock_hand(manager.time().day_progress())
|
||||||
|
|
||||||
func _on_player_inventory_changed():
|
func _on_player_inventory_changed():
|
||||||
update_inventory_ui()
|
update_inventory_ui()
|
||||||
|
|
||||||
func update_inventory_ui():
|
func update_inventory_ui():
|
||||||
inventory_ui.update(player.get_inventory())
|
inventory_ui.update(player.get_inventory())
|
||||||
|
|
||||||
|
func _on_time_advance(_now: int, _advanced_by: int):
|
||||||
|
update_clock_hand(manager.time().day_progress())
|
||||||
|
|
||||||
|
func update_clock_hand(progress: float):
|
||||||
|
clock_hand.rotation = progress * PI * 2.0
|
||||||
|
|
||||||
|
func on_day_end():
|
||||||
|
print("Day over!")
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,14 @@
|
||||||
[gd_scene load_steps=5 format=3 uid="uid://blutrglw7mycx"]
|
[gd_scene load_steps=8 format=3 uid="uid://blutrglw7mycx"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://djccw7ahn8b47" path="res://prefabs/ui/inventory_ui.gd" id="1_4ieor"]
|
[ext_resource type="Script" uid="uid://djccw7ahn8b47" path="res://prefabs/ui/inventory_ui.gd" id="1_4ieor"]
|
||||||
[ext_resource type="Script" uid="uid://ckalp7icn1f28" path="res://prefabs/ui/ui.gd" id="1_htiv7"]
|
[ext_resource type="Script" uid="uid://ckalp7icn1f28" path="res://prefabs/ui/ui.gd" id="1_htiv7"]
|
||||||
[ext_resource type="Texture2D" uid="uid://4rxwcyoye2sa" path="res://sprites/blueberry_item.png" id="2_htiv7"]
|
[ext_resource type="Texture2D" uid="uid://4rxwcyoye2sa" path="res://sprites/blueberry_item.png" id="2_htiv7"]
|
||||||
[ext_resource type="Texture2D" uid="uid://d11rkcho3c38n" path="res://sprites/cowberry_item.png" id="3_gxjsb"]
|
[ext_resource type="Texture2D" uid="uid://d11rkcho3c38n" path="res://sprites/cowberry_item.png" id="3_gxjsb"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://1wsheq2hjkip" path="res://sprites/clock_base.png" id="5_mbf2n"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://ct5u214yridak" path="res://sprites/clock_hand.png" id="6_lntee"]
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_mbf2n"]
|
||||||
|
bg_color = Color(0.192157, 0.121569, 0.0313726, 0.231373)
|
||||||
|
|
||||||
[node name="UI" type="Control"]
|
[node name="UI" type="Control"]
|
||||||
layout_mode = 3
|
layout_mode = 3
|
||||||
|
|
@ -15,9 +20,11 @@ grow_vertical = 2
|
||||||
script = ExtResource("1_htiv7")
|
script = ExtResource("1_htiv7")
|
||||||
|
|
||||||
[node name="PanelContainer" type="PanelContainer" parent="."]
|
[node name="PanelContainer" type="PanelContainer" parent="."]
|
||||||
layout_mode = 0
|
layout_mode = 1
|
||||||
offset_right = 40.0
|
offset_right = 46.0
|
||||||
offset_bottom = 40.0
|
offset_bottom = 68.0
|
||||||
|
scale = Vector2(2, 2)
|
||||||
|
theme_override_styles/panel = SubResource("StyleBoxFlat_mbf2n")
|
||||||
|
|
||||||
[node name="Inventory" type="VBoxContainer" parent="PanelContainer"]
|
[node name="Inventory" type="VBoxContainer" parent="PanelContainer"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
|
|
@ -45,3 +52,30 @@ texture = ExtResource("3_gxjsb")
|
||||||
[node name="Count" type="Label" parent="PanelContainer/Inventory/Cowberry"]
|
[node name="Count" type="Label" parent="PanelContainer/Inventory/Cowberry"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "0"
|
text = "0"
|
||||||
|
|
||||||
|
[node name="Time" type="Control" parent="."]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 1
|
||||||
|
anchor_left = 1.0
|
||||||
|
anchor_right = 1.0
|
||||||
|
offset_left = -80.0
|
||||||
|
offset_top = 16.0
|
||||||
|
offset_right = -16.0
|
||||||
|
offset_bottom = 80.0
|
||||||
|
grow_horizontal = 0
|
||||||
|
scale = Vector2(2, 2)
|
||||||
|
pivot_offset = Vector2(64, 0)
|
||||||
|
|
||||||
|
[node name="Base" type="TextureRect" parent="Time"]
|
||||||
|
layout_mode = 2
|
||||||
|
offset_right = 64.0
|
||||||
|
offset_bottom = 64.0
|
||||||
|
texture = ExtResource("5_mbf2n")
|
||||||
|
|
||||||
|
[node name="Hand" type="TextureRect" parent="Time"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
layout_mode = 2
|
||||||
|
offset_right = 64.0
|
||||||
|
offset_bottom = 64.0
|
||||||
|
pivot_offset = Vector2(32, 32)
|
||||||
|
texture = ExtResource("6_lntee")
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 797 B |
|
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://1wsheq2hjkip"
|
||||||
|
path="res://.godot/imported/clock_base.png-a0dc432930e17741ad47c2b60b16358b.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://sprites/clock_base.png"
|
||||||
|
dest_files=["res://.godot/imported/clock_base.png-a0dc432930e17741ad47c2b60b16358b.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 165 B |
|
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://ct5u214yridak"
|
||||||
|
path="res://.godot/imported/clock_hand.png-467d156ceb932e32aade89754e696be7.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://sprites/clock_hand.png"
|
||||||
|
dest_files=["res://.godot/imported/clock_hand.png-467d156ceb932e32aade89754e696be7.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 4.0 KiB |
|
|
@ -1,4 +1,8 @@
|
||||||
use godot::{classes::*, prelude::*};
|
use godot::{
|
||||||
|
classes::*,
|
||||||
|
obj::{WithBaseField, WithUserSignals},
|
||||||
|
prelude::*,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
|
@ -45,6 +49,11 @@ impl GameManager {
|
||||||
#[derive(Debug, GodotClass)]
|
#[derive(Debug, GodotClass)]
|
||||||
#[class(init, base=Node)]
|
#[class(init, base=Node)]
|
||||||
pub struct TimeManager {
|
pub struct TimeManager {
|
||||||
|
#[export]
|
||||||
|
#[init(val = 40)]
|
||||||
|
day_length: i32,
|
||||||
|
|
||||||
|
#[var(get)]
|
||||||
time_of_day: i32,
|
time_of_day: i32,
|
||||||
|
|
||||||
base: Base<Node>,
|
base: Base<Node>,
|
||||||
|
|
@ -58,10 +67,32 @@ impl TimeManager {
|
||||||
#[func]
|
#[func]
|
||||||
pub fn reset_time(&mut self) {
|
pub fn reset_time(&mut self) {
|
||||||
self.time_of_day = 0;
|
self.time_of_day = 0;
|
||||||
|
self.signals().time_resetted().emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[func]
|
#[func]
|
||||||
pub fn advance_time(&mut self, amount: i32) {
|
pub fn advance_time(&mut self, amount: i32) {
|
||||||
self.time_of_day += amount;
|
let new_time = self.time_of_day + amount;
|
||||||
|
self.time_of_day = new_time;
|
||||||
|
self.signals().time_advanced().emit(new_time, amount);
|
||||||
|
if self.time_of_day >= self.day_length {
|
||||||
|
GameManager::get(self.to_gd()).propagate_call(calls::ON_DAY_END);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[func]
|
||||||
|
pub fn day_progress(&self) -> f32 {
|
||||||
|
self.time_of_day as f32 / self.day_length as f32
|
||||||
|
}
|
||||||
|
|
||||||
|
#[func]
|
||||||
|
fn on_round_end(&mut self) {
|
||||||
|
self.advance_time(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[signal]
|
||||||
|
fn time_resetted();
|
||||||
|
|
||||||
|
#[signal]
|
||||||
|
fn time_advanced(now: i32, advanced_by: i32);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ impl GridPosition {
|
||||||
#[class(init, base=Node)]
|
#[class(init, base=Node)]
|
||||||
pub struct Mover {
|
pub struct Mover {
|
||||||
#[export]
|
#[export]
|
||||||
#[init(val = 30.0)]
|
#[init(val = 15.0)]
|
||||||
movement_speed: f32,
|
movement_speed: f32,
|
||||||
|
|
||||||
#[export_group(name = "Flags")]
|
#[export_group(name = "Flags")]
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ impl TurnManager {
|
||||||
self.current_actor = None;
|
self.current_actor = None;
|
||||||
self.round_queue = self.new_round();
|
self.round_queue = self.new_round();
|
||||||
if !self.round_queue.is_empty() {
|
if !self.round_queue.is_empty() {
|
||||||
GameManager::get(self.to_gd()).propagate_call("on_round_start");
|
GameManager::get(self.to_gd()).propagate_call(calls::ON_ROUND_START);
|
||||||
self.start_next_turn();
|
self.start_next_turn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -77,12 +77,14 @@ impl TurnManager {
|
||||||
self.unregister(&actor);
|
self.unregister(&actor);
|
||||||
self.start_next_turn();
|
self.start_next_turn();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
GameManager::get(self.to_gd()).propagate_call(calls::ON_ROUND_END);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_actor_turn_end(&mut self, action: GString) {
|
fn on_actor_turn_end(&mut self, action: GString) {
|
||||||
GameManager::get(self.to_gd())
|
GameManager::get(self.to_gd())
|
||||||
.propagate_call_ex("on_turn_end")
|
.propagate_call_ex(calls::ON_TURN_END)
|
||||||
.args(&varray![self.current_actor, action])
|
.args(&varray![self.current_actor, action])
|
||||||
.done();
|
.done();
|
||||||
self.start_next_turn();
|
self.start_next_turn();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,12 @@
|
||||||
use godot::prelude::*;
|
use godot::prelude::*;
|
||||||
|
|
||||||
|
pub mod calls {
|
||||||
|
pub const ON_ROUND_START: &str = "on_round_start";
|
||||||
|
pub const ON_ROUND_END: &str = "on_round_end";
|
||||||
|
pub const ON_TURN_END: &str = "on_turn_end";
|
||||||
|
pub const ON_DAY_END: &str = "on_day_end";
|
||||||
|
}
|
||||||
|
|
||||||
pub fn find_in_parents<T, U>(from: Gd<U>) -> Option<Gd<T>>
|
pub fn find_in_parents<T, U>(from: Gd<U>) -> Option<Gd<T>>
|
||||||
where
|
where
|
||||||
T: Inherits<Node>,
|
T: Inherits<Node>,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue