Started cutscene system

This commit is contained in:
2025-01-05 15:30:00 -06:00
parent e74878eb80
commit 0554f5719d
11 changed files with 135 additions and 7 deletions

View File

@@ -0,0 +1,39 @@
class_name Cutscene
const CutsceneEvent = preload("res://scripts/Cutscene/CutsceneEvent.gd");
var queue:Array[CutsceneEvent] = [];
func setupCutscene() -> void:
print_debug("Cutscene setup has not been overriden");
pass
func update(delta:float) -> void:
if queue.size() == 0:
return
var item = queue[0]
if !item.started:
item.start()
item.started = true
item.update(delta)
if item.isDone():
item.end()
queue.erase(item)
pass
func add(items:Array[CutsceneEvent]) -> void:
queue.append_array(items)
func clear() -> void:
if queue.size() == 0:
return
var item = queue[0]
if item.started:
item.end()
item.started = false
queue.clear()

View File

@@ -0,0 +1,18 @@
class_name CutsceneEvent
var started:bool = false;
func _init() -> void:
pass
func start() -> void:
pass
func update(delta:float) -> void:
pass
func isDone() -> bool:
return true
func end() -> void:
pass

View File

@@ -0,0 +1,9 @@
class_name CutscenePrintEvent extends "res://scripts/Cutscene/CutsceneEvent.gd"
var text:String = ""
func _init(text:String) -> void:
self.text = text
func start() -> void:
print(self.text)

View File

@@ -0,0 +1,12 @@
class_name CutsceneWaitEvent extends "res://scripts/Cutscene/CutsceneEvent.gd"
var wait:float = 0.0
func _init(wait:float) -> void:
self.wait = wait
func update(delta:float) -> void:
self.wait -= delta
func isDone() -> bool:
return self.wait <= 0.0

View File

@@ -0,0 +1,10 @@
class_name TestCutscene extends "res://scripts/Cutscene/Cutscene.gd"
const CutscenePrintEvent = preload("res://scripts/Cutscene/Event/CutscenePrintEvent.gd");
const CutsceneWaitEvent = preload("res://scripts/Cutscene/Event/CutsceneWaitEvent.gd");
func setupCutscene() -> void:
add([
CutsceneWaitEvent.new(4.0),
CutscenePrintEvent.new("Hello, World!")
]);
pass

View File

@@ -1,8 +1,10 @@
class_name TestNPCController extends "res://scripts/Entities/OverworldEntity.gd"
const TestCutscene = preload("res://scripts/Cutscene/TestCutscene.gd")
func interact(interactor) -> void:
var systems = getSystems();
systems.ITEM.addItem(systems.ITEM.ITEM_POTION, 1);
systems.CUTSCENE.setCurrentCutscene(TestCutscene.new())
#systems.ITEM.addItem(systems.ITEM.ITEM_POTION, 1);
#var itemSystem = (get_node("Systems") as Systems).ITEM;
#itemSystem.addItem(itemSystem.ITEM_POTION, 1);
#pass

View File

@@ -0,0 +1,19 @@
class_name CutsceneSystem extends Node
const Cutscene = preload("res://scripts/Cutscene/Cutscene.gd");
var currentCutscene:Cutscene = null;
func _process(delta: float) -> void:
if currentCutscene != null:
currentCutscene.update(delta);
func _exit_tree() -> void:
if currentCutscene != null:
currentCutscene.clear();
func setCurrentCutscene(cutscene:Cutscene) -> void:
if currentCutscene != null:
currentCutscene.clear();
currentCutscene = cutscene;
currentCutscene.setupCutscene();

View File

@@ -1,4 +1,4 @@
class_name ItemSystem
class_name ItemSystem extends Node
const Item = preload("res://scripts/Items/Item.gd");
const ItemStack = preload("res://scripts/Items/ItemStack.gd");
@@ -17,7 +17,7 @@ class ItemStackTypeComparator:
# Constants
const ITEM_STACK_SIZE_MAX = 99;
var ITEM_POTION = preload("res://scripts/Items/Potion.gd").new()
var ITEM_POTION = preload("res://scripts/Items/Potion.gd").new();
var inventory:Array[ItemStack] = [];
# Methods

View File

@@ -1,3 +1,14 @@
class_name Systems extends Node
const ItemSystem = preload("res://scripts/Systems/ItemSystem.gd");
const CutsceneSystem = preload("res://scripts/Systems/CutsceneSystem.gd")
var ITEM = preload("res://scripts/Systems/ItemSystem.gd").new()
var ITEM:ItemSystem;
var CUTSCENE:CutsceneSystem;
func _ready():
ITEM = $Item;
CUTSCENE = $Cutscene;
pass
func _process(delta):
pass