Equipment menu

This commit is contained in:
gotfishmakesticks 2024-01-13 10:58:44 +03:00
commit bef15301cb
28 changed files with 809 additions and 48 deletions

View file

@ -2,12 +2,15 @@ extends Node
class_name Game
enum ITEM_TYPE {VALUABLE, WEAPON, MODULE, AMMUNITION}
enum ITEM_TYPE {VALUABLE, WEAPON, HULL, SHIELD, ENGINE, AMMUNITION}
enum AMMO_TYPE {NULL, LASER_ENERGY, ROCKETS}
enum BASE_TYPE {POWER, MINING, FOOD, TRADING, MODULE}
const DEFAULT_ITEM = preload("res://items/test_item.tres")
const DEFAULT_WEAPON = preload("res://scenes/weapons/presets/SingleLaserMk1.tscn")
const DEFAULT_HULL = preload("res://scenes/hulls/starterhull.tscn")
const DEFAULT_ENGINE = preload("res://scenes/engines/starterengine.tscn")
const DEFAULT_SHIELD = preload("res://scenes/shields/startershield.tscn")
const salt = "2ndbeam"
const gameversion = "Ictar 1.1"
@ -40,10 +43,13 @@ static func profile_save(scene : Node) -> void:
'data' : scene.ship.quest.data,
'got_reward' : scene.ship.quest_completed
}
if scene.ship.primary_slot.get_child_count() > 0:
profile.profile_meta['game']['primaryweapon'] = scene.ship.primary_slot.get_child(0).id
if scene.ship.secondary_slot.get_child_count() > 0:
profile.profile_meta['game']['secondaryweapon'] = scene.ship.secondary_slot.get_child(0).id
profile.profile_meta['game']['ship_equipment'] = {
'hull' : scene.ship.hull.id,
'engine' : scene.ship.engine.id,
'shield' : scene.ship.shield.id,
'primary_weapon' : scene.ship.primary_slot.get_child(0).id,
'secondary_weapon' : scene.ship.secondary_slot.get_child(0).id
}
profile_save_from_meta(profile.profile_meta)
## Saves profile with provided profile meta
@ -102,11 +108,10 @@ static func profile_legit_check(profile_meta : Dictionary) -> Dictionary:
static func get_item(id : String) -> Item:
var path_name = id.to_lower().replace(" ", "_")
var path = "res://items/{name}.tres".format({"name": path_name})
var res = load(path)
if res != null:
if FileAccess.file_exists(path):
var res = load(path)
return res.duplicate()
else:
return DEFAULT_ITEM.duplicate()
return DEFAULT_ITEM
## Returns weapon packed scene if it exists or DEFAULT_WEAPON instead
static func get_weapon(id : String) -> PackedScene:
@ -116,3 +121,17 @@ static func get_weapon(id : String) -> PackedScene:
return res
else:
return DEFAULT_WEAPON
static func get_module(id : String, type : String) -> PackedScene:
var path = "res://scenes/{type}s/{name}.tscn".format({"name": id, "type": type})
var res = load(path)
if res != null:
return res
match type:
"hull":
return DEFAULT_HULL
"engine":
return DEFAULT_ENGINE
"shield":
return DEFAULT_SHIELD
return DEFAULT_HULL