Update HEADS to get the new ESS changes. Because of these changes the Entities autoload is now removed, it's code/functionality has been brought into a new bs_entity_spawner resource.

This commit is contained in:
Relintai 2020-04-18 14:35:28 +02:00
parent f0ade5e332
commit dada397e92
12 changed files with 57 additions and 45 deletions

View File

@ -185,7 +185,7 @@ remotesync func cspawn_player(info : Dictionary, sid : int, pos : Vector3):
Logger.verbose("NetworkManager cspawn_player")
if sid == get_tree().get_network_unique_id():
local_player_master.player = Entities.spawn_player(info["selected_class"] as int, pos, info["name"] as String, str(sid), sid)
local_player_master.player = ESS.get_ess_entity_spawner().spawn_player(info["selected_class"] as int, pos, info["name"] as String, str(sid), sid)
call_deferred("set_terrarin_player")
if get_tree().is_network_server() and not splayers_dict.has(sid):
@ -195,7 +195,7 @@ remotesync func cspawn_player(info : Dictionary, sid : int, pos : Vector3):
var pm : PlayerMaster = PlayerMaster.new()
pm.sid = sid
pm.player = Entities.spawn_networked_player(info["selected_class"] as int, pos, info["name"] as String, str(sid), sid)
pm.player = ESS.get_ess_entity_spawner().spawn_networked_player(info["selected_class"] as int, pos, info["name"] as String, str(sid), sid)
if get_tree().is_network_server() and not splayers_dict.has(sid):
splayers_dict[sid] = pm
@ -209,7 +209,7 @@ func upload_character(data : String) -> void:
rpc_id(1, "sreceive_upload_character", data)
master func sreceive_upload_character(data: String) -> void:
Entities.spawn_networked_player_from_data(data, Vector3(0, 10, 0), multiplayer.get_rpc_sender_id())
ESS.get_ess_entity_spawner().spawn_networked_player_from_data(data, Vector3(0, 10, 0), multiplayer.get_rpc_sender_id())
func set_terrarin_player():
Logger.verbose("NetworkManager cspawn_player")

View File

