Skip to content

Commit

Permalink
feat: Fix set_interactive command (#461)
Browse files Browse the repository at this point in the history
Co-authored-by: Dennis Ploeger <[email protected]>
  • Loading branch information
dploeger and dploeger authored Nov 25, 2021
1 parent 7a69db0 commit 87ef970
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
21 changes: 20 additions & 1 deletion addons/escoria-core/game/core-scripts/esc/types/esc_object.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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**
Expand Down
11 changes: 9 additions & 2 deletions addons/escoria-core/game/core-scripts/esc_item.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 87ef970

Please sign in to comment.