Basic events system started.

This commit is contained in:
2025-05-06 11:07:16 -05:00
parent 4ad63b8c41
commit b9f0295722
22 changed files with 325 additions and 103 deletions

View File

@@ -87,6 +87,11 @@ debug={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194306,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194306,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
] ]
} }
run={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
[rendering] [rendering]

View File

@@ -1,8 +1,7 @@
[gd_scene load_steps=8 format=3 uid="uid://dr4b2pmsknuhc"] [gd_scene load_steps=7 format=3 uid="uid://dr4b2pmsknuhc"]
[ext_resource type="Script" uid="uid://d23qg1ovkbxst" path="res://scripts/Entities/BasicNPCEntity.gd" id="1_1muh7"] [ext_resource type="Script" uid="uid://d23qg1ovkbxst" path="res://scripts/Entities/BasicNPCEntity.gd" id="1_1muh7"]
[ext_resource type="Shader" uid="uid://7h2axb2tsh17" path="res://shaders/NPC Shader.gdshader" id="1_xgcv1"] [ext_resource type="Shader" uid="uid://7h2axb2tsh17" path="res://shaders/NPC Shader.gdshader" id="1_xgcv1"]
[ext_resource type="Script" uid="uid://btxgv85qst1jy" path="res://scripts/Cutscene/TestCutscene.gd" id="2_jwvuu"]
[ext_resource type="Texture2D" uid="uid://cofrgefp8e617" path="res://textures/human.png" id="4_vo0ku"] [ext_resource type="Texture2D" uid="uid://cofrgefp8e617" path="res://textures/human.png" id="4_vo0ku"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_dw1sy"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_dw1sy"]
@@ -21,7 +20,6 @@ shader_parameter/direction = 1
[node name="TestNpc" type="CharacterBody3D"] [node name="TestNpc" type="CharacterBody3D"]
script = ExtResource("1_1muh7") script = ExtResource("1_1muh7")
interactCutscene = ExtResource("2_jwvuu")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."] [node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("CapsuleShape3D_dw1sy") shape = SubResource("CapsuleShape3D_dw1sy")

View File

@@ -1,68 +0,0 @@
[gd_scene load_steps=11 format=3 uid="uid://dx6fv8n4jl5ku"]
[ext_resource type="PackedScene" uid="uid://yhtpoum3eek7" path="res://scenes/Entities/Rosa.tscn" id="2_2h4bv"]
[ext_resource type="Shader" uid="uid://67hsyo0qqlfm" path="res://shaders/Map Shader.gdshader" id="3_7avga"]
[ext_resource type="PackedScene" uid="uid://dr4b2pmsknuhc" path="res://scenes/Entities/TestNPC.tscn" id="3_q0pj2"]
[ext_resource type="Texture2D" uid="uid://cu1hvpqmqn31n" path="res://icon.svg" id="4_qs7p7"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_e1h75"]
sky_horizon_color = Color(0.59625, 0.6135, 0.6375, 1)
sky_energy_multiplier = 0.0
ground_bottom_color = Color(0, 0, 0, 1)
ground_horizon_color = Color(0.59625, 0.6135, 0.6375, 1)
[sub_resource type="Sky" id="Sky_weucl"]
sky_material = SubResource("ProceduralSkyMaterial_e1h75")
[sub_resource type="Environment" id="Environment_nyivo"]
sky = SubResource("Sky_weucl")
ambient_light_source = 1
[sub_resource type="BoxMesh" id="BoxMesh_s8iqe"]
lightmap_size_hint = Vector2i(504, 257)
uv2_padding = 0.0
size = Vector3(50, 0.1, 50)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_s8iqe"]
render_priority = 0
shader = ExtResource("3_7avga")
shader_parameter/tileset = ExtResource("4_qs7p7")
[sub_resource type="BoxShape3D" id="BoxShape3D_s8iqe"]
size = Vector3(50, 0.1, 50)
[node name="Some-map" type="Node3D"]
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_nyivo")
[node name="Rosa" parent="." instance=ExtResource("2_2h4bv")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.19857, 0.684572, 0.968477)
[node name="TestNpc" parent="." instance=ExtResource("3_q0pj2")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.68747, 0.459578, -0.399262)
interactType = 1
moveType = 1
direction = 1
[node name="OmniLight3D" type="OmniLight3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 4.28892, 0)
light_energy = 3.375
shadow_bias = 0.0
shadow_normal_bias = 0.9
omni_range = 281.646
[node name="Map" type="Node3D" parent="."]
metadata/_edit_lock_ = true
[node name="Ground" type="StaticBody3D" parent="Map"]
metadata/_edit_lock_ = true
[node name="MeshInstance3D" type="MeshInstance3D" parent="Map/Ground"]
mesh = SubResource("BoxMesh_s8iqe")
surface_material_override/0 = SubResource("ShaderMaterial_s8iqe")
metadata/_edit_lock_ = true
[node name="CollisionShape3D" type="CollisionShape3D" parent="Map/Ground"]
shape = SubResource("BoxShape3D_s8iqe")
metadata/_edit_lock_ = true

View File

@@ -0,0 +1,74 @@
[gd_scene load_steps=11 format=3 uid="uid://dx6fv8n4jl5ku"]
[ext_resource type="PackedScene" uid="uid://yhtpoum3eek7" path="res://scenes/Entities/Rosa.tscn" id="1_7b7hx"]
[ext_resource type="PackedScene" uid="uid://dr4b2pmsknuhc" path="res://scenes/Entities/TestNPC.tscn" id="2_cg1ph"]
[ext_resource type="PackedScene" uid="uid://lh713g04d3bg" path="res://scenes/Maps/TestMap/TestMapGround.tscn" id="3_gxq5o"]
[ext_resource type="PackedScene" uid="uid://boj5o4fx41rv8" path="res://scenes/Maps/TestMap/TestMapBuilding.tscn" id="4_brp0k"]
[ext_resource type="Script" path="res://scripts/Events/EventTextbox.gd" id="5_cg1ph"]
[ext_resource type="Script" uid="uid://sqi2ehu4sqa1" path="res://scripts/Events/EventGroup.gd" id="5_gxq5o"]
[ext_resource type="Script" uid="uid://bv36suxm08vqe" path="res://scripts/Events/EventPause.gd" id="6_brp0k"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_e1h75"]
sky_horizon_color = Color(0.59625, 0.6135, 0.6375, 1)
sky_energy_multiplier = 0.0
ground_bottom_color = Color(0, 0, 0, 1)
ground_horizon_color = Color(0.59625, 0.6135, 0.6375, 1)
[sub_resource type="Sky" id="Sky_weucl"]
sky_material = SubResource("ProceduralSkyMaterial_e1h75")
[sub_resource type="Environment" id="Environment_nyivo"]
sky = SubResource("Sky_weucl")
ambient_light_source = 1
[node name="Some-map" type="Node3D"]
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_nyivo")
[node name="Rosa" parent="." instance=ExtResource("1_7b7hx")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.19857, 0.684572, 0.968477)
[node name="Green" parent="." node_paths=PackedStringArray("interactEvent") instance=ExtResource("2_cg1ph")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.68747, 0.459578, -0.399262)
interactEvent = NodePath("../Events/TestGroup")
moveType = 1
direction = 1
[node name="OmniLight3D" type="OmniLight3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 7.20244, 3.80554)
light_energy = 3.375
shadow_bias = 0.0
shadow_normal_bias = 0.9
omni_range = 281.646
[node name="Map" type="Node3D" parent="."]
metadata/_edit_lock_ = true
[node name="Ground" parent="Map" instance=ExtResource("3_gxq5o")]
[node name="Building2" parent="Map" instance=ExtResource("4_brp0k")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8.13514, 2.62692, -0.0984068)
[node name="Building" parent="Map" instance=ExtResource("4_brp0k")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.92766, 2.37929, -4.38178)
[node name="Events" type="Node" parent="."]
[node name="TestGroup" type="Node" parent="Events"]
script = ExtResource("5_gxq5o")
[node name="Pause" type="Node" parent="Events/TestGroup"]
script = ExtResource("6_brp0k")
[node name="Text 0" type="Node" parent="Events/TestGroup"]
script = ExtResource("5_cg1ph")
text = "Text 0"
[node name="Text 1" type="Node" parent="Events/TestGroup"]
script = ExtResource("5_cg1ph")
text = "Text 1"
[node name="Resume" type="Node" parent="Events/TestGroup"]
script = ExtResource("6_brp0k")
pauseType = 0

View File

@@ -0,0 +1,15 @@
[gd_scene load_steps=3 format=3 uid="uid://boj5o4fx41rv8"]
[sub_resource type="BoxMesh" id="BoxMesh_22rim"]
size = Vector3(5, 5, 5)
[sub_resource type="BoxShape3D" id="BoxShape3D_jh0ui"]
size = Vector3(5, 5, 5)
[node name="Building" type="StaticBody3D"]
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
mesh = SubResource("BoxMesh_22rim")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("BoxShape3D_jh0ui")

View File

@@ -0,0 +1,29 @@
[gd_scene load_steps=6 format=3 uid="uid://lh713g04d3bg"]
[ext_resource type="Shader" uid="uid://67hsyo0qqlfm" path="res://shaders/Map Shader.gdshader" id="1_knx2j"]
[ext_resource type="Texture2D" uid="uid://cu1hvpqmqn31n" path="res://icon.svg" id="2_3bnhs"]
[sub_resource type="BoxMesh" id="BoxMesh_s8iqe"]
lightmap_size_hint = Vector2i(504, 257)
uv2_padding = 0.0
size = Vector3(50, 0.1, 50)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_s8iqe"]
render_priority = 0
shader = ExtResource("1_knx2j")
shader_parameter/tileset = ExtResource("2_3bnhs")
[sub_resource type="BoxShape3D" id="BoxShape3D_s8iqe"]
size = Vector3(50, 0.1, 50)
[node name="Ground" type="StaticBody3D"]
metadata/_edit_lock_ = true
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
mesh = SubResource("BoxMesh_s8iqe")
surface_material_override/0 = SubResource("ShaderMaterial_s8iqe")
metadata/_edit_lock_ = true
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("BoxShape3D_s8iqe")
metadata/_edit_lock_ = true

View File

@@ -1,7 +1,7 @@
[gd_scene load_steps=3 format=3 uid="uid://tmbx2kit0jyq"] [gd_scene load_steps=3 format=3 uid="uid://tmbx2kit0jyq"]
[ext_resource type="Script" uid="uid://pcncoc6wum4q" path="res://scripts/Scenes/OverworldScene.gd" id="1_rfscu"] [ext_resource type="Script" uid="uid://pcncoc6wum4q" path="res://scripts/Scenes/OverworldScene.gd" id="1_rfscu"]
[ext_resource type="PackedScene" uid="uid://dx6fv8n4jl5ku" path="res://scenes/Maps/TestMap.tscn" id="2_puia7"] [ext_resource type="PackedScene" uid="uid://dx6fv8n4jl5ku" path="res://scenes/Maps/TestMap/TestMap.tscn" id="2_puia7"]
[node name="Overworld" type="Node3D"] [node name="Overworld" type="Node3D"]
script = ExtResource("1_rfscu") script = ExtResource("1_rfscu")

View File

@@ -1,21 +1,12 @@
class_name BasicNPCEntity extends "res://scripts/Entities/OverworldEntity.gd" class_name BasicNPCEntity extends "res://scripts/Entities/OverworldEntity.gd"
const Cutscene = preload("res://scripts/Cutscene/Cutscene.gd"); const Event = preload("res://scripts/Events/Event.gd");
const OverworldConversationEvent = preload("res://scripts/Cutscene/Scene/OverworldConversationEvent.gd");
enum BasicNPCInteractType {
NONE,
CUTSCENE,
TEXTS
};
enum BasicNPCMoveType { enum BasicNPCMoveType {
STILL, STILL,
RANDOM_LOOK RANDOM_LOOK
}; };
@export var interactType:BasicNPCInteractType = BasicNPCInteractType.NONE; @export var interactEvent:Event;
@export var interactCutscene:GDScript;
@export var interactTexts:Array[String];
@export var moveType:BasicNPCMoveType = BasicNPCMoveType.STILL; @export var moveType:BasicNPCMoveType = BasicNPCMoveType.STILL;
@@ -24,22 +15,10 @@ enum BasicNPCMoveType {
var randomLookTimer:float = 0.0; var randomLookTimer:float = 0.0;
func interact(interactor:OverworldEntity) -> void: func interact(interactor:OverworldEntity) -> void:
if interactType == BasicNPCInteractType.NONE: if interactEvent == null:
push_error("BasicNPCEntity: interactType EVENT but no event set");
return return
interactEvent.onEntityInteract(interactor, self);
if interactType == BasicNPCInteractType.CUTSCENE:
# Cutscene in this manner must take two entities
# (self, speaker, and interactor, player)
var cs:Cutscene = interactCutscene.new(self, interactor);
CUTSCENE.setCurrentCutscene(cs);
return
if interactType == BasicNPCInteractType.TEXTS:
var cs:Cutscene = OverworldConversationEvent.new(self, interactor, interactTexts);
CUTSCENE.setCurrentCutscene(cs);
return
pass
func updateMovement(delta:float) -> void: func updateMovement(delta:float) -> void:
if moveType == BasicNPCMoveType.STILL: if moveType == BasicNPCMoveType.STILL:

View File

@@ -7,7 +7,8 @@ enum Direction {
EAST, EAST,
} }
var speed:float = 150; var speed:float = 200;
var runSpeed:float = 400;
var friction:float = 8.5; var friction:float = 8.5;
var gravity:float = 30; var gravity:float = 30;

View File

@@ -1,6 +1,6 @@
extends Camera3D extends Camera3D
const PIXEL_SCALE:float = 4.0; const PIXEL_SCALE:float = 2.0;
const WORLD_UNITS:float = 32.0; const WORLD_UNITS:float = 32.0;
func _ready() -> void: func _ready() -> void:

View File

@@ -27,9 +27,16 @@ func updateOverworldLogic(delta) -> void:
func updateMovement(delta) -> void: func updateMovement(delta) -> void:
# User movement # User movement
var dir:Vector2 = Input.get_vector("left", "right", "up", "down"); var dir:Vector2 = Input.get_vector("left", "right", "up", "down");
var moveSpeed:float;
if Input.is_action_pressed("run"):
moveSpeed = runSpeed;
else:
moveSpeed = speed;
if(dir.x != 0 or dir.y != 0): if(dir.x != 0 or dir.y != 0):
velocity.x = dir.x * speed * delta; velocity.x = dir.x * moveSpeed * delta;
velocity.z = dir.y * speed * delta; velocity.z = dir.y * moveSpeed * delta;
# Update direction # Update direction
if(dir.x >= abs(dir.y) and( if(dir.x >= abs(dir.y) and(
@@ -48,4 +55,3 @@ func updateMovement(delta) -> void:
direction = Direction.SOUTH; direction = Direction.SOUTH;
elif (dir.y < 0): elif (dir.y < 0):
direction = Direction.NORTH; direction = Direction.NORTH;
pass

52
scripts/Events/Event.gd Normal file
View File

@@ -0,0 +1,52 @@
class_name Event extends Node
const OverworldEntity = preload("res://scripts/Entities/OverworldEntity.gd");
var started:bool = false;
var ended:bool = false;
var interactor:OverworldEntity = null
var interactee:OverworldEntity = null
# Godot Methods
func _init() -> void:
pass
func _process(delta: float) -> void:
if !started || ended:
return
self.update(delta)
if self.isDone():
self.end()
# Event methods (cleaned up)
func start() -> void:
assert(started == false)
started = true
func update(delta:float) -> void:
assert(started == true)
assert(ended == false)
func isDone() -> bool:
return true
func end() -> void:
assert(ended == false)
ended = true
func reset() -> void:
started = false
ended = false
interactor = null
interactee = null
func onEntityInteract(
interactor:OverworldEntity,
interactee:OverworldEntity
) -> void:
self.reset()
self.interactor = interactor
self.interactee = interactee
self.start()

View File

@@ -0,0 +1 @@
uid://cl3vqv8bwyoeu

View File

@@ -0,0 +1 @@
uid://tkfc88q8m86f

View File

@@ -0,0 +1,76 @@
class_name EventGroup extends "res://scripts/Events/EventWithChildren.gd"
enum ProcessType {
SEQUENTIAL,
PARALLEL,
}
@export var processType:ProcessType = ProcessType.SEQUENTIAL;
var childIndex:int = 0
func start() -> void:
super.start()
# If sequential, start first child
if processType == ProcessType.SEQUENTIAL:
childIndex = -1
nextChild()
# If parallel, start all children
elif processType == ProcessType.PARALLEL:
for child in childEvents:
startChild(child)
func update(delta:float) -> void:
super.update(delta)
# If sequential, see if the current child is done, if so go to next child
if processType == ProcessType.SEQUENTIAL:
if childIndex < 0 || childIndex >= childEvents.size():
return
if childEvents[childIndex].isDone():
nextChild()
func nextChild() -> void:
childIndex += 1
if childIndex >= childEvents.size():
return
startChild(childEvents[childIndex])
func isDone() -> bool:
if !super.isDone():
return false
# If sequential, check if we've reached the end of the children
if processType == ProcessType.SEQUENTIAL:
return childIndex >= childEvents.size()
# If parallel, check if all children are done
elif processType == ProcessType.PARALLEL:
for child in childEvents:
if !child.isDone():
return false
return true
return false
func end() -> void:
super.end()
for child in childEvents:
if child.ended || !child.started:
continue
child.end()
func reset() -> void:
super.reset()
childIndex = -1
for child in childEvents:
child.reset()
func startChild(child:Event) -> void:
# Inherits some properties from this event.
child.interactee = self.interactee
child.interactor = self.interactor
child.start()

View File

@@ -0,0 +1 @@
uid://sqi2ehu4sqa1

View File

@@ -0,0 +1,16 @@
class_name EventPause extends "res://scripts/Events/Event.gd"
const PauseSystem = preload("res://scripts/Singletons/Pause.gd")
@export var pauseType:PauseSystem.PauseType = PauseSystem.PauseType.ENTITY_PAUSED
@export var entities:Array[OverworldEntity] = []
@export var includeInteractee:bool = true
@export var includeInteractor:bool = true
func start() -> void:
var ents:Array[OverworldEntity] = entities
if interactor != null and includeInteractor:
ents.append(interactor)
if interactee != null and includeInteractee:
ents.append(interactee)
PAUSE.pause(pauseType, ents)

View File

@@ -0,0 +1 @@
uid://bv36suxm08vqe

View File

@@ -0,0 +1,11 @@
class_name EventTextbox extends "res://scripts/Events/Event.gd"
# @export var text:Array[String] = [ "Hello Text" ];
@export var text:String = "Hello Text"
func start() -> void:
super.start()
VN.getTextbox().setText(self.text);
func isDone() -> bool:
return super.isDone() && VN.getTextbox().isClosed;

View File

@@ -0,0 +1 @@
uid://y7ckj1tn5cro

View File

@@ -0,0 +1,22 @@
class_name EventWithChildren extends "res://scripts/Events/Event.gd"
var childEvents:Array[Event] = []
func _init() -> void:
super._init()
_updateChildEvents()
_updateChildEvents()
self.child_entered_tree.connect(onChildEntered)
self.child_exiting_tree.connect(onChildExited)
func _updateChildEvents() -> void:
childEvents = []
for child in get_children():
if child is Event:
childEvents.append(child)
func onChildEntered(child:Node) -> void:
_updateChildEvents()
func onChildExited(child:Node) -> void:
_updateChildEvents()

View File

@@ -0,0 +1 @@
uid://dj5wl682sbohc