mirror of
https://port.numenaute.org/aleajactaest/khanat-client.git
synced 2024-12-21 08:58:44 +00:00
308 lines
11 KiB
GDScript3
308 lines
11 KiB
GDScript3
|
tool
|
||
|
extends Node
|
||
|
|
||
|
var JSONBeautifier = preload( "res://ressources/scripts/json_beautifier/json_beautifier.gd" )
|
||
|
|
||
|
class Data:
|
||
|
var datas = {}
|
||
|
|
||
|
func _init( p_name = null ):
|
||
|
self.set_data( "name", p_name )
|
||
|
|
||
|
func get_data( p_key, p_default_value = null ):
|
||
|
return self.datas.get( p_key, p_default_value )
|
||
|
|
||
|
func set_data( p_key, p_value ):
|
||
|
self.datas[ p_key ] = p_value
|
||
|
|
||
|
func get_filename():
|
||
|
if not self.get_data( "name", null ):
|
||
|
return "unknow.data"
|
||
|
if self.get_data( "name" ).get_extension():
|
||
|
return self.get_data( "name" )
|
||
|
return self.get_data( "name" ) + ".data"
|
||
|
|
||
|
func save( p_emplacement = "res"):
|
||
|
var filename = self.get_filename()
|
||
|
var ext = filename.get_extension()
|
||
|
var file = File.new()
|
||
|
|
||
|
if p_emplacement == "res":
|
||
|
if file.open("res://ressources/files/"+ext+"s/"+filename, File.WRITE) == OK:
|
||
|
file.store_line( JSONBeautifier.beautify_json( to_json(self.datas), 4 ) )
|
||
|
file.close()
|
||
|
elif p_emplacement == "user":
|
||
|
var dir = Directory.new()
|
||
|
if not dir.dir_exists( "user://saves/save_temp/ressources/files/"+ext+"s/" ):
|
||
|
dir .make_dir_recursive( "user://saves/save_temp/ressources/files/"+ext+"s/" )
|
||
|
|
||
|
if file.open("user://saves/save_temp/ressources/files/"+ext+"s/"+filename, File.WRITE) == OK:
|
||
|
file.store_line( JSONBeautifier.beautify_json( to_json(self.datas), 4 ) )
|
||
|
file.close()
|
||
|
elif p_emplacement == "pc":
|
||
|
var dir = Directory.new()
|
||
|
if not dir.dir_exists( "user://saves/save_temp/ressources/files/"+ext+"s/pc/" ):
|
||
|
dir .make_dir_recursive( "user://saves/save_temp/ressources/files/"+ext+"s/pc/" )
|
||
|
|
||
|
if file.open("user://saves/save_temp/ressources/files/"+ext+"s/pc/"+filename, File.WRITE) == OK:
|
||
|
file.store_line( JSONBeautifier.beautify_json( to_json(self.datas), 4 ) )
|
||
|
file.close()
|
||
|
|
||
|
|
||
|
func load( p_path = null, p_emplacement = null ):
|
||
|
|
||
|
var dict = null
|
||
|
|
||
|
if not p_path:
|
||
|
var filename = self.get_filename()
|
||
|
var ext = filename.get_extension()
|
||
|
var file = File.new()
|
||
|
if not p_emplacement:
|
||
|
if file.open("user://saves/save_temp/ressources/files/"+ext+"s/"+filename, File.READ) == OK or file.open("res://ressources/files/"+ext+"s/"+filename, File.READ) == OK:
|
||
|
dict = JSON.parse(file.get_as_text()).get_result()
|
||
|
else:
|
||
|
var path = "res://ressources/files/"+ext+"s/"+filename
|
||
|
if p_emplacement == "usr":
|
||
|
path = "user://saves/save_temp/ressources/files/"+ext+"s/"+filename
|
||
|
elif p_emplacement == "pc":
|
||
|
path = "user://saves/save_temp/ressources/files/"+ext+"s/pc/"+filename
|
||
|
|
||
|
if file.open(path, File.READ) == OK:
|
||
|
dict = JSON.parse(file.get_as_text()).get_result()
|
||
|
file.close()
|
||
|
|
||
|
else:
|
||
|
var file = File.new()
|
||
|
if file.open(p_path, File.READ) == OK:
|
||
|
dict = JSON.parse(file.get_as_text()).get_result()
|
||
|
file.close()
|
||
|
|
||
|
if dict:
|
||
|
for key in dict.keys():
|
||
|
self.set_data( key, dict[key] )
|
||
|
|
||
|
class ProxyData extends Data:
|
||
|
|
||
|
var data = null
|
||
|
|
||
|
func _init( p_data_filename, p_data = null ):
|
||
|
.set_data( "item_filename", p_data_filename )
|
||
|
.set_data( "modified_values", {} )
|
||
|
|
||
|
var ref_data = Data.new()
|
||
|
ref_data.set_data( "name", .get_data( "item_filename" ) )
|
||
|
ref_data.load()
|
||
|
if ref_data and ref_data is Data:
|
||
|
self.data = ref_data
|
||
|
var modified_values = {}
|
||
|
for data_name in self.data.datas.keys():
|
||
|
if self.data and p_data and not self.data.get_data( data_name ) == p_data.get_data( data_name ):
|
||
|
modified_values[ data_name ] = p_data.get_data( data_name )
|
||
|
.set_data( "modified_values", modified_values )
|
||
|
|
||
|
|
||
|
func set_data( p_data_name, p_value ):
|
||
|
if not .get_data( "modified_values" ):
|
||
|
.set_data( "modified_values", {} )
|
||
|
|
||
|
var new_modified_value = .get_data( "modified_values" )
|
||
|
new_modified_value[ p_data_name ] = p_value
|
||
|
.set_data( "modified_values", new_modified_value )
|
||
|
|
||
|
func get_data( p_key, p_default_value = null ):
|
||
|
if .get_data( "modified_values" ) and p_key in .get_data( "modified_values" ):
|
||
|
return .get_data( "modified_values" )[ p_key ]
|
||
|
elif self.data:
|
||
|
return self.data.get_data( p_key, p_default_value )
|
||
|
return p_default_value
|
||
|
|
||
|
func save( p_emplacement = "usr"):
|
||
|
.save( p_emplacement )
|
||
|
|
||
|
func load( p_path = null, p_emplacement = "usr" ):
|
||
|
.load( p_path, p_emplacement )
|
||
|
|
||
|
class Creature extends Data:
|
||
|
func _init( p_name = null ).( p_name ):
|
||
|
self.set_data( "race", null )
|
||
|
# Caracteristiques.
|
||
|
self.set_data( "strength", 5 )
|
||
|
self.set_data( "perception", 5 )
|
||
|
self.set_data( "endurance", 5 )
|
||
|
self.set_data( "constitution", 5 )
|
||
|
self.set_data( "agility", 5 )
|
||
|
self.set_data( "current_life", self.get_max_life() )
|
||
|
self.set_data( "current_stamina", self.get_max_stamina() )
|
||
|
# inventaire.
|
||
|
self.set_data( "inventory", [] )
|
||
|
|
||
|
func get_filename():
|
||
|
if not self.get_data( "name", null ):
|
||
|
return "unknow.creature"
|
||
|
return self.get_data( "name" )+".creature"
|
||
|
|
||
|
func get_max_life():
|
||
|
return self.get_data( "constitution", 5 ) * 1000
|
||
|
func get_max_stamina():
|
||
|
return self.get_data( "endurance", 5 ) * 1000
|
||
|
|
||
|
class Human extends Creature:
|
||
|
func _init( p_name = null ).( p_name ):
|
||
|
self.set_data( "first_name", null )
|
||
|
self.set_data( "last_name", null )
|
||
|
# Aspect.
|
||
|
self.set_data( "caucasian", 0.0 )
|
||
|
self.set_data( "african", 0.0 )
|
||
|
self.set_data( "asian", 0.0 )
|
||
|
self.set_data( "size", 1.0 )
|
||
|
self.set_data( "fat", 0.0 )
|
||
|
self.set_data( "muscles", 0.0 )
|
||
|
self.set_data( "proportion", 0.0 )
|
||
|
self.set_data( "breast", 0.0 )
|
||
|
self.set_data( "pregnancy", 0.0 )
|
||
|
self.set_data( "skin_tone", 0.0 )
|
||
|
self.set_data( "hair", 0 )
|
||
|
self.set_data( "hair_color", Color.white )
|
||
|
self.set_data( "cleft_chin", 0.0 )
|
||
|
self.set_data( "chin_angle", 0.0 )
|
||
|
self.set_data( "mouth_horiz", 0.0 )
|
||
|
self.set_data( "mouth_vert", 0.0 )
|
||
|
self.set_data( "nose_galbe", 0.0 )
|
||
|
self.set_data( "nose_grec", 0.0 )
|
||
|
self.set_data( "nose_horiz", 0.0 )
|
||
|
self.set_data( "nose_depth", 0.0 )
|
||
|
self.set_data( "eyes_vert", 0.0 )
|
||
|
self.set_data( "eyes_gap", 0.0 )
|
||
|
self.set_data( "earlobes", 0.0 )
|
||
|
self.set_data( "ears_wing", 0.0 )
|
||
|
self.set_data( "lips_up_shape", 0.0 )
|
||
|
self.set_data( "lips_up_shape_2", 0.0 )
|
||
|
|
||
|
|
||
|
func get_filename():
|
||
|
if not self.get_data( "first_name" ) and not self.get_data( "last_name" ):
|
||
|
return "unknow.creature"
|
||
|
elif not self.get_data( "last_name" ):
|
||
|
return self.get_data( "first_name" ) + ".creature"
|
||
|
elif not self.get_data( "first_name" ):
|
||
|
return self.get_data( "last_name" ) + ".creature"
|
||
|
return self.get_data( "first_name" ) + "_" + self.get_data( "last_name" ) + ".creature"
|
||
|
|
||
|
|
||
|
|
||
|
class Item extends Data:
|
||
|
func _init( p_name = null ).( p_name ):
|
||
|
self.set_data( "model", null )
|
||
|
self.set_data( "label", "" )
|
||
|
self.set_data( "description", "" )
|
||
|
self.set_data( "icon", null )
|
||
|
self.set_data( "stack", 1 )
|
||
|
self.set_data( "default_num_given", 1 )
|
||
|
self.set_data( "pickable", true )
|
||
|
self.set_data( "dropable", true )
|
||
|
self.set_data( "hit_points", -1 )
|
||
|
|
||
|
func get_filename():
|
||
|
if not self.get_data( "name", null ):
|
||
|
return "unknow.item"
|
||
|
return self.get_data( "name" )+".item"
|
||
|
|
||
|
class Equipment extends Item:
|
||
|
|
||
|
enum SLOT {
|
||
|
cloth_hand,
|
||
|
cloth_face,
|
||
|
cloth_head,
|
||
|
cloth_torso,
|
||
|
cloth_legs,
|
||
|
cloth_feet,
|
||
|
cloth_back,
|
||
|
weapon_hand_right,
|
||
|
weapon_hand_left,
|
||
|
weapon_hands,
|
||
|
weapon_hip_right,
|
||
|
weapon_hip_left,
|
||
|
weapon_back_right,
|
||
|
weapon_back_left,
|
||
|
weapon_holster_right,
|
||
|
weapon_holster_left
|
||
|
}
|
||
|
|
||
|
func _init( p_name = null ).( p_name ):
|
||
|
self.set_data( "slots", [SLOT.weapon_hand_right] )
|
||
|
self.set_data( "default_slot", SLOT.weapon_hand_right )
|
||
|
self.set_data( "model_equiped", null )
|
||
|
self.set_data( "attachment", "attachment_hand_R" )
|
||
|
self.set_data( "attachment_equiped", "attachment_hand_R" )
|
||
|
|
||
|
func get_filename():
|
||
|
if not self.get_data( "name", null ):
|
||
|
return "unknow.equipment"
|
||
|
return self.get_data( "name" )+".equipment"
|
||
|
|
||
|
class Cloth extends Equipment:
|
||
|
|
||
|
enum LIMB {
|
||
|
head,
|
||
|
torso,
|
||
|
left_upper_arm,
|
||
|
right_upper_arm,
|
||
|
left_lower_arm,
|
||
|
right_lower_arm,
|
||
|
left_hand,
|
||
|
right_hand,
|
||
|
left_upper_leg,
|
||
|
right_upper_leg,
|
||
|
left_lower_leg,
|
||
|
right_lower_leg,
|
||
|
left_feet,
|
||
|
right_feet
|
||
|
}
|
||
|
|
||
|
func _init( p_name = null ).( p_name ):
|
||
|
self.set_data( "protection", 0 )
|
||
|
self.set_data( "protected_limbs", [] )
|
||
|
self.set_data( "texture", null )
|
||
|
|
||
|
func get_filename():
|
||
|
if not self.get_data( "name", null ):
|
||
|
return "unknow.cloth"
|
||
|
return self.get_data( "name" )+".cloth"
|
||
|
|
||
|
class Weapon extends Equipment:
|
||
|
|
||
|
enum TYPE {
|
||
|
melee,
|
||
|
ranged,
|
||
|
throwed
|
||
|
}
|
||
|
|
||
|
func _init( p_name = null ).( p_name ):
|
||
|
self.set_data( "damage", 0.0 )
|
||
|
self.set_data( "reload_needed", 0 )
|
||
|
self.set_data( "range", 1.0 )
|
||
|
self.set_data( "type", TYPE.melee )
|
||
|
self.set_data( "attack_delay", 1.0 )
|
||
|
|
||
|
func get_filename():
|
||
|
if not self.get_data( "name", null ):
|
||
|
return "unknow.weapon"
|
||
|
return self.get_data( "name" )+".weapon"
|
||
|
|
||
|
|
||
|
class InventoryItem extends ProxyData:
|
||
|
|
||
|
func _init( p_item_filename, p_number = 1, p_item = null ).( p_item_filename, p_item ):
|
||
|
self.set_data( "number", p_number )
|
||
|
|
||
|
class PickupItem extends ProxyData:
|
||
|
|
||
|
func _init( p_item_filename, p_global_transform, p_item = null ).( p_item_filename, p_item ):
|
||
|
self.set_data( "global_transform", p_global_transform )
|
||
|
|
||
|
#
|
||
|
#class Character extends ProxyData:
|
||
|
# func _init( p_item_filename, p_item = null ).( p_item_filename, p_item ):
|
||
|
# self.set_data( "current_life", self.get_data( "constitution", 5 )*1000 )
|
||
|
# self.set_data( "current_stamina", self.get_data( "endurance", 5 )*1000 )
|