Merge branch 'gymkhana/main' of git.fosil.eu:gymkhana/gymkhana into gymkhana/main

This commit is contained in:
2023-09-25 23:07:20 +02:00
35 changed files with 410 additions and 70 deletions

View File

@@ -0,0 +1,40 @@
# `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.error(
self,
"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

View File

@@ -0,0 +1,57 @@
# `play_lib_snd`
#
# Plays a sound from the library.
#
# **Parameters**
#
# - *file_name*: File name withot extension
# - *namespace*: Subfolder
#
# @ESC
extends ESCBaseCommand
class_name PlayLibSound
# Return the descriptor of the arguments of this command
func configure() -> ESCCommandArgumentDescriptor:
return ESCCommandArgumentDescriptor.new(
1,
[TYPE_STRING,TYPE_STRING],
[null,""]
)
# Validate whether the given arguments match the command descriptor
func validate(arguments: Array):
if not .validate(arguments):
return false
var subFolder = arguments[1]
if(arguments[1] != ""):
subFolder += "/"
var resourceFile = "res://gymkhana/sounds/" + subFolder + arguments[0] + ".ogg"
if not ResourceLoader.exists(resourceFile):
escoria.logger.error(
self,
"[%s]: invalid parameter. File %s not found."
% [get_command_name(), resourceFile]
)
return false
return true
# Run the command
func run(command_params: Array) -> int:
var resourceFile = "res://gymkhana/sounds/" + command_params[0] + ".ogg"
escoria.object_manager.get_object("_sound").node.set_state(
resourceFile
)
return ESCExecution.RC_OK
# Function called when the command is interrupted.
func interrupt():
# Do nothing
pass

View File

@@ -0,0 +1,75 @@
# A manager for inventory objects
extends Resource
class_name ESCItemCountManager
func add(global_id: String, value:= 1) -> void:
var item = get_item(global_id)
set(global_id, item.count + value)
func remove(global_id: String, value:= 1) -> void:
var item = get_item(global_id)
set(global_id, item.count - value)
func set(global_id: String, value: int) -> void:
var item = get_item(global_id)
item.count = value
updateSprite(item)
escoria.globals_manager.set_global(global_id, value)
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.error(
self,
"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

View File

@@ -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

View File

@@ -310,7 +310,9 @@ func click_on_inventory_item(item_global_id: String, event: InputEvent, action:
# If item needs combination with this action, use the item texture as mouse cursor
if action in target_obj.combine_when_selected_action_is_in:
Input.set_custom_mouse_cursor(target_obj.inventory_texture)
var texture = target_obj.inventory_texture
var middleOfTheTexture = Vector2(texture.get_width() / 2, texture.get_height() / 2)
Input.set_custom_mouse_cursor(target_obj.inventory_texture, 0, middleOfTheTexture)
escoria.action_manager.do(
escoria.action_manager.ACTION.ITEM_LEFT_CLICK,

View File

@@ -12,12 +12,25 @@ func get_plugin_name():
func disable_plugin():
print("Disabling plugin Escoria UI Return to Monkey Island.")
EscoriaPlugin.deregister_ui("res://gymkhana/addons/escoria-ui-return-monkey-island/game.tscn")
ESCProjectSettingsManager.remove_setting(
RTMIUiSettings.SOUND_LIBRARY_FOLDER
)
# Register UI with Escoria
func enable_plugin():
print("Enabling plugin Escoria UI Return to Monkey Island.")
if not EscoriaPlugin.register_ui(self, "res://gymkhana/addons/escoria-ui-return-monkey-island/game.tscn"):
print("Enabling plugin Escoria Dialog Simple")
if EscoriaPlugin.register_ui(self, "res://gymkhana/addons/escoria-ui-return-monkey-island/game.tscn"):
ESCProjectSettingsManager.register_setting(
RTMIUiSettings.SOUND_LIBRARY_FOLDER,
"res://game/sounds",
{
"type": TYPE_STRING
}
)
else:
get_editor_interface().set_plugin_enabled(
get_plugin_name(),
false

View File

@@ -0,0 +1,7 @@
extends Resource
class_name RTMIUiSettings
const SETTINGS_ROOT = "escoria/rtmi_ui"
const SOUND_LIBRARY_FOLDER = "%s/sound_library_folder" % SETTINGS_ROOT