gymkhana/item_count (#16)
Item can now be countable objects, like money, bullets or even potatoes! Reviewed-on: gymkhana/gymkhana#16
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
# `item_count_add item_id value`
|
||||
#
|
||||
# Add value to the count in a item.
|
||||
# - item_id: string: id of the item to apply
|
||||
# - value: int: number to add
|
||||
#
|
||||
# @ESC
|
||||
extends ESCBaseCommand
|
||||
class_name ItemCountAddCommand
|
||||
|
||||
|
||||
var item_count_manager = ESCItemCountManager.new()
|
||||
|
||||
# Return the descriptor of the arguments of this command
|
||||
func configure() -> ESCCommandArgumentDescriptor:
|
||||
return ESCCommandArgumentDescriptor.new(
|
||||
1,
|
||||
[TYPE_STRING, TYPE_INT],
|
||||
[null, 1]
|
||||
)
|
||||
|
||||
|
||||
# Validate wether the given arguments match the command descriptor
|
||||
func validate(arguments: Array):
|
||||
if not escoria.object_manager.has(arguments[0]):
|
||||
escoria.logger.report_errors(
|
||||
"item_count_add: invalid object",
|
||||
["Object %s not registered" % arguments[0]]
|
||||
)
|
||||
return false
|
||||
|
||||
return .validate(arguments)
|
||||
|
||||
|
||||
# Run the command
|
||||
func run(command_params: Array) -> int:
|
||||
item_count_manager.add(command_params[0], command_params[1])
|
||||
|
||||
return ESCExecution.RC_OK
|
||||
@@ -0,0 +1,76 @@
|
||||
# A manager for inventory objects
|
||||
extends Resource
|
||||
class_name ESCItemCountManager
|
||||
|
||||
|
||||
func add(global_id: String, value:= 1) -> void:
|
||||
var item = get_item(global_id)
|
||||
item.count = item.count + value
|
||||
updateSprite(item)
|
||||
|
||||
|
||||
func remove(global_id: String, value:= 1) -> void:
|
||||
var item = get_item(global_id)
|
||||
item.count = item.count - value
|
||||
updateSprite(item)
|
||||
|
||||
|
||||
func set(global_id: String, value: int) -> void:
|
||||
var item = get_item(global_id)
|
||||
item.count = value
|
||||
updateSprite(item)
|
||||
|
||||
|
||||
func removeFromInventoryIfCountLessThan(global_id: String, value:= 1) -> void:
|
||||
var item = get_item(global_id)
|
||||
if item.count < value:
|
||||
escoria.inventory_manager.remove_item(global_id)
|
||||
|
||||
|
||||
func get_item(global_id: String) -> ESCItem:
|
||||
var node = escoria.object_manager.get_object(global_id).node
|
||||
if not node is ESCItem:
|
||||
escoria.logger.error(
|
||||
"item_count_add: invalid object",
|
||||
["Object is not an ESCItem"]
|
||||
)
|
||||
return null
|
||||
|
||||
return node
|
||||
|
||||
|
||||
func updateSprite(item: ESCItemWithTooltip) -> void:
|
||||
var child_node = item.get_node("Sprite") as Sprite
|
||||
if not child_node is Sprite:
|
||||
escoria.logger.report_errors(
|
||||
"item_count_add: invalid sprite",
|
||||
["No Sprite node found"]
|
||||
)
|
||||
|
||||
var texture_path = getCountTexturePath(item)
|
||||
var texture = load(texture_path)
|
||||
|
||||
# Update texture in scene
|
||||
var sprite = child_node as Sprite
|
||||
sprite.texture = texture
|
||||
|
||||
# Update texture in scene
|
||||
# TODO optional inventory_texture
|
||||
# TODO change inventory texture without removing and adding the item
|
||||
# https://github.com/godot-escoria/escoria-issues/issues/364
|
||||
# https://discord.com/channels/884336424780984330/1124614097917460584/1127151969614696548
|
||||
item.inventory_texture = texture
|
||||
if escoria.inventory_manager.inventory_has(item.global_id):
|
||||
escoria.inventory_manager.remove_item(item.global_id)
|
||||
escoria.inventory_manager.add_item(item.global_id)
|
||||
|
||||
|
||||
func getCountTexturePath(item: ESCItemWithTooltip) -> String:
|
||||
var count = item.count
|
||||
var textures = item.count_textures # TODO sort dictionaries by start key
|
||||
var i = 0
|
||||
|
||||
while (i < textures.size() - 1) and count >= textures[i + 1].start:
|
||||
i = i + 1
|
||||
|
||||
return textures[i].texture
|
||||
@@ -19,12 +19,26 @@ export(Dictionary) var tooltips = {}
|
||||
# Action 3 tooltip texts if item is target. Dictionary with tool's global id as key.
|
||||
export(Dictionary) var action3_target_texts = {}
|
||||
|
||||
# Action 4 tooltip texts if item is target. Dictionary with tool's global id as key.
|
||||
# Action 4 tooltip texts if item is target. Dictionary with tool's global id as key
|
||||
export(Dictionary) var action4_target_texts = {}
|
||||
|
||||
# If action used by player is in this list, this is a valid target (second item in combination)
|
||||
export(Array) var target_when_selected_action_is_in = []
|
||||
|
||||
# If item is countable (E.g. money) marks the quantity
|
||||
export(int) var count = 0
|
||||
|
||||
# If item is countable (E.g. money) marks which texture to use depending of count value.
|
||||
# Each element is a Dictionary with start and texture keys:
|
||||
# [
|
||||
# { "start": 0, "texture": "res://gymkhana/items/inventory/assets/no_money.png"},
|
||||
# { "start": 1, "texture": "res://gymkhana/items/inventory/assets/one_coin.png"},
|
||||
# { "start": 2, "texture": "res://gymkhana/items/inventory/assets/two_coins.png"},
|
||||
# { "start": 3, "texture": "res://gymkhana/items/inventory/assets/coins.png"},
|
||||
# { "start": 10, "texture": "res://gymkhana/items/inventory/assets/bills.png"},
|
||||
# ]
|
||||
export(Array) var count_textures = []
|
||||
|
||||
var outline: ItemOutline
|
||||
|
||||
var isHighlighted: bool
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
:action3
|
||||
say player "Es mi frontal de toda la vida, le tengo cariño"
|
||||
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
:action1
|
||||
say player "Que cosa tan curiosa"
|
||||
|
||||
say player "Que patata más bonita, cómo se nota que es de la huerta."
|
||||
|
||||
:action2
|
||||
say player "No lo quiero coger"
|
||||
say player "Bieen! una patata!"
|
||||
set_active turno_cocina_patata false
|
||||
item_count_add turno_cocina_patata
|
||||
inventory_add turno_cocina_patata
|
||||
|
||||
:action3
|
||||
say player "Que patata más bonita, cómo se nota que es de la huerta."
|
||||
|
||||
@@ -15,12 +15,17 @@ esc_script = "res://gymkhana/items/inventory/turno_cocina_patata.esc"
|
||||
inventory_texture = ExtResource( 2 )
|
||||
dialog_color = Color( 1, 1, 1, 1 )
|
||||
tooltips = {
|
||||
"action1": "¿Que es esto?",
|
||||
"action2": "Coger",
|
||||
"action3": "Mirar",
|
||||
"action4": "Usar"
|
||||
"action1": "Admirar la patata",
|
||||
"action2": "Cogerla",
|
||||
"action3": "Admirar la patata",
|
||||
}
|
||||
animations = null
|
||||
count_textures = [
|
||||
{ "start": 1, "texture": "res://gymkhana/items/inventory/assets/turno_cocina_patata.png" },
|
||||
{ "start": 2, "texture": "res://gymkhana/items/inventory/assets/turno_cocina_dos_patatas.png" },
|
||||
{ "start": 3, "texture": "res://gymkhana/items/inventory/assets/turno_cocina_tres_patatas.png" },
|
||||
{ "start": 4, "texture": "res://gymkhana/items/inventory/assets/turno_cocina_cuatro_patatas.png" },
|
||||
]
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
position = Vector2( -2, 0 )
|
||||
@@ -33,4 +38,4 @@ shape = SubResource( 1 )
|
||||
|
||||
[node name="ESCLocation" type="Position2D" parent="."]
|
||||
position = Vector2( -51, 69 )
|
||||
script = ExtResource( 3 )
|
||||
script = ExtResource( 3 )
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
:action1
|
||||
say player "Hay una patata!"
|
||||
say player "Solo veo pieles de cebollas."
|
||||
|
||||
:action2
|
||||
say current_player "Bieeen!!! una patata!"
|
||||
say current_player "Bieeen!!! Había una patata!"
|
||||
set_active turno_cocina_patata_grande false
|
||||
inventory_add turno_cocina_patata_grande
|
||||
|
||||
:action3
|
||||
say current_player "Es bien grande"
|
||||
say current_player "Es la segunda patata más grande que he visto nunca."
|
||||
|
||||
:action4
|
||||
say current_player "Así no me sirve de nada"
|
||||
say current_player "Creo que necesito patatas normales, no patatas gigantes..."
|
||||
|
||||
@@ -11,10 +11,4 @@ esc_script = "res://gymkhana/items/inventory/turno_cocina_patata_grande.esc"
|
||||
combine_when_selected_action_is_in = [ ]
|
||||
inventory_texture = ExtResource( 2 )
|
||||
dialog_color = Color( 1, 1, 1, 1 )
|
||||
tooltips = {
|
||||
"action1": "¿Que es esto?",
|
||||
"action2": "Coger",
|
||||
"action3": "Mirar",
|
||||
"action4": "Usar"
|
||||
}
|
||||
animations = null
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
:action1
|
||||
say player "Es un peso, con esto podría coger la cantidad exacta de algún ingrediente"
|
||||
say player "Es un peso, con esto podría coger la cantidad exacta de algún ingrediente"
|
||||
|
||||
:action2
|
||||
say current_player "Podria ser útil!!"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=13 format=2]
|
||||
[gd_scene load_steps=14 format=2]
|
||||
|
||||
[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_room.gd" type="Script" id=1]
|
||||
[ext_resource path="res://gymkhana/characters/oier/oier.tscn" type="PackedScene" id=2]
|
||||
@@ -11,6 +11,7 @@
|
||||
[ext_resource path="res://gymkhana/rooms/turno_cocina/cocina/assets/foreground-silla.png" type="Texture" id=9]
|
||||
[ext_resource path="res://gymkhana/items/inventory/turno_cocina_peso.tscn" type="PackedScene" id=10]
|
||||
[ext_resource path="res://gymkhana/items/inventory/turno_cocina_bol.tscn" type="PackedScene" id=11]
|
||||
[ext_resource path="res://gymkhana/items/inventory/turno_cocina_patata.tscn" type="PackedScene" id=12]
|
||||
|
||||
[sub_resource type="NavigationPolygon" id=3]
|
||||
vertices = PoolVector2Array( 2398, 485, 2442, 499, 2446, 617, 2409, 597, 2283, 493, 144, 568, 3, 570, -56, 524, 111, 445, 162, 471, 229, 445, 200, 465, 252, 478, 305, 524, 273, 570, 2287, 687, 2062, 635, 2113, 565, 696, 737, 512, 591, 703, 699, 1269, 739, 1241, 699, 1502, 646, 1409, 752, 1345, 667, 1489, 627, 1347, 563, 1480, 587, 1466, 514, 1345, 505, 1382, 439, 2109, 424, 2238, 386, 1788, 325, 2018, 419, 1787, 383, 1466, 412, 1493, 479, 1305.5, 467, 1337.5, 449, 1306.5, 498 )
|
||||
@@ -39,7 +40,7 @@ player_doubleclick_speed_multiplier = 2.0
|
||||
|
||||
[node name="Foreground-mesa" type="Sprite" parent="ESCTerrain"]
|
||||
position = Vector2( 1786, 424 )
|
||||
z_index = 4096
|
||||
z_index = 1000
|
||||
texture = ExtResource( 8 )
|
||||
|
||||
[node name="NavigationPolygonInstance" type="NavigationPolygonInstance" parent="ESCTerrain"]
|
||||
@@ -60,7 +61,7 @@ is_exit = true
|
||||
combine_when_selected_action_is_in = [ ]
|
||||
dialog_color = Color( 1, 1, 1, 1 )
|
||||
tooltips = {
|
||||
"action1": "Ir detrás"
|
||||
"action1": "Ir detrás"
|
||||
}
|
||||
animations = null
|
||||
|
||||
@@ -84,7 +85,7 @@ is_exit = true
|
||||
combine_when_selected_action_is_in = [ ]
|
||||
dialog_color = Color( 1, 1, 1, 1 )
|
||||
tooltips = {
|
||||
"action1": "Salir de la cocina"
|
||||
"action1": "Salir de la cocina"
|
||||
}
|
||||
animations = null
|
||||
|
||||
@@ -130,8 +131,8 @@ esc_script = "res://gymkhana/rooms/turno_cocina/cocina/esc/fregadero_der.esc"
|
||||
combine_when_selected_action_is_in = [ ]
|
||||
dialog_color = Color( 1, 1, 1, 1 )
|
||||
tooltips = {
|
||||
"action1": "Mirar fregadero",
|
||||
"action2": "Usar"
|
||||
"action1": "Mirar fregadero",
|
||||
"action2": "Usar"
|
||||
}
|
||||
action3_target_texts = {
|
||||
"turno_cocina_bol": "Llenar el bol de agua",
|
||||
@@ -155,8 +156,8 @@ esc_script = "res://gymkhana/rooms/turno_cocina/cocina/esc/fregadero_izq.esc"
|
||||
combine_when_selected_action_is_in = [ ]
|
||||
dialog_color = Color( 1, 1, 1, 1 )
|
||||
tooltips = {
|
||||
"action1": "Mirar fregadero",
|
||||
"action2": "Usar"
|
||||
"action1": "Mirar el fregadero",
|
||||
"action2": "Usar"
|
||||
}
|
||||
action3_target_texts = {
|
||||
"turno_cocina_bol": "Llenar el bol de agua",
|
||||
@@ -180,11 +181,11 @@ esc_script = "res://gymkhana/rooms/turno_cocina/cocina/esc/debajo_sofa.esc"
|
||||
combine_when_selected_action_is_in = [ "action4" ]
|
||||
dialog_color = Color( 1, 1, 1, 1 )
|
||||
tooltips = {
|
||||
"action1": "Mirar debajo del sofa",
|
||||
"action2": "Meter la mano"
|
||||
"action1": "Mirar debajo del sofa",
|
||||
"action2": "Meter la mano"
|
||||
}
|
||||
action3_target_texts = {
|
||||
"turno_cocina_frontal": "Mirar denajo del sofa"
|
||||
"turno_cocina_frontal": "Alumbrar debajo del sofa"
|
||||
}
|
||||
target_when_selected_action_is_in = [ "action3" ]
|
||||
animations = null
|
||||
@@ -195,3 +196,19 @@ polygon = PoolVector2Array( 484, 406, 485, 421, 556, 423, 551, 415, 550, 409, 55
|
||||
[node name="ESCLocation" type="Position2D" parent="debajo_sofa"]
|
||||
position = Vector2( 420, 494 )
|
||||
script = ExtResource( 5 )
|
||||
|
||||
[node name="turno_cocina_patata" parent="." instance=ExtResource( 12 )]
|
||||
position = Vector2( 2202, 343 )
|
||||
rotation = -0.270526
|
||||
scale = Vector2( 0.35, 0.35 )
|
||||
z_index = 1001
|
||||
combine_when_selected_action_is_in = [ ]
|
||||
|
||||
[node name="turno_cocina_patata_collision" type="CollisionPolygon2D" parent="turno_cocina_patata"]
|
||||
position = Vector2( 9.0867, -13.5233 )
|
||||
z_index = 1001
|
||||
polygon = PoolVector2Array( 6.50781, 0.0583801, 20.7368, 12.8992, 7.896, 27.1279, -19.937, 31.269, -42.4258, 16.1375, -26.0684, -0.0810547 )
|
||||
|
||||
[node name="turno_cocina_patata_location" type="Position2D" parent="turno_cocina_patata"]
|
||||
position = Vector2( 93.1357, 65.3632 )
|
||||
script = ExtResource( 5 )
|
||||
|
||||
@@ -8,15 +8,10 @@
|
||||
stop
|
||||
|
||||
say player "Bieen! una patata!"
|
||||
item_count_add turno_cocina_patata
|
||||
inventory_add turno_cocina_patata
|
||||
set_active cocina_debajo_sofa false
|
||||
|
||||
:action3 turno_cocina_bol_lentejas
|
||||
say player "Agua a ojo... en su justa medida."
|
||||
inventory_remove turno_cocina_peso_bol
|
||||
inventory_add turno_cocina_bol_lentejas
|
||||
inventory_add turno_cocina_peso
|
||||
|
||||
:action3 turno_cocina_frontal
|
||||
say player "Veo una patata!!"
|
||||
set_global turno_cocina_frontal_debajo_sofa true
|
||||
|
||||
@@ -141,7 +141,7 @@ pause_mode = 1
|
||||
position = Vector2( 941, 385 )
|
||||
script = ExtResource( 6 )
|
||||
global_id = "turno_cocina_despensa_bidon_izq"
|
||||
esc_script = "res://gymkhana/rooms/turno_cocina/despensa/esc/bidon_der.esc"
|
||||
esc_script = "res://gymkhana/rooms/turno_cocina/despensa/esc/bidon_izq.esc"
|
||||
combine_when_selected_action_is_in = [ ]
|
||||
dialog_color = Color( 1, 1, 1, 1 )
|
||||
tooltips = {
|
||||
@@ -163,7 +163,10 @@ script = ExtResource( 5 )
|
||||
position = Vector2( 440, 161 )
|
||||
scale = Vector2( 0.880435, 0.88735 )
|
||||
tooltips = {
|
||||
"action1": "Mirar"
|
||||
"action1": "Mirar",
|
||||
"action2": "Rascar por el fondo",
|
||||
"action3": "Mirar",
|
||||
"action4": "Usar"
|
||||
}
|
||||
|
||||
[node name="ESCLocation2" type="Position2D" parent="turno_cocina_patata_grande"]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
:action1
|
||||
say player "Está lleno de algo que no se que es."
|
||||
say player "Está lleno de algo que no sé que es."
|
||||
|
||||
:action2
|
||||
say player "Lo que hay dentro no lo necesito para nada."
|
||||
say player "Lo que hay dentro no lo necesito para nada."
|
||||
|
||||
Reference in New Issue
Block a user