start work on inventory, items, coins
This commit is contained in:
parent
71b6d2617c
commit
211ef3bbc7
10
data/meat.tres
Normal file
10
data/meat.tres
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[gd_resource type="Resource" script_class="InventoryItem" load_steps=3 format=3 uid="uid://cbbclpp04ptlf"]
|
||||||
|
|
||||||
|
[ext_resource type="Texture2D" uid="uid://cb6qv3c0iojfl" path="res://icon.svg" id="1_2wt7x"]
|
||||||
|
[ext_resource type="Script" path="res://src/lib/inventory_item.gd" id="2_inc63"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("2_inc63")
|
||||||
|
icon = ExtResource("1_2wt7x")
|
||||||
|
name = "Meat"
|
||||||
|
id = &"meat"
|
@ -11,6 +11,7 @@ extends Node3D
|
|||||||
@export var _chat_panel_inactive: Panel
|
@export var _chat_panel_inactive: Panel
|
||||||
@export var _chat_history_inactive: VBoxContainer
|
@export var _chat_history_inactive: VBoxContainer
|
||||||
@export var _chat_history_scroll_inactive: ScrollContainer
|
@export var _chat_history_scroll_inactive: ScrollContainer
|
||||||
|
@export var _coin_label: RichTextLabel
|
||||||
|
|
||||||
## Things to yet play, so to not repeat ourselves much.
|
## Things to yet play, so to not repeat ourselves much.
|
||||||
const PLAYLIST: Array[String] = [
|
const PLAYLIST: Array[String] = [
|
||||||
@ -83,6 +84,11 @@ func _input(event: InputEvent) -> void:
|
|||||||
_deactivate_chat()
|
_deactivate_chat()
|
||||||
|
|
||||||
|
|
||||||
|
func _process(_delta: float) -> void:
|
||||||
|
# this is fine but should this be done in response to a signal instead?
|
||||||
|
_coin_label.text = "COINS: %d" % GameState.fetch().coins
|
||||||
|
|
||||||
|
|
||||||
func _activate_chat() -> void:
|
func _activate_chat() -> void:
|
||||||
_chat_panel.show()
|
_chat_panel.show()
|
||||||
_chat_panel_inactive.hide()
|
_chat_panel_inactive.hide()
|
||||||
|
@ -32,7 +32,7 @@ sky = SubResource("Sky_ygvd3")
|
|||||||
ambient_light_color = Color(0, 0.164706, 0.278431, 1)
|
ambient_light_color = Color(0, 0.164706, 0.278431, 1)
|
||||||
ambient_light_energy = 2.0
|
ambient_light_energy = 2.0
|
||||||
|
|
||||||
[node name="Ingame" type="Node3D" node_paths=PackedStringArray("_soundtrack", "_players", "_chat_panel", "_chat_input", "_chat_history_scroll", "_chat_history", "_chat_panel_inactive", "_chat_history_inactive", "_chat_history_scroll_inactive")]
|
[node name="Ingame" type="Node3D" node_paths=PackedStringArray("_soundtrack", "_players", "_chat_panel", "_chat_input", "_chat_history_scroll", "_chat_history", "_chat_panel_inactive", "_chat_history_inactive", "_chat_history_scroll_inactive", "_coin_label")]
|
||||||
script = ExtResource("1_akuuj")
|
script = ExtResource("1_akuuj")
|
||||||
_player_scene = ExtResource("2_w1gjc")
|
_player_scene = ExtResource("2_w1gjc")
|
||||||
_soundtrack = NodePath("Soundtrack")
|
_soundtrack = NodePath("Soundtrack")
|
||||||
@ -44,6 +44,7 @@ _chat_history = NodePath("UI/ChatPanel/ChatHistoryScroll/ChatHistory")
|
|||||||
_chat_panel_inactive = NodePath("UI/ChatPanelInactive")
|
_chat_panel_inactive = NodePath("UI/ChatPanelInactive")
|
||||||
_chat_history_inactive = NodePath("UI/ChatPanelInactive/ChatHistoryScroll/ChatHistory")
|
_chat_history_inactive = NodePath("UI/ChatPanelInactive/ChatHistoryScroll/ChatHistory")
|
||||||
_chat_history_scroll_inactive = NodePath("UI/ChatPanelInactive/ChatHistoryScroll")
|
_chat_history_scroll_inactive = NodePath("UI/ChatPanelInactive/ChatHistoryScroll")
|
||||||
|
_coin_label = NodePath("UI/CoinLabel")
|
||||||
|
|
||||||
[node name="Soundtrack" type="AudioStreamPlayer" parent="."]
|
[node name="Soundtrack" type="AudioStreamPlayer" parent="."]
|
||||||
bus = &"Music"
|
bus = &"Music"
|
||||||
@ -165,6 +166,15 @@ text = "+5!"
|
|||||||
wait_time = 3.0
|
wait_time = 3.0
|
||||||
one_shot = true
|
one_shot = true
|
||||||
|
|
||||||
|
[node name="CoinLabel" type="RichTextLabel" parent="UI"]
|
||||||
|
clip_contents = false
|
||||||
|
offset_left = 16.0
|
||||||
|
offset_top = 16.0
|
||||||
|
offset_right = 192.0
|
||||||
|
offset_bottom = 40.0
|
||||||
|
theme_override_constants/outline_size = 6
|
||||||
|
text = "Coins: 0"
|
||||||
|
|
||||||
[node name="CSGBox3D" type="CSGBox3D" parent="."]
|
[node name="CSGBox3D" type="CSGBox3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 7.45058e-09, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 7.45058e-09, 0)
|
||||||
collision_mask = 0
|
collision_mask = 0
|
||||||
|
@ -25,7 +25,7 @@ var _interaction_selection: Node3D
|
|||||||
|
|
||||||
var controls_disabled := false
|
var controls_disabled := false
|
||||||
var held_thing: String
|
var held_thing: String
|
||||||
|
|
||||||
|
|
||||||
# What the others see.
|
# What the others see.
|
||||||
func _init_bystander() -> void:
|
func _init_bystander() -> void:
|
||||||
|
@ -80,8 +80,8 @@ func get_picked_up() -> void:
|
|||||||
|
|
||||||
|
|
||||||
func mark_interactive() -> void:
|
func mark_interactive() -> void:
|
||||||
($Model as CSGSphere3D).material_override.next_pass.set("shader_parameter/color", Color.WHITE)
|
(_model as CSGSphere3D).material_override.next_pass.set("shader_parameter/color", Color.WHITE)
|
||||||
|
|
||||||
|
|
||||||
func mark_non_interactive() -> void:
|
func mark_non_interactive() -> void:
|
||||||
($Model as CSGSphere3D).material_override.next_pass.set("shader_parameter/color", Color(1, 1, 1, 0))
|
(_model as CSGSphere3D).material_override.next_pass.set("shader_parameter/color", Color(1, 1, 1, 0))
|
||||||
|
@ -1,7 +1,15 @@
|
|||||||
class_name GameState
|
class_name GameState
|
||||||
extends Resource
|
extends Resource
|
||||||
|
|
||||||
|
const INVENTORY_ITEM_DB = {
|
||||||
|
&"meat": preload("res://data/meat.tres"),
|
||||||
|
}
|
||||||
|
|
||||||
|
# keys are multiplayer ID ints, values are PlayerData
|
||||||
@export var player_data := {}
|
@export var player_data := {}
|
||||||
|
# keys are InventoryItem resource IDs (from db), values are InventoryItems
|
||||||
|
@export var inventory := {}
|
||||||
|
@export var coins: int
|
||||||
|
|
||||||
static var _instance := GameState.new()
|
static var _instance := GameState.new()
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
class_name Item
|
class_name InventoryItem
|
||||||
extends Resource
|
extends Resource
|
||||||
|
|
||||||
@export var icon: Texture2D = preload("res://icon.svg")
|
@export var icon: Texture2D = preload("res://icon.svg")
|
||||||
@export var name := "NAME"
|
@export var name := "NAME"
|
||||||
@export var id := &"ID"
|
@export var id := &"ID"
|
||||||
|
|
||||||
|
@export var count := 0
|
@ -35,6 +35,11 @@ func _on_player_joined(id: int) -> void:
|
|||||||
_register_player.rpc_id(id, username)
|
_register_player.rpc_id(id, username)
|
||||||
|
|
||||||
if _game_started:
|
if _game_started:
|
||||||
|
set_coins.rpc_id(id, GameState.fetch().coins)
|
||||||
|
|
||||||
|
for item_id in GameState.fetch().inventory:
|
||||||
|
set_inventory_item_count.rpc_id(id, item_id, GameState.fetch().inventory[item_id].count)
|
||||||
|
|
||||||
_start_game.rpc_id(id)
|
_start_game.rpc_id(id)
|
||||||
|
|
||||||
|
|
||||||
@ -173,3 +178,39 @@ func _on_chat_message_submitted(text := "") -> void:
|
|||||||
|
|
||||||
_submit_chat_message.rpc_id(1, _chat_input.text)
|
_submit_chat_message.rpc_id(1, _chat_input.text)
|
||||||
_chat_input.clear()
|
_chat_input.clear()
|
||||||
|
|
||||||
|
|
||||||
|
@rpc("authority", "call_local", "reliable")
|
||||||
|
func set_coins(value: int) -> void:
|
||||||
|
GameState.fetch().coins = value
|
||||||
|
|
||||||
|
|
||||||
|
@rpc("authority", "call_local", "reliable")
|
||||||
|
func add_inventory_item(item_id: StringName, amount: int) -> void:
|
||||||
|
if not GameState.fetch().inventory.has(item_id):
|
||||||
|
GameState.fetch().inventory[item_id] = GameState.INVENTORY_ITEM_DB[item_id].duplicate()
|
||||||
|
|
||||||
|
GameState.fetch().inventory[item_id].count += amount
|
||||||
|
|
||||||
|
|
||||||
|
@rpc("authority", "call_local", "reliable")
|
||||||
|
func remove_inventory_item(item_id: StringName, amount: int) -> void:
|
||||||
|
assert(GameState.fetch().inventory.has(item_id))
|
||||||
|
|
||||||
|
GameState.fetch().inventory[item_id].count -= amount
|
||||||
|
assert(GameState.fetch().inventory[item_id].count >= 0)
|
||||||
|
|
||||||
|
if GameState.fetch().inventory[item_id].count == 0:
|
||||||
|
GameState.fetch().inventory.erase(item_id)
|
||||||
|
|
||||||
|
|
||||||
|
@rpc("authority", "call_local", "reliable")
|
||||||
|
func set_inventory_item_count(item_id: StringName, value: int) -> void:
|
||||||
|
assert(value >= 0)
|
||||||
|
if not GameState.fetch().inventory.has(item_id):
|
||||||
|
GameState.fetch().inventory[item_id] = GameState.INVENTORY_ITEM_DB[item_id].duplicate()
|
||||||
|
|
||||||
|
GameState.fetch().inventory[item_id].count = value
|
||||||
|
|
||||||
|
if GameState.fetch().inventory[item_id].count == 0:
|
||||||
|
GameState.fetch().inventory.erase(item_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user