Singelton patch

This commit is contained in:
2025-05-05 22:21:51 -05:00
parent 43487bb448
commit 631365aa38
46 changed files with 78 additions and 174 deletions

View File

@@ -0,0 +1,9 @@
extends Node
const Battle = preload("res://scripts/Battle/Battle.gd");
var battle:Battle = null;
func startBattle(battle:Battle) -> void:
print("start battle");
self.battle = battle;

View File

@@ -0,0 +1 @@
uid://2ejo2auklqhu

View File

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

View File

@@ -0,0 +1,5 @@
extends Node
const CookingGame = preload("res://scripts/Cooking/CookingGame.gd");
var game:CookingGame = null;

View File

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

View File

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

View File

@@ -0,0 +1,22 @@
extends Node
var currentCutscene:Cutscene = null;
func _process(delta: float) -> void:
if PAUSE.getPauseState() == PAUSE.PauseType.FULLY_PAUSED:
return;
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;
cutscene.cutsceneSystem = self;
currentCutscene.setupCutscene();

View File

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

View File

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

106
scripts/Singletons/Item.gd Normal file
View File

@@ -0,0 +1,106 @@
extends Node
const Item = preload("res://scripts/Item/Item.gd");
const ItemStack = preload("res://scripts/Item/ItemStack.gd");
enum ItemSortType {
NAME,
TYPE
};
class ItemStackNameComparator:
static func _sort(a, b):
return a.item.getName().to_lower() < b.item.getName().to_lower()
class ItemStackTypeComparator:
static func _sort(a, b):
return a.item.getCategory() < b.item.getCategory()
# Constants
const ITEM_STACK_SIZE_MAX = 99;
static var ITEM_POTION = preload("res://scripts/Item/Potion.gd").new();
# Class
var inventory:Array[ItemStack] = [];
# Methods
func addItem(item: Item, quantity: int = 1) -> void:
print("Adding ", quantity, "x ", item.getName());
if !item.isStackable():
# Item cannot be stacked, add each item to inv
for i in range(quantity):
inventory.append(ItemStack.new(item, 1))
return
# Check for existing stacks
for stack in inventory:
if stack.item != item or stack.quantity >= ITEM_STACK_SIZE_MAX:
continue
var spaceAvailable = ITEM_STACK_SIZE_MAX - stack.quantity
if quantity <= spaceAvailable:
stack.quantity += quantity;
return
stack.quantity = ITEM_STACK_SIZE_MAX;
quantity -= spaceAvailable;
# Add any remaining inventory as new stack.
while quantity > 0:
var newStackQuantity = min(quantity, ITEM_STACK_SIZE_MAX);
inventory.append(ItemStack.new(item, newStackQuantity));
quantity -= newStackQuantity;
func removeItem(item: Item, quantity: int) -> void:
var totalQuantity = 0
# Calculate total quantity of the item in the inventory
for stack in inventory:
if stack.item != item:
continue
totalQuantity += stack.quantity
if totalQuantity < quantity:
push_error("Not enough quantity to remove");
return
# Remove the quantity from the stacks
for stack in inventory:
if stack.item != item:
continue
if stack.quantity < quantity:
quantity -= stack.quantity
inventory.erase(stack)
stack.quantity -= quantity
if stack.quantity == 0:
inventory.erase(stack)
if quantity == 0:
return
func removeStack(stack: ItemStack) -> void:
self.removeItem(stack.item, stack.quantity);
func hasItem(item: Item, quantity: int = 1) -> bool:
var totalQuantity = 0
for stack in inventory:
if stack.item != item:
continue
totalQuantity += stack.quantity
if totalQuantity >= quantity:
return true
return false
func sortBy(by:ItemSortType) -> void:
match by:
ItemSortType.NAME:
inventory.sort_custom(ItemStackNameComparator._sort)
ItemSortType.TYPE:
inventory.sort_custom(ItemStackTypeComparator._sort)

View File

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

View File

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

View File

@@ -0,0 +1,13 @@
extends Node
const MAPS:Dictionary[String, String] = {
"TestMap": "res://scenes/Maps/TestMap.tscn"
};
var currentMap:String = "";
func setMap(map:String) -> void:
if MAPS.has(map):
currentMap = map
else:
push_error("Map not found: " + map)

View File

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

View File

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

View File

@@ -0,0 +1,37 @@
class_name PauseSystem extends Node
enum PauseType {
# Completely unpaused
NOT_PAUSED,
# Fully paused, with no exceptions to anything
FULLY_PAUSED,
# Specific entities are paused
ENTITY_PAUSED,
# All entities are paused unless specified
CUTSCENE_PAUSED
};
var pauseType:PauseType = PauseType.NOT_PAUSED;
var entities:Array = [];
var playerPaused:bool = false;
func getPauseState() -> PauseType:
if isPlayerPaused():
return PauseType.FULLY_PAUSED;
return pauseType;
func pause(
pauseType:PauseType,
entities:Array = [],
) -> void:
self.pauseType = pauseType;
self.entities = entities;
func unpause() -> void:
self.pauseType = PauseType.NOT_PAUSED;
func isPlayerPaused() -> bool:
return playerPaused;
func playerPauseToggle() -> void:
playerPaused = !playerPaused;

View File

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

View File

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

View File

@@ -0,0 +1,7 @@
class_name QuestSystem extends Node
static var QUEST_EXAMPLE = preload("res://scripts/Quest/QuestExample.gd").new();
static var ALL_QUESTS = [
QUEST_EXAMPLE
]

View File

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

View File

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

View File

@@ -0,0 +1,52 @@
extends Node
const MainMenu = preload("res://scenes/MainMenu.tscn");
const OverworldScene = preload("res://scenes/Meta/Overworld.tscn");
enum DawnScene {
INITIAL,
MAIN_MENU,
OVERWORLD,
BATTLE,
COOKING
};
# static const SCENES:Dictionary[String, PackedScene] = {
# "MainMenu": MainMenu,
# "Overworld": OverworldScene
# };
var scene:DawnScene = DawnScene.INITIAL;
func getMainMenuScene():
return get_tree().current_scene.get_node("MainMenu");
func setScene(newScene:DawnScene) -> void:
print("Setting scene to " + str(newScene));
scene = newScene;
if newScene == DawnScene.MAIN_MENU:
# Remove all non essential scenes
# Add Main menu scene if not present
var mainMenu = getMainMenuScene();
if mainMenu == null:
var instance = MainMenu.instantiate(PackedScene.GEN_EDIT_STATE_DISABLED);
get_tree().current_scene.add_child(instance);
return
if newScene == DawnScene.OVERWORLD:
# Remove all non essential scenes
var mainMenuScene = getMainMenuScene();
if mainMenuScene != null:
mainMenuScene.queue_free();
# Add Overworld scene if not present
var overworld = get_tree().current_scene.get_node("OverworldScene");
if overworld == null:
var instance = OverworldScene.instantiate(PackedScene.GEN_EDIT_STATE_DISABLED);
get_tree().current_scene.add_child(instance);
return
# error
print("Scene not found: " + str(newScene));

View File

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

View File

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

View File

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

6
scripts/Singletons/VN.gd Normal file
View File

@@ -0,0 +1,6 @@
class_name VNSystem extends Node
const VNTextbox = preload("res://scripts/UI/VNTextbox.gd")
func getTextbox() -> VNTextbox:
return null
# return get_tree().current_scene.get_node("UI/VNTextbox") as VNTextbox;

View File

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

View File

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