Refactoring
This commit is contained in:
84
overworld/Overworld.gd
Normal file
84
overworld/Overworld.gd
Normal file
@@ -0,0 +1,84 @@
|
||||
class_name OverworldSingleton extends Node
|
||||
|
||||
signal mapChanged(map:PackedScene, playerDestinationNodeName:String)
|
||||
|
||||
var newMapPath:String
|
||||
var hasFadedOut:bool = false
|
||||
var playerDestinationNodeName:String
|
||||
var newMapLoaded:bool = false
|
||||
|
||||
func isMapChanging() -> bool:
|
||||
return newMapPath != ""
|
||||
|
||||
func _enter_tree() -> void:
|
||||
pass
|
||||
|
||||
func _exit_tree() -> void:
|
||||
TRANSITION.fadeOutEnd.disconnect(onFadeOutEnd)
|
||||
TRANSITION.fadeInEnd.disconnect(onFadeInEnd)
|
||||
|
||||
func _process(_delta:float) -> void:
|
||||
if(!isMapChanging()):
|
||||
return
|
||||
|
||||
var status = ResourceLoader.load_threaded_get_status(newMapPath)
|
||||
if status == ResourceLoader.THREAD_LOAD_FAILED:
|
||||
push_error("Failed to load map: " + newMapPath)
|
||||
newMapPath = ""
|
||||
|
||||
elif status == ResourceLoader.THREAD_LOAD_INVALID_RESOURCE:
|
||||
push_error("Failed to load map: " + newMapPath)
|
||||
newMapPath = ""
|
||||
|
||||
elif status == ResourceLoader.THREAD_LOAD_IN_PROGRESS:
|
||||
print("Map loading in progress for: " + newMapPath)
|
||||
|
||||
elif status == ResourceLoader.THREAD_LOAD_LOADED:
|
||||
newMapLoaded = true
|
||||
newMapReady()
|
||||
|
||||
|
||||
|
||||
func mapChange(map:String, playerDestinationNodeName:String) -> void:
|
||||
# Begin Loading new map
|
||||
newMapPath = map
|
||||
playerDestinationNodeName = playerDestinationNodeName
|
||||
ResourceLoader.load_threaded_request(newMapPath)
|
||||
|
||||
# Begin fadeout
|
||||
hasFadedOut = false
|
||||
TRANSITION.fade(TransitionSingleton.FadeType.FADE_OUT)
|
||||
TRANSITION.fadeOutEnd.connect(onFadeOutEnd)
|
||||
|
||||
func onFadeOutEnd() -> void:
|
||||
# Fade out has occurred, are we still waiting for the map to load?
|
||||
TRANSITION.fadeOutEnd.disconnect(onFadeOutEnd)
|
||||
hasFadedOut = true
|
||||
|
||||
# Make sure we aren't still waiting for the map to load.
|
||||
if !newMapLoaded:
|
||||
return
|
||||
newMapReady()
|
||||
|
||||
func newMapReady():
|
||||
if !hasFadedOut:
|
||||
return
|
||||
|
||||
# Instantiate the new map
|
||||
var mapResource = ResourceLoader.load_threaded_get(newMapPath)
|
||||
if mapResource == null:
|
||||
push_error("Failed to load map resource: " + newMapPath)
|
||||
return
|
||||
|
||||
# Stop tracking new map name
|
||||
newMapPath = ""
|
||||
|
||||
# Emit event
|
||||
mapChanged.emit(mapResource, playerDestinationNodeName)
|
||||
|
||||
# Begin Fade In
|
||||
TRANSITION.fade(TransitionSingleton.FadeType.FADE_IN)
|
||||
TRANSITION.fadeInEnd.connect(onFadeInEnd)
|
||||
|
||||
func onFadeInEnd() -> void:
|
||||
TRANSITION.fadeInEnd.disconnect(onFadeInEnd)
|
||||
1
overworld/Overworld.gd.uid
Normal file
1
overworld/Overworld.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dqtt405nifbhq
|
||||
@@ -1,4 +1,5 @@
|
||||
class_name Entity extends CharacterBody3D
|
||||
const ConversationElement = preload("res://ConversationElement.gd")
|
||||
|
||||
enum MovementType {
|
||||
NONE,
|
||||
@@ -8,11 +9,15 @@ enum MovementType {
|
||||
|
||||
enum InteractType {
|
||||
NONE,
|
||||
CONVERSATION,
|
||||
};
|
||||
|
||||
|
||||
# Movement settings
|
||||
@export_category("Movement")
|
||||
@export var movementType:MovementType = MovementType.NONE
|
||||
|
||||
# Interaction settings
|
||||
@export var interactType:InteractType = InteractType.NONE
|
||||
@export_category("Interactions")
|
||||
@export var interactType:InteractType = InteractType.NONE
|
||||
@export var conversation:Array[ConversationElement] = []
|
||||
|
||||
1
overworld/entity/EntityConversationElement.gd.uid
Normal file
1
overworld/entity/EntityConversationElement.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://55jotw6snoi
|
||||
@@ -4,13 +4,29 @@ const Entity = preload("res://overworld/entity/Entity.gd")
|
||||
@export var entity:Entity
|
||||
|
||||
func isInteractable() -> bool:
|
||||
return entity && entity.interactType != Entity.InteractType.NONE
|
||||
|
||||
func onInteract() -> void:
|
||||
if !isInteractable():
|
||||
return
|
||||
if !entity:
|
||||
return false
|
||||
|
||||
if entity.interactType == Entity.InteractType.NONE:
|
||||
return
|
||||
return false
|
||||
|
||||
print("Entity Interacted")
|
||||
if entity.interactType == Entity.InteractType.CONVERSATION:
|
||||
if entity.conversation.size() == 0:
|
||||
return false
|
||||
|
||||
return true
|
||||
|
||||
func _onConversationInteract(_other:Entity) -> void:
|
||||
print("Starting conversation with ", entity.name)
|
||||
pass
|
||||
|
||||
func onInteract(other:Entity) -> void:
|
||||
if entity.interactType == Entity.InteractType.NONE:
|
||||
return
|
||||
|
||||
match entity.interactType:
|
||||
Entity.InteractType.CONVERSATION:
|
||||
_onConversationInteract(other)
|
||||
return
|
||||
_:
|
||||
pass
|
||||
@@ -5,11 +5,15 @@ var interactableAreas:Array[EntityInteractableArea] = []
|
||||
@export var entity:Entity
|
||||
|
||||
func hasInteraction() -> bool:
|
||||
return true
|
||||
return interactableAreas.size() > 0
|
||||
|
||||
func interact() -> void:
|
||||
for area in interactableAreas:
|
||||
area.onInteract()
|
||||
if !area.isInteractable():
|
||||
continue
|
||||
|
||||
area.onInteract(self.entity)
|
||||
break
|
||||
|
||||
func _enter_tree() -> void:
|
||||
self.area_entered.connect(_onAreaEntered)
|
||||
@@ -23,11 +27,7 @@ func _onAreaEntered(area:Area3D) -> void:
|
||||
if area is EntityInteractableArea:
|
||||
if area.entity == entity:
|
||||
return
|
||||
if !area.isInteractable():
|
||||
return
|
||||
print("EntityInteractingArea: Area Entered")
|
||||
interactableAreas.append(area)
|
||||
|
||||
func _onAreaExited(area:Area3D) -> void:
|
||||
print("EntityInteractingArea: Area Exited")
|
||||
interactableAreas.erase(area)
|
||||
@@ -1,5 +1,6 @@
|
||||
class_name EntityMovement extends Node
|
||||
|
||||
const GRAVITY = Vector3.DOWN * 100
|
||||
const FRICTION = 0.01
|
||||
const WALK_SPEED_DEFAULT = 8
|
||||
const RUN_SPEED_DEFAULT = 12
|
||||
@@ -18,7 +19,7 @@ const RUN_SPEED_DEFAULT = 12
|
||||
#
|
||||
func _applyGravity() -> void:
|
||||
if !entity.is_on_floor():
|
||||
entity.velocity += PHYSICS.GRAVITY * get_process_delta_time()
|
||||
entity.velocity += GRAVITY * get_process_delta_time()
|
||||
|
||||
func _applyPlayerMovement(_delta:float):
|
||||
if Input.is_action_just_pressed("interact") && interactingArea && interactingArea.hasInteraction():
|
||||
|
||||
@@ -1,14 +1,23 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://d0ywgijpuqy0r"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://d0ywgijpuqy0r"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://xe6pcuq741xi" path="res://overworld/map/TestMap.gd" id="1_6ms5s"]
|
||||
[ext_resource type="PackedScene" uid="uid://cluuhtfjeodwb" path="res://overworld/map/TestMapBase.tscn" id="1_ox0si"]
|
||||
[ext_resource type="PackedScene" uid="uid://by4a0r2hp0w6s" path="res://overworld/entity/Entity.tscn" id="2_jmygs"]
|
||||
[ext_resource type="Script" uid="uid://b40rstjkpompc" path="res://ConversationElement.gd" id="3_p7git"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_p7git"]
|
||||
script = ExtResource("3_p7git")
|
||||
entity = NodePath(".")
|
||||
label = "Hello!"
|
||||
metadata/_custom_type_script = "uid://b40rstjkpompc"
|
||||
|
||||
[node name="TestMap" type="Node3D"]
|
||||
script = ExtResource("1_6ms5s")
|
||||
|
||||
[node name="NotPlayer" parent="." instance=ExtResource("2_jmygs")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00883961, 1.11219, 0.0142021)
|
||||
interactType = 1
|
||||
conversation = Array[ExtResource("3_p7git")]([SubResource("Resource_p7git")])
|
||||
|
||||
[node name="TestMapBase" parent="." instance=ExtResource("1_ox0si")]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user