feat: Fix set_interactive command (#461)

Co-authored-by: Dennis Ploeger <develop@dieploegers.de>
This commit is contained in:
Dennis Ploeger
2021-11-25 07:26:11 +01:00
committed by GitHub
parent 7a69db03e9
commit 87ef9708de
2 changed files with 29 additions and 3 deletions

View File

@@ -10,7 +10,7 @@ var global_id: String
var active: bool = true setget _set_active
# Wether the object is interactive (clickable by the player)
var interactive: bool = true
var interactive: bool = true setget _set_interactive, _get_interactive
# The state of the object. If the object has a respective animation,
# it will be played
@@ -60,6 +60,25 @@ func _set_active(value: bool):
self.node.visible = value
# Get the interactive value from the node
#
# **Returns** Whether the node is interactive or not
func _get_interactive() -> bool:
if "is_interactive" in self.node:
return self.node.is_interactive
else:
return true
# Set the interactive value in the node
#
# #### Parameters
# - value: Whether the object is interactive or not
func _set_interactive(value: bool):
if "is_interactive" in self.node:
self.node.is_interactive = value
# Return the data of the object to be inserted in a savegame file.
#
# **Returns**

View File

@@ -270,9 +270,16 @@ func _ready():
#
# - event: Triggered event
func _unhandled_input(event: InputEvent) -> void:
if not escoria.current_state == escoria.GAME_STATE.DEFAULT:
return
if event is InputEventMouseButton and event.is_pressed():
if not escoria.current_state == escoria.GAME_STATE.DEFAULT or \
not is_interactive:
escoria.logger.info(
(
"Item %s is not interactive or the game state doesn't " +
"accept interactions"
) % global_id
)
return
var p = get_global_mouse_position()
var mouse_in_shape: bool = false
var colliders = get_world_2d().direct_space_state.intersect_point(