This repository has been archived on 2025-09-12. You can view files and clone it, but cannot push or open issues or pull requests.
ld49/level/Fridge.gd
2021-10-04 07:23:21 +03:00

71 lines
2.1 KiB
GDScript

class_name Fridge
extends Area
export var activity_cold_beverage: Resource
enum States {IDLE, WORKING}
var should_ignore_clicks: bool = false
var state: int = States.IDLE
var timeout: float = 0.0
func _ready() -> void:
connect("mouse_entered", self, "hover")
pass
func hover() -> void:
var activity_intent = get_current_activity_intent()
if !activity_intent:
return
var current_activity_title = activity_intent["activity"].displayed_name
#print("ACTIVITY TITLE: %s" % current_activity_title)
# TODO: add a tooltip saying current title
# TODO: add outline effect to the object
# NOTE: make sure there is only one object outlined at a time
pass
func get_current_activity_intent():
if should_ignore_clicks:
eprint("was clicked already")
return false
return {"activity": activity_cold_beverage, "handler": "set_using"}
func _input_event(camera, event, click_position, click_normal, shape_idx):
if !(event is InputEventMouseButton) or event.button_index != BUTTON_LEFT or !event.pressed:
return
var activity_intent = get_current_activity_intent()
if activity_intent:
should_ignore_clicks = true
var location = $ActivityLocations/Position3D
# TODO: have multiple locations to choose from, randomize it
get_node(@"/root/Game").set_activity(activity_intent["activity"], self, activity_intent["handler"], location)
match state:
States.IDLE:
return
States.WORKING:
eprint("chilling already")
# make some unhappy machine noises as machine is buy
return
func _process(delta: float) -> void:
var is_timeout = get_node(@"/root/Game").time_elapsed > timeout
if state == States.WORKING and is_timeout:
eprint("finished chilling at the fridge")
state = States.IDLE
# TODO: make a "fridge closing" noise
return
pass
func set_using():
should_ignore_clicks = false
eprint("using the fridge...")
state = States.WORKING
var beverage_duration: float = activity_cold_beverage.duration
timeout = get_node(@"/root/Game").time_elapsed + beverage_duration
# TODO: convert this into speech baloons
func eprint(text: String):
print("FRIDGE: %s" % text)