2025-02-04 08:38:42 +01:00

155 lines
5.5 KiB
GDScript

extends Node
enum scene {
INTRO,
MAIN,
}
@onready var crosshair_bone: SpineBoneNode = %CrosshairBone
@onready var evil_coco1: SpineSprite = %EvilCoco1
@onready var evil_coco2: SpineSprite = %EvilCoco2
@onready var ui: SpineSprite = %UI
@onready var ui_bone: SpineBoneNode = %UIBone
@onready var nv_hand: SpineSprite = %NVHand
@onready var gear_collision: CollisionPolygon2D = %GearCollision
@onready var gear_area: Area2D = %GearArea
var bounceS = GDRx.on_input_as_observable(self)\
.filter(is_right_mouse_click)\
.subscribe(start)\
.dispose_with(self)
func _ready() -> void:
#GDRx.from_signal(gear_enter_area.area_entered)
print(gear_area.collision_layer)
var gearOnS = GDRx.from_signal(gear_area.mouse_shape_entered)\
#.filter(is_right_mouse_click)\
.subscribe(show_ui)\
.dispose_with(self)
var gearOffS = GDRx.from_signal(gear_area.mouse_shape_exited)\
#.filter(is_right_mouse_click)\
.subscribe(hide_ui)\
.dispose_with(self)
var crosshairS = GDRx.on_process_as_observable(self)\
#.debounce(1)\
.subscribe(crosshair)\
.dispose_with(self)
var uiBoneS = GDRx.on_process_as_observable(self)\
#.debounce(1)\
.subscribe(ui_crosshair)\
.dispose_with(self)
#var play_soundsS = GDRx.from_signal(ui.animation_event)\
#.subscribe(func(a): print("play sound"); print(a))\
#.dispose_with(ui)
#var play_idleS = GDRx.from_signal(evil_coco2.animation_event)\
#.subscribe(func(a): print("idle"))\
#.dispose_with(ui)
evil_coco1.show()
evil_coco2.hide()
nv_hand.hide()
ui.hide()
evil_coco1.get_animation_state().set_animation("idle", true)
func ui_crosshair(_delta):
gear_area.global_position = ui_bone.global_position
func test_func(a: Object):
print(a.sprite)
var thisScript = a.get_script()
print('Properties of "%s":' % [ thisScript.resource_path ])
for propertyInfo in thisScript.get_script_property_list():
var propertyName: String = propertyInfo.name
var propertyValue = get(propertyName)
print(' %s = %s' % [ propertyName, propertyValue ])
func start(event: InputEvent) -> void:
evil_coco1.hide()
evil_coco2.show()
evil_coco2.get_animation_state().set_animation("start", false)
ui.show()
bounceS.dispose()
ui.get_animation_state().set_animation("main/closing", false)
evil_coco2.animation_event.connect(bounce)
ui.animation_event.connect(play_sounds)
func bounce(sprite: SpineSprite, animation_state: SpineAnimationState, track_entry: SpineTrackEntry, event: SpineEvent):
var event_name = event.get_data().get_event_name()
if event_name == "ready":
evil_coco2.get_animation_state().set_animation("idle", true)
func credits() -> void:
if OS.get_name() == "HTML5":
OS.shell_open("https://example.com")
#func _on_mouse_entered() -> void:
#Input.set_custom_mouse_cursor(load("res://assets/spine/out/cursor.png"))
#func _on_mouse_exited() -> void:
#Input.set_custom_mouse_cursor(null)
func crosshair(_delta):
crosshair_bone.global_position = get_viewport().get_mouse_position() + Vector2(-500, -942)
func is_right_mouse_click(event: InputEvent):
return event is InputEventMouseButton and event.button_index == 1
func play_sounds(sprite: SpineSprite, animation_state: SpineAnimationState, track_entry: SpineTrackEntry, event: SpineEvent):
var event_name = event.get_data().get_event_name()
if event_name == "open" and $open_sfx:
$open_sfx.play()
elif event_name == "close" and $close_sfx:
$close_sfx.play()
else:
return
#func animate_hand():
#var o = GDRx.on_input_as_observable(self)\
#.filter(func (e): return e is InputEventKey or e is InputEventMouseButton)\
#.subscribe(change_scene)\
#.dispose_with(self)
#func _ready() -> void:
#var gear = skeleton.find_slot("bb")
#animation_state.set_time_scale(time_scale)
#animation_state.set_animation("main/closing", false, 0)
#self.animation_event.connect(_on_animation_event)
func show_ui(_shape_idx: int) -> void:
ui.get_animation_state().set_animation("main/onopen", false, 0)
#gear_enter_area.hide()
#gear_leave_area.show()
func hide_ui(_shape_idx: int) -> void:
ui.get_animation_state().set_animation("main/onclose", false, 0)
#gear_enter_area.show()
#gear_leave_area.hide()
func set_skin(skin_choice: Globals.SkinChoices) -> void:
#var a = Globals.SkinChoices.find_key(skin_choice)
var slot: SpineSlot = evil_coco2.get_skeleton().find_slot("glasses")
var attch: SpineAttachment = evil_coco2.get_skeleton().get_attachment_by_slot_name("glasses", "nv_device")
slot.set_attachment(attch)
#var slots: Array = self.get_skeleton().get_slots()
#var skin = self.new_skin("default")
##for slot: SpineSlot in slots:
##print(slot.get_sequence_index(), " ", slot.get_attachment_state())
##var skin: SpineSkin = self.get_skeleton().get_skin()
#for key in Globals.current_choices:
#var a = skin.find_attachments_for_slot(key)
#print(a)
#print(skin.find_names_for_slot(slot.get_sequence_index()))
#func _ready() -> void:
#var gear = skeleton.find_slot("bb")
#animation_state.set_time_scale(time_scale)
#animation_state.set_animation("main/closing", false, 0)
#self.animation_event.connect(_on_animation_event)
#func _on_animation_event(sprite: SpineSprite, animation_state: SpineAnimationState, track_entry: SpineTrackEntry, event: SpineEvent):
#var event_name = event.get_data().get_event_name()
#if event_name == "open" and audio_stream_player2d:
#audio_stream_player2d.play()
#elif event_name == "close" and audio_stream_player2d:
#audio_stream_player2d.play()
#else:
#return