@ -170,7 +170,7 @@ func generate_terrarin(chunk : VoxelChunk) -> void:
# chunk.draw_debug_voxel_lights()
if not Engine.editor_hint and chunk.position_y == 0 and _spawn_mobs:
Entities.spawn_mob(1, randi() % 3, Vector3(chunk.position_x * chunk.size_x * chunk.voxel_scale - chunk.size_x / 2,\
ESS.entity_spawner.spawn_mob(1, randi() % 3, Vector3(chunk.position_x * chunk.size_x * chunk.voxel_scale - chunk.size_x / 2,\
(chunk.position_y + 1) * chunk.size_y * chunk.voxel_scale, \
chunk.position_z * chunk.size_z * chunk.voxel_scale - chunk.size_z / 2))

View File

@ -83,15 +83,15 @@ func spawn():
spawned = true
if get_tree().network_peer == null:
player = Entities.spawn_player(1, Vector3(10, 20, 10), "Player", "1", 1)
player = ESS.entity_spawner.spawn_player(1, Vector3(10, 20, 10), "Player", "1", 1)
call_deferred("set_terrarin_player")
#
# Entities.spawn_mob(1, 50, Vector3(20, 6, 20))
# Entities.spawn_mob(1, 50, Vector3(54, 6, 22))
# Entities.spawn_mob(1, 50, Vector3(76, 6, 54))
# ESS.entity_spawner.spawn_mob(1, 50, Vector3(20, 6, 20))
# ESS.entity_spawner.spawn_mob(1, 50, Vector3(54, 6, 22))
# ESS.entity_spawner.spawn_mob(1, 50, Vector3(76, 6, 54))
func set_terrarin_player():
terrarin.set_player(player as Spatial)
terrarin.set_player(player.get_body() as Spatial)
func _on_host_button_clicked():
get_tree().connect("network_peer_connected", self, "_network_peer_connected")

View File

@ -87,7 +87,7 @@ func update_visibility() -> void:
var ent : Entity = e as Entity
if self.get_network_master() != 1:
Entities.despawn_for(self, ent)
ESS.entity_spawner.despawn_for(self, ent)
removes_sees(ent)
@ -95,7 +95,7 @@ func update_visibility() -> void:
var ent : Entity = e as Entity
if self.get_network_master() != 1:
Entities.spawn_for(self, ent)
ESS.entity_spawner.spawn_for(self, ent)
adds_sees(ent)

View File

@ -1,4 +1,4 @@
extends Node
extends ESSEntitySpawner
# Copyright Péter Magyar relintai@gmail.com
# MIT License, functionality from this class needs to be protable to the entity spell system
@ -35,31 +35,36 @@ var _spawn_parent : Node = null
var _next_entity_guid : int = 0
func _ready():
_spawn_parent = get_node(spawn_parent_path)
# get_scene_tree().multiplayer.connect("network_peer_packet", self, "on_network_peer_packet")
ProfileManager.load()
ESS.load_resource_db()
ESS.get_resource_db().load_all()
ESS.connect("on_entity_spawn_requested", self, "on_entity_spawn_requested")
# ProfileManager.load()
# ESS.load_resource_db()
# ESS.get_resource_db().load_all()
# ESS.connect("on_entity_spawn_requested", self, "on_entity_spawn_requested")
# get_tree().connect("network_peer_connected", self, "_player_connected")
# get_tree().connect("network_peer_disconnected", self, "_player_disconnected")
# get_tree().connect("connected_to_server", self, "_connected_ok")
# get_tree().connect("connection_failed", self, "_connected_fail")
# get_tree().connect("server_disconnected", self, "_server_disconnected")
pass
func on_network_peer_packet(id : int, packet : PoolByteArray) ->void:
#todo
pass
func spawn_for(player : Entity, target: Entity) -> void:
Logger.info("spawnfor " + target.name)
rpc_id(player.get_network_master(), "creceive_spawn_for", to_json(target.to_dict()), target.name, target.translation)
# rpc_id(player.get_network_master(), "creceive_spawn_for", to_json(target.to_dict()), target.name, target.translation)
func despawn_for(player : Entity, target: Entity) -> void:
Logger.info("despawnfor " + target.name)
rpc_id(player.get_network_master(), "creceive_despawn_for", target.get_path())
# rpc_id(player.get_network_master(), "creceive_despawn_for", target.get_path())
remote func creceive_spawn_for(data: String, global_name : String, position: Vector3) -> Entity:
var createinfo : EntityCreateInfo = EntityCreateInfo.new()
createinfo.player_name = name
createinfo.player_name = global_name
createinfo.entity_controller = EntityEnums.ENITIY_CONTROLLER_PLAYER
createinfo.entity_player_type = EntityEnums.ENTITY_PLAYER_TYPE_NETWORKED
createinfo.serialized_data = parse_json(data)
@ -73,7 +78,7 @@ remote func creceive_spawn_for(data: String, global_name : String, position: Vec
remote func creceive_despawn_for(path : NodePath) -> void:
# print("recdespawnfor " + path)
var ent = get_node_or_null(path)
var ent = get_scene_tree().root.get_node_or_null(path)
if ent:
ent.queue_free()
@ -81,8 +86,8 @@ remote func creceive_despawn_for(path : NodePath) -> void:
puppet func spawn_owned_player(data : String, position : Vector3) -> Entity:
var createinfo : EntityCreateInfo = EntityCreateInfo.new()
createinfo.guid = multiplayer.get_network_unique_id()
createinfo.player_name = name
createinfo.guid = get_scene_tree().multiplayer.get_network_unique_id()
# createinfo.player_name = ""
createinfo.entity_controller = EntityEnums.ENITIY_CONTROLLER_PLAYER
createinfo.entity_player_type = EntityEnums.ENTITY_PLAYER_TYPE_PLAYER
createinfo.serialized_data = parse_json(data)
@ -99,7 +104,7 @@ func load_player(file_name : String, position : Vector3, network_owner : int) ->
createinfo.guid = _next_entity_guid
_next_entity_guid += 1
createinfo.player_name = name
# createinfo.player_name = name
createinfo.entity_controller = EntityEnums.ENITIY_CONTROLLER_PLAYER
createinfo.entity_player_type = EntityEnums.ENTITY_PLAYER_TYPE_PLAYER
createinfo.serialized_data = load_file(file_name)
@ -143,7 +148,7 @@ func spawn_display_player(file_name : String, node_path : NodePath) -> Entity:
createinfo.guid = _next_entity_guid
_next_entity_guid += 1
createinfo.player_name = name
# createinfo.player_name = name
createinfo.entity_controller = EntityEnums.ENITIY_CONTROLLER_PLAYER
createinfo.entity_player_type = EntityEnums.ENTITY_PLAYER_TYPE_DISPLAY
createinfo.serialized_data = load_file(file_name)
@ -157,7 +162,7 @@ func spawn_display_player(file_name : String, node_path : NodePath) -> Entity:
func spawn_networked_player(class_id : int, position : Vector3, name : String, node_name : String, sid : int) -> Entity:
var createinfo : EntityCreateInfo = EntityCreateInfo.new()
var cls : EntityData = Entities.get_player_character_data(class_id)
var cls : EntityData = ESS.resource_db.get_player_character_data(class_id)
var class_profile : ClassProfile = ProfileManager.get_class_profile(class_id)
var level : int = class_profile.level
@ -187,7 +192,7 @@ func spawn_networked_player(class_id : int, position : Vector3, name : String,
func spawn_player(class_id : int, position : Vector3, name : String, node_name : String, network_owner : int) -> Entity:
var createinfo : EntityCreateInfo = EntityCreateInfo.new()
var cls : EntityData = Entities.get_player_character_data(class_id)
var cls : EntityData = ESS.resource_db.get_player_character_data(class_id)
var class_profile : ClassProfile = ProfileManager.get_class_profile(class_id)
var level : int = class_profile.level
@ -236,7 +241,7 @@ func spawn_mob(class_id : int, level : int, position : Vector3) -> void:
#return createinfo.created_entity
func on_entity_spawn_requested(createinfo : EntityCreateInfo):
func _request_entity_spawn(createinfo : EntityCreateInfo):
var entity_node : Entity = null
if createinfo.entity_player_type == EntityEnums.ENTITY_PLAYER_TYPE_DISPLAY:
@ -257,12 +262,15 @@ func on_entity_spawn_requested(createinfo : EntityCreateInfo):
entity_node.get_body().translation = createinfo.transform.origin
if (createinfo.parent_path == ""):
if _spawn_parent == null:
_spawn_parent = get_scene_tree().root.get_node(spawn_parent_path)
if _spawn_parent.current_scene != null:
var spawn_parent = _spawn_parent.current_scene
spawn_parent.add_child(entity_node)
else:
get_node(createinfo.parent_path).add_child(entity_node)
get_scene_tree().root.get_node(createinfo.parent_path).add_child(entity_node)
entity_node.setup(createinfo)

View File

@ -1,14 +1,16 @@
[gd_scene load_steps=6 format=2]
[gd_resource type="ESSEntitySpawner" load_steps=6 format=2]
[ext_resource path="res://autoload/Entities.gd" type="Script" id=1]
[ext_resource path="res://player/bs_entity_spawner.gd" type="Script" id=1]
[ext_resource path="res://player/NetworkedPlayer.tscn" type="PackedScene" id=2]
[ext_resource path="res://player/Player.tscn" type="PackedScene" id=3]
[ext_resource path="res://player/Mob.tscn" type="PackedScene" id=4]
[ext_resource path="res://player/DisplayPlayer.tscn" type="PackedScene" id=5]
[ext_resource path="res://player/Mob.tscn" type="PackedScene" id=3]
[ext_resource path="res://player/DisplayPlayer.tscn" type="PackedScene" id=4]
[ext_resource path="res://player/Player.tscn" type="PackedScene" id=5]
[node name="Entities" type="Node"]
[resource]
script = ExtResource( 1 )
player_scene = ExtResource( 3 )
player_scene = ExtResource( 5 )
networked_player_scene = ExtResource( 2 )
mob_scene = ExtResource( 4 )
player_display_scene = ExtResource( 5 )
mob_scene = ExtResource( 3 )
player_display_scene = ExtResource( 4 )
spawn_parent_path = "/root/Main"
default_level_override = 0

View File

@ -326,7 +326,6 @@ config/version="0.2"
Logger="*res://autoload/Logger.tscn"
Settings="*res://autoload/SettingsManager.gd"
CursorManager="*res://autoload/CursorManager.tscn"
Entities="*res://autoload/Entities.tscn"
WorldNumbers="*res://autoload/WorldNumbers.tscn"
ThemeAtlas="*res://autoload/ThemeAtlas.tscn"
Server="*res://autoload/Server.tscn"
@ -358,6 +357,7 @@ spells/allow_class_spell_learning=true
spells/allow_class_recipe_learning=true
level/use_class_xp=true
data/ess_resource_db_path="res://data/resource_db.tres"
data/ess_entity_spawner_path="res://player/bs_entity_spawner.tres"
profiles/automatic_save=true
[importer_defaults]

View File

@ -75,7 +75,7 @@ func create() -> void:
var id : int = active.id
var ent : Entity = Entities.spawn_player_for_menu(id, name_line_edit.text, self)
var ent : Entity = ESS.entity_spawner.spawn_player_for_menu(id, name_line_edit.text, self)
if f.open(file_name, File.WRITE) == OK:
f.store_string(to_json(ent.to_dict()))
f.close()

View File

@ -84,7 +84,7 @@ func refresh():
Logger.error("Save corrupted! Not Dict! " + file_name)
continue
var display : Entity = Entities.spawn_display_player(file_name, player_display_container_node.get_path())
var display : Entity = ESS.entity_spawner.spawn_display_player(file_name, player_display_container_node.get_path())
#player_display_container_node.add_child(display)
#display.owner = player_display_container_node
@ -97,7 +97,6 @@ func refresh():
centry.pressed = true
centry.connect("pressed", self, "character_selection_changed")
centry.setup(file_name, display.sentity_name, ESS.get_resource_db().get_entity_data(display.characterclass_id).text_name, display.scharacter_level, display.sclass_level, display)
if first_entry == null:

View File

@ -39,6 +39,9 @@ var current_character_file_name : String = ""
func _ready() -> void:
_loading_screen = get_node(loading_screen_path)
ProfileManager.load()
ESS.load_all()
switch_scene(start_scene)
func switch_scene(scene : int) -> void:

View File

@ -96,7 +96,7 @@ func generate_terrarin(chunk : VoxelChunk, spawn_mobs: bool) -> void:
# chunk.build()
if not Engine.editor_hint and chunk.position_y == 0 and spawn_mobs:
Entities.spawn_mob(1, randi() % 3, Vector3(chunk.position_x * chunk.size_x * chunk.voxel_scale + chunk.size_x / 2,\
ESS.entity_spawner.spawn_mob(1, randi() % 3, Vector3(chunk.position_x * chunk.size_x * chunk.voxel_scale + chunk.size_x / 2,\
(chunk.position_y + 1) * chunk.size_y * chunk.voxel_scale, \
chunk.position_z * chunk.size_z * chunk.voxel_scale + chunk.size_z / 2))

View File

@ -218,7 +218,7 @@ func setup_client_seed(pseed : int) -> void:
func load_character(file_name : String) -> void:
_player_file_name = file_name
_player = Entities.load_player(file_name, Vector3(5, 30, 5), 1) as Entity
_player = ESS.entity_spawner.load_player(file_name, Vector3(5, 30, 5), 1) as Entity
#TODO hack, do this properly
_player.set_physics_process(false)
@ -240,4 +240,4 @@ func save() -> void:
if _player == null or _player_file_name == "":
return
Entities.save_player(_player, _player_file_name)
ESS.get_ess_entity_spawner().save_player(_player, _player_file_name)