2022-02-15 20:41:14 +00:00
|
|
|
extends Node3D
|
|
|
|
|
|
|
|
var oldobject:Node3D = null
|
2023-04-07 11:41:06 +00:00
|
|
|
#@onready var player_ptr = $player
|
2022-10-31 18:43:59 +00:00
|
|
|
@export var PlayerCharacter = preload("res://PlayerB/Player/Player.tscn")
|
2022-03-30 20:32:56 +00:00
|
|
|
|
2022-02-15 20:41:14 +00:00
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
2022-10-31 18:43:59 +00:00
|
|
|
single_player()
|
|
|
|
# $player.connect("switch_to_ship", self.switch_to_ship.bind() )
|
2022-02-15 20:41:14 +00:00
|
|
|
# $player_ship.set_process(false)
|
|
|
|
# $player_ship.hide()
|
|
|
|
|
|
|
|
|
2022-10-31 18:43:59 +00:00
|
|
|
func single_player():
|
|
|
|
#singleplayer = true
|
|
|
|
#$ListenServer.visible = false
|
|
|
|
#$DServer.visible = false
|
|
|
|
#$Client.visible = false
|
|
|
|
#$Singleplayer.visible = false
|
|
|
|
var p = PlayerCharacter.instantiate()
|
2023-04-07 11:41:06 +00:00
|
|
|
if !weakref(p).get_ref():
|
|
|
|
Common.msg_error("Erreur")
|
|
|
|
get_tree().quit() # default behavior
|
|
|
|
return
|
2022-10-31 18:43:59 +00:00
|
|
|
$PlayerSpawnLocation.add_child(p)
|
|
|
|
|
|
|
|
|
2022-02-15 20:41:14 +00:00
|
|
|
func change_creature( new_model_path ):
|
|
|
|
var new_model = load( new_model_path )
|
|
|
|
if new_model:
|
|
|
|
new_model = new_model.instantiate()
|
|
|
|
new_model.translate($player.get_position())
|
|
|
|
if $player:
|
|
|
|
print("Remove old")
|
|
|
|
var old_model = $player
|
|
|
|
self.remove_child( old_model )
|
|
|
|
#self.animation_object = null
|
|
|
|
old_model.queue_free()
|
|
|
|
if new_model:
|
|
|
|
print("Add new")
|
|
|
|
self.add_child( new_model )
|
|
|
|
#new_model.connect( "animation_finished", self, "_on_creature_animation_finished" )
|
|
|
|
# new_model.duplicate_meshes()
|
|
|
|
|
|
|
|
func switch_to_ship(near_boat):
|
|
|
|
near_boat.hide()
|
|
|
|
oldobject = near_boat
|
|
|
|
print("GO switch_to_ship:", str(near_boat))
|
|
|
|
|
|
|
|
var new_model = load( "res://player/player_ship/player_ship.tscn" )
|
|
|
|
if new_model:
|
|
|
|
new_model = new_model.instantiate()
|
|
|
|
print("A:", near_boat.get_position())
|
|
|
|
print("B:", near_boat.get_global_transform().origin )
|
|
|
|
var newpos:Vector3 = near_boat.get_global_transform().origin
|
|
|
|
new_model.translate(newpos)
|
|
|
|
if $player:
|
|
|
|
print("Remove old")
|
|
|
|
var old_model = $player
|
|
|
|
self.remove_child( old_model )
|
|
|
|
#self.animation_object = null
|
|
|
|
old_model.queue_free()
|
|
|
|
if new_model:
|
|
|
|
print("Add new")
|
|
|
|
self.add_child( new_model )
|
|
|
|
# $player.set_process(false)
|
|
|
|
# $player.hide()
|
|
|
|
# $player_ship.show()
|
|
|
|
# $player_ship.set_process(true)
|