Reworked entity body setup. Now instead of Entity -> body -> (Sprite, Nameplate etc). It will worki like Body -> (Entity, sprite, Nameplate etc). This fixes y sorting. Nameplates are a bit broken right now, that will be fixed later.

This commit is contained in:
Relintai 2022-03-01 22:00:10 +01:00
parent b549f908bb
commit 1b375d109d
13 changed files with 117 additions and 53 deletions

26
game/Node.tscn Normal file
View File

@ -0,0 +1,26 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://sprites/characters/CharacterSideModel.tscn" type="PackedScene" id=1]
[node name="Node" type="Node"]
[node name="Node2D" type="Node2D" parent="."]
[node name="Camera2D" type="Camera2D" parent="Node2D"]
[node name="YSort" type="YSort" parent="Node2D"]
[node name="Node" type="Node" parent="Node2D/YSort"]
[node name="CharacterSideModel" parent="Node2D/YSort/Node" instance=ExtResource( 1 )]
position = Vector2( -55.7296, -15.6844 )
[node name="Node2" type="Node" parent="Node2D/YSort"]
[node name="CharacterSideModel2" parent="Node2D/YSort/Node2" instance=ExtResource( 1 )]
position = Vector2( -57.0644, -30.7013 )
[node name="Node3" type="Node" parent="Node2D/YSort"]
[node name="CharacterSideModel3" parent="Node2D/YSort/Node3" instance=ExtResource( 1 )]
position = Vector2( -40.7126, -17.6866 )

View File

@ -24,9 +24,9 @@
extends KinematicBody2D
export(float) var MOUSE_SENSITIVITY : float = 0.05
export(String) var world_path : String = "../.."
export(NodePath) var model_path : NodePath = "Rotation_Helper/Model"
export(NodePath) var character_skeleton_path : NodePath = "Character"
export(String) var world_path : String = ".."
#export(NodePath) var model_path : NodePath = "Rotation_Helper/Model"
#export(NodePath) var character_skeleton_path : NodePath = "Character"
const BASE_SPEED = 60.0
@ -91,20 +91,34 @@ func _enter_tree() -> void:
world = get_node(world_path) as Node2D
camera = get_node_or_null("Camera") as Camera2D
character_skeleton = get_node(character_skeleton_path)
entity = get_node("..")
entity.set_character_skeleton(character_skeleton)
#character_skeleton = get_node(character_skeleton_path)
#entity = get_node("..")
#entity.set_character_skeleton(character_skeleton)
# entity.connect("notification_ccast", self, "on_notification_ccast")
entity.connect("diesd", self, "on_diesd")
entity.connect("onc_entity_controller_changed", self, "on_c_controlled_changed")
owner = entity
entity.connect("centity_data_changed", self, "on_centity_data_changed")
on_c_controlled_changed()
transform = entity.get_transform_2d(true)
entity.set_body(self)
set_physics_process(true)
func on_centity_data_changed(entd : EntityData):
if entd.entity_species_data:
var sk : CharacterSkeleton2D = entd.entity_species_data.get_model_data(0).body.instance()
if character_skeleton:
character_skeleton.queue_free()
character_skeleton = sk
entity.set_character_skeleton(character_skeleton)
if character_skeleton:
add_child(character_skeleton)
func _process(delta : float) -> void:
if entity.ai_state == EntityEnums.AI_STATE_OFF:
return
@ -135,6 +149,9 @@ func _physics_process(delta : float) -> void:
if not _on:
return
if !world:
return
if world.initial_generation:
return
@ -184,6 +201,9 @@ func process_input(delta: float) -> void:
var input_length : float = input_dir.length_squared()
if !character_skeleton:
return
if input_length > 0.1:
#handle_graphic_facing(abs(dir.dot(Vector2(0, 1))) > 0.9)
character_skeleton.update_facing(input_dir)
@ -398,9 +418,11 @@ func target(position : Vector2):
if results:
for result in results:
if result.collider and result.collider.owner is Entity:
entity.target_crequest_change((result.collider.owner as Node).get_path())
return
if result.collider:
if result.collider.has_method("get_entity"):
entity.target_crequest_change((result.collider.get_entity() as Node).get_path())
return
entity.target_crequest_change(NodePath())
else:
@ -413,8 +435,8 @@ func cmouseover(event):
if results:
for result in results:
if result.collider and result.collider.owner is Entity:
var mo : Entity = result.collider.owner as Entity
if result.collider and result.collider.has_method("get_entity") :
var mo : Entity = result.collider.get_entity() as Entity
if last_mouse_over != null and last_mouse_over != mo:
if is_instance_valid(last_mouse_over):
@ -501,7 +523,7 @@ func on_c_controlled_changed():
set_process_unhandled_input(false)
var nameplatescn : PackedScene = ResourceLoader.load("res://ui/2d/world/nameplates/NamePlate.tscn")
_nameplate = nameplatescn.instance()
get_parent().add_child(_nameplate)
add_child(_nameplate)
func on_diesd(entity):
if dead:
@ -525,3 +547,5 @@ remote func cset_position(pposition : Vector2) -> void:
pposition = pposition
func get_entity() -> Entity:
return entity

View File

@ -1,7 +1,6 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=3 format=2]
[ext_resource path="res://player/Body.gd" type="Script" id=1]
[ext_resource path="res://sprites/characters/Character.tscn" type="PackedScene" id=2]
[sub_resource type="CircleShape2D" id=1]
radius = 8.0
@ -9,7 +8,5 @@ radius = 8.0
[node name="Body" type="KinematicBody2D"]
script = ExtResource( 1 )
[node name="Character" parent="." instance=ExtResource( 2 )]
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )

