added first theme progress and switched all files to use static typing

This commit is contained in:
Luca 2024-10-10 15:26:56 +02:00
parent c9458f3627
commit b5ace17da9
2665 changed files with 50249 additions and 476 deletions

View file

@ -1,6 +1,7 @@
class_name MonsterData
extends Resource
@warning_ignore("unused_signal")
signal on_level_up
@export var unique_id : String = ""
@ -31,14 +32,14 @@ signal on_level_up
# The ID is the filename of the monster from res://entities/monsters/<filename>.tres
func set_values(p_unique_id = "", current_values: Dictionary = {}, p_level: int = 1) -> void:
func set_values(p_unique_id : String = "", current_values: Dictionary = {}, p_level: int = 1) -> void:
if p_unique_id.is_empty():
printerr("Monster.gd: No ID given")
return
# Get an instance of the base monster data
var base_monster = Utils.load_base_monster_data(p_unique_id)
var base_monster: MonsterData = Utils.load_base_monster_data(p_unique_id)
# Set the values
self.name = base_monster.name
self.description = base_monster.description
@ -46,22 +47,22 @@ func set_values(p_unique_id = "", current_values: Dictionary = {}, p_level: int
self.model = base_monster.model
self.primary_type = base_monster.primary_type
self.secondary_type = base_monster.secondary_type
# Set base values
self.base_attack = base_monster.base_attack
self.base_health = base_monster.base_health
self.base_defense = base_monster.base_defense
self.base_tempo = base_monster.base_tempo
self.base_xp = base_monster.base_xp
set_level(p_level)
# If there are not values to edit, return
if current_values.is_empty():
return
# else, set custom values here
for key in current_values:
for key: String in current_values:
self[key] = current_values[key]
## This sets the monster to the specified level
@ -71,10 +72,10 @@ func set_level(p_level: int) -> void:
# Updates the values according to the current level of the monster
func update() -> void:
self.attack = int((((base_attack * 2) * level ) / 100) + (level + 5))
self.health = int((((base_health * 2) * level ) / 100) + (level + 5))
self.defense = int((((base_defense * 2) * level ) / 100) + (level + 5))
self.tempo = int((((base_tempo * 2) * level ) / 100) + (level + 5))
self.attack = int((((base_attack * 2.0) * level ) / 100) + (level + 5))
self.health = int((((base_health * 2.0) * level ) / 100) + (level + 5))
self.defense = int((((base_defense * 2.0) * level ) / 100) + (level + 5))
self.tempo = int((((base_tempo * 2.0) * level ) / 100) + (level + 5))
self.xp_for_levelup = int(pow(level + 1, 3))
func level_up() -> void:
@ -83,7 +84,7 @@ func level_up() -> void:
func calculate_gained_xp(enemy_data: MonsterData) -> int:
var calculated_xp: int = 0
calculated_xp = int( (enemy_data.base_xp * enemy_data.level / 5) * ( float(enemy_data.level) / float(level) ) )
calculated_xp = int( (enemy_data.base_xp * enemy_data.level / 5.0) * ( float(enemy_data.level) / float(level) ) )
return calculated_xp
func add_xp(amount: int = 0) -> void:
@ -94,10 +95,10 @@ func add_xp(amount: int = 0) -> void:
func attack_enemy(enemy_data: MonsterData) -> int:
var damage: int = 0
var base_damage: int = 2
damage = floor(floor((level * 2/5 + 2)) * base_damage * (float(attack) / (2 * enemy_data.defense)) + 2)
damage = floor(floor((level * 2.0/5 + 2)) * base_damage * (float(attack) / (2 * enemy_data.defense)) + 2)
enemy_data.take_damage(damage)
return damage
func take_damage(amount: int) -> void:

View file

@ -5,65 +5,65 @@ extends Node
# Reference to the currently loaded save game
@onready var current_save : SavedGame = SavedGame.new()
var world
var world: Node3D
func save_game():
func save_game() -> void:
# Create a new empty save game
var saved_game := SavedGame.new()
var saved_game: SavedGame = SavedGame.new()
# Save the environment data
saved_game.world = SceneManager.get_world()
saved_game.daytime = 12.5
saved_game.weather = "this should be an enum"
# Save the party data
for monster in SaveManager.current_save.party:
for monster: MonsterData in SaveManager.current_save.party:
saved_game.party.append(monster)
# Create an array to store the data of all other nodes
var saved_data : Array[SavedData] = []
# Use a group call to collect all the data from the other objects
get_tree().call_group("save_nodes", "on_save_game", saved_data)
# Store the array in the saved game
saved_game.saved_data = saved_data
# Store it into a file
ResourceSaver.save(saved_game, "user://savegame.tres")
func load_game():
func load_game() -> void:
# Load the saved game file
var saved_game : SavedGame = load("user://savegame.tres") as SavedGame
# Return if no save file is found
if saved_game == null:
print("No savegame found.")
return
# Save a reference to the current save game
current_save = saved_game
# Clean up all non-static objects from the scene
get_tree().call_group("save_nodes", "on_before_load_game")
# Restore world data
SceneManager.set_world(saved_game.world)
# Restore all other nodes
for node in saved_game.saved_data:
for node: SavedData in saved_game.saved_data:
# Instantiate the scene for the node
var scene := load(node.scene_path) as PackedScene
var restored_node = scene.instantiate()
var scene: PackedScene = load(node.scene_path) as PackedScene
var restored_node: Node = scene.instantiate()
# Add the item to the world
# todo: add parent as value to save and restore to the parent
SceneManager.current_world.add_child(restored_node)
# run a callback to restore the item's state
if restored_node.has_method("on_load_game"):
restored_node.on_load_game(node)
func save_exists():
func save_exists() -> bool:
return FileAccess.file_exists("user://savegame.tres")