extends Node #全局数据json的加载 var texture_json_path:String="res://json/texture.json" var texture_data:Dictionary var card_json_path:String="res://json/card.json" var card_data:Dictionary var script_json_path:String="res://json/script.json" var script_data:Dictionary var script_type_divide_data:Array=[] var event_json_path:String="res://json/event.json" var event_data:Dictionary var scene_json_path:String="res://json/scene.json" var scene_data:Dictionary var character_json_path:String="res://json/character.json" var character_data:Dictionary var map_json_path:String="res://json/map.json" var map_data:Dictionary var npc_json_path:String="res://json/npc.json" var npc_data:Dictionary var system_config_data:Dictionary={ } var system_game_data:Dictionary={ "unlock_character":["test_character_01","test_character_02"] } var now_game_data:Dictionary={ "character_data":{ }, "script_data":{ }, "now_scene":"scene_01", "difficulty":0, "gold":9999, "health":100, "spirit":999, "map":"map_01", "move_ability":1, "time_unix":0, "card_in_bag":["card_03","card_03","card_02","card_02","card_01","card_01","card_01","card_01"] } #当前战斗场景 var now_fight_scene:FightScene #向卡组中添加卡牌 func add_card(card_id:String): now_game_data["card_in_bag"].append(card_id) #从卡组中删除卡牌 func delete_card(card_id:String)->bool: var now_arr:Array= now_game_data["card_in_bag"] var ind=now_arr.find(card_id) if ind==-1: return false else: now_game_data["card_in_bag"].pop_at(ind) return true #使用卡牌 func use_card(card_data:Dictionary,target=null): print("执行了卡牌:\n"+str(card_data)+"\n目标"+str(target)) pass func get_all_card()->Array: return now_game_data["card_in_bag"].duplicate() func get_move_ability(): return now_game_data["move_ability"] func get_time_dictionary(): var time_unix=int(now_game_data["time_unix"]) return Time.get_datetime_dict_from_unix_time(time_unix) func get_time_unix(): return now_game_data["time_unix"] #year、month、day、weekday、hour、minute 和 second func flow_time(data:Dictionary): var date=get_time_dictionary() var change_unix:float=0 if data.has("day"): var day=data["year"] change_unix+=day*86400 if data.has("hour"): var hour=data["hour"] change_unix+=3600*hour if data.has("minute"): var minute=data["minute"] change_unix+=minute*60 now_game_data["time_unix"]+=change_unix time_changed.emit() signal time_changed var triger:Dictionary={ "change_event":func (data):now_game_flow.show_event(data), "change_texture": func (data):now_game_flow.event_panel.change_texture(data), "change_text":func(data):now_game_flow.event_panel.change_text(data), "change_choice":func(data):now_game_flow.event_panel.change_choice(data), "increase_health":func (data):now_game_data.health-=data, "end_event":func(data):now_game_flow.event_panel.hide(), "flow_time":func (data):flow_time(data) } func call_triger(triger_type:String,data): if triger.has(triger_type): return triger[triger_type].call(data) else: return null #条件类型字典 var condition_triger:Dictionary={ "date_limit":func (data:Dictionary):return TimeTool.is_in_date(data,get_time_dictionary()), "time_limit":func (data:Dictionary):return TimeTool.is_in_time(data,get_time_dictionary()), "rand":func (data:Dictionary):return get_rand(data["scene_id"],data["touch_id"],data["index"],data["condition"]), } func call_condition_triger(triger_type:String,data): if condition_triger.has(triger_type): return condition_triger[triger_type].call(data) else: return null pass var condition_triger_randi_dic:Dictionary={ "scene_id":{ "touch_name":{ "index":{ "last_time_triger":0000, "last_rand_result":false, } } } } func get_rand(scene_id:String,touch_name:String,index:String,condition:float)->bool: if condition_triger_randi_dic.has(scene_id): var scene_data=condition_triger_randi_dic[scene_id] if scene_data.has(touch_name): var touch_data=scene_data[touch_name] if touch_data.has(index): var triger_data=touch_data[index] var last_time_triger=triger_data["last_time_triger"] if last_time_triger==get_time_unix(): return triger_data["last_rand_result"] else: var dic=recreate_rand_dic(condition) condition_triger_randi_dic[scene_id][touch_name][index]=dic return dic["last_rand_result"] pass else: var dic=recreate_rand_dic(condition) condition_triger_randi_dic[scene_id][touch_name][index]=dic return dic["last_rand_result"] else: var dic=recreate_rand_dic(condition) condition_triger_randi_dic[scene_id][touch_name]={ index:dic } return dic["last_rand_result"] pass else: var dic=recreate_rand_dic(condition) condition_triger_randi_dic[scene_id]={ touch_name:{ index:dic } } return dic["last_rand_result"] func recreate_rand_dic(condition:float)->Dictionary: var new_rand_result:bool=(randf() void: load_texture_data() load_script_data() load_event_data() load_scene_data() load_card_data() load_character_data() load_map_data() load_npc_data() func load_texture_data(): var file=FileAccess.open(texture_json_path,FileAccess.READ) var str=file.get_as_text() var dictionary:Dictionary=JSON.parse_string(str) for i in dictionary.keys(): var texture=load(dictionary[i]) if texture is Texture2D: dictionary[i]=texture texture_data=dictionary func load_script_data(): var file=FileAccess.open(script_json_path,FileAccess.READ) var str=file.get_as_text() var dictionary:Dictionary=JSON.parse_string(str) script_type_divide_data=[{},{},{},{}] for i in dictionary.keys(): dictionary[i]["id"]=i var data=dictionary[i] if data.has("type"): var type:int=int(data["type"]) script_type_divide_data[type][i]=data script_data=dictionary func load_event_data(): var file=FileAccess.open(event_json_path,FileAccess.READ) var str=file.get_as_text() var dictionary:Dictionary=JSON.parse_string(str) for i in dictionary.keys(): dictionary[i]["id"]=i event_data=dictionary func load_scene_data(): var file=FileAccess.open(scene_json_path,FileAccess.READ) var str=file.get_as_text() var dictionary:Dictionary=JSON.parse_string(str) for i in dictionary.keys(): dictionary[i]["id"]=i scene_data=dictionary pass func load_character_data(): var file=FileAccess.open(character_json_path,FileAccess.READ) var str=file.get_as_text() var dictionary:Dictionary=JSON.parse_string(str) for i in dictionary.keys(): dictionary[i]["id"]=i character_data=dictionary func load_map_data(): var file=FileAccess.open(map_json_path,FileAccess.READ) var str=file.get_as_text() var dictionary:Dictionary=JSON.parse_string(str) for i in dictionary.keys(): dictionary[i]["id"]=i map_data=dictionary func load_npc_data(): var file=FileAccess.open(npc_json_path,FileAccess.READ) var str=file.get_as_text() var dictionary:Dictionary=JSON.parse_string(str) for i in dictionary.keys(): dictionary[i]["id"]=i npc_data=dictionary func load_card_data(): var file=FileAccess.open(card_json_path,FileAccess.READ) var str=file.get_as_text() var dictionary:Dictionary=JSON.parse_string(str) for i in dictionary.keys(): dictionary[i]["id"]=i card_data=dictionary pass func get_texture(id:String): if texture_data.has(id): return texture_data[id] else: return null func get_script_data(id:String): if script_data.has(id): var dictionary:Dictionary=script_data[id] return dictionary.duplicate(true) else: return null func get_all_script_data(): return script_type_divide_data.duplicate() func get_event_data(id:String): if event_data.has(id): var dictionary:Dictionary=event_data[id] return dictionary.duplicate(true) else: return null func get_scene_data(id:String): if scene_data.has(id): var dictionary:Dictionary=scene_data[id] return dictionary.duplicate(true) else: return null func get_character_data(id:String): if character_data.has(id): var dictionary:Dictionary=character_data[id] return dictionary.duplicate(true) else: return null func get_map_data(id:String): if map_data.has(id): var dictionary:Dictionary=map_data[id] return dictionary.duplicate(true) else: return null pass func get_npc_data(id:String): if npc_data.has(id): var dictionary:Dictionary=npc_data[id] return dictionary.duplicate(true) else: return null pass func get_card_data(id:String): if card_data.has(id): var dictionary:Dictionary=card_data[id] return dictionary.duplicate(true) else: return null