View File

@ -1,26 +1,12 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=4 format=2]
[ext_resource path="res://player/DisplayPlayer.gd" type="Script" id=1]
[node name="DisplayPlayer" type="Entity" groups=[
"players",
]]
body_path = NodePath("KinematicBody2D")
character_skeleton_path = NodePath("KinematicBody2D/Rotation_Helper/Model")
[sub_resource type="EntityResourceHealth" id=1]
[sub_resource type="EntityResourceSpeed" id=2]
[node name="DisplayPlayer" type="Entity" groups=["players"]]
sseed = 9240987
cseed = 9240987
sresources = [ SubResource( 1 ), SubResource( 2 ) ]
script = ExtResource( 1 )
[node name="KinematicBody2D" type="KinematicBody2D" parent="."]
[node name="Rotation_Helper" type="Spatial" parent="KinematicBody2D"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.960532, 0 )
__meta__ = {
"_editor_description_": ""
}
[node name="Model" type="Spatial" parent="KinematicBody2D/Rotation_Helper"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.875205, 0 )
__meta__ = {
"_editor_description_": ""
}

View File

@ -20,12 +20,18 @@ extends Control
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
export (String) var player_path : String = "../../.."
export (String) var player_path : String = "../.."
export (Array, NodePath) var child_controls : Array
func _ready() -> void:
if player_path != null:
var player : Entity = get_node(player_path) as Entity
# var player : Entity = get_node(player_path) as Entity
var n : Node = get_node(player_path)
if !n:
return
var player : Entity = n.entity
if (player == null):
print("Player is null!")

View File

@ -53,7 +53,7 @@ func _enter_tree():
health_bar = get_node(health_bar_path) as TextureProgress
health_bar_label = get_node(health_bar_label_path) as Label
entity = get_node("..") as Entity
entity = get_node("..").entity
entity.connect("centity_resource_added", self, "on_centity_resource_added")
name_label.text = entity.centity_name

View File

@ -6,8 +6,6 @@
[sub_resource type="EntityResourceSpeed" id=2]
[node name="Player" type="Entity" groups=[
"players",
]]
[node name="Player" type="Entity" groups=["players"]]
sresources = [ SubResource( 1 ), SubResource( 2 ) ]
script = ExtResource( 2 )

View File

@ -24,6 +24,7 @@ extends ESSEntitySpawner
# SOFTWARE.
export(PackedScene) var player_display_scene : PackedScene
export(PackedScene) var player_body_scene : PackedScene
export(String) var spawn_parent_path : String = "/root/Main"
export(int) var default_level_override : int = 0
@ -242,6 +243,21 @@ func _request_entity_spawn(createinfo : EntityCreateInfo):
if createinfo.entity_player_type == EntityEnums.ENTITY_PLAYER_TYPE_DISPLAY:
entity_node = player_display_scene.instance()
if (createinfo.parent_path == ""):
if _spawn_parent == null:
_spawn_parent = get_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_tree().root.get_node(createinfo.parent_path).add_child(entity_node)
entity_node.setup(createinfo)
createinfo.created_entity = entity_node
return
else:
if not createinfo.networked:
if createinfo.entity_controller == EntityEnums.ENITIY_CONTROLLER_PLAYER:
@ -255,6 +271,11 @@ func _request_entity_spawn(createinfo : EntityCreateInfo):
print("EntityManager: entity node is null")
return null
var body : Node2D = player_body_scene.instance()
body.add_child(entity_node)
body.entity = entity_node
entity_node.set_transform_2d(createinfo.transform2d)
if (createinfo.parent_path == ""):
@ -264,9 +285,9 @@ func _request_entity_spawn(createinfo : EntityCreateInfo):
if _spawn_parent.current_scene != null:
var spawn_parent = _spawn_parent.current_scene
spawn_parent.add_child(entity_node)
spawn_parent.add_child(body)
else:
get_tree().root.get_node(createinfo.parent_path).add_child(entity_node)
get_tree().root.get_node(createinfo.parent_path).add_child(body)
entity_node.setup(createinfo)

View File

@ -1,8 +1,10 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=4 format=2]
[ext_resource path="res://player/bs_entity_spawner.gd" type="Script" id=1]
[ext_resource path="res://player/DisplayPlayer.tscn" type="PackedScene" id=2]
[ext_resource path="res://player/Body.tscn" type="PackedScene" id=3]
[node name="ESSEntitySpawner" type="ESSEntitySpawner"]
script = ExtResource( 1 )
player_display_scene = ExtResource( 2 )
player_body_scene = ExtResource( 3 )

View File

@ -1,6 +1,6 @@
[gd_resource type="EntitySpeciesData" load_steps=3 format=2]
[ext_resource path="res://sprites/entities/Human/Body_2d_old.tscn" type="PackedScene" id=1]
[ext_resource path="res://sprites/characters/Character.tscn" type="PackedScene" id=1]
[sub_resource type="SpeciesModelData" id=1]
bone_structure = 4

View File

@ -39,13 +39,16 @@ func _ready():
if player_path != null:
var player = get_node(player_path)
if !player:
return
for c in windows.get_children():
if c.has_method("set_player"):
c.set_player(player)
c.set_player(player.entity)
for c in gui_base.get_children():
if c.has_method("set_player"):
c.set_player(player)
c.set_player(player.entity)
func initialize():
gui_base = get_node(gui_base_path)

View File

@ -12,6 +12,7 @@
[node name="GUILayer" type="CanvasLayer"]
script = ExtResource( 6 )
player_path = ".."
gui_base_path = NodePath("GUI")
buttons_path = NodePath("GUI/Buttons")
windows_path = NodePath("GUI/Windows")