9.23下午

This commit is contained in:
TsubakiLoL 2024-09-23 17:27:43 +08:00
parent f2a5809732
commit 67a6671d04
7 changed files with 295 additions and 19 deletions

View File

@ -49,6 +49,8 @@ func get_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()
@ -79,12 +81,74 @@ func call_triger(triger_type:String,data):
return triger[triger_type].call(data)
else:
return null
#条件类型字典
var condition_triger:Dictionary={
"date_limit":"",
"time_limit":"",
"rand":"",
"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()<condition)
var dic={
"last_time_triger":get_time_unix(),
"last_rand_result":new_rand_result,
}
return dic
func move_scene(scene_id:String,distance):
if scene_id==get_now_scene():
return false

132
class/time/TimeTool.gd Normal file
View File

@ -0,0 +1,132 @@
class_name TimeTool
static func is_in_date(data:Dictionary,now_time:Dictionary)->bool:
var from_time:Dictionary
if data.has("from"):
from_time=data["from"]
else:
from_time={
"year":-999999,
"month":-1,
"day":-1
}
var to_time:Dictionary
if data.has("to"):
to_time=data["to"]
else:
to_time={
"year":99999999,
"month":-1,
"day":-1
}
return date_limit(from_time,to_time,now_time)
static func date_limit(from:Dictionary,to:Dictionary,now_time:Dictionary)->bool:
var dic:Dictionary=now_time
var from_year=from["year"]
var from_month
if from.has("month"):
from_month=from["month"]
else:
from_month=1
var from_day
if from.has("day"):
from_day=from["day"]
else:
from_day=1
var to_year=to["year"]
var to_month
if to.has("month"):
to_month=to["month"]
else:
to_month=1
var to_day
if to.has("day"):
to_day=to["day"]
else:
to_day=1
var now_year=dic["year"]
var now_month=dic["month"]
var now_day=dic["day"]
return date_CMOS(now_year,now_month,now_day,from_year,from_month,from_day) and date_CMOS(to_year,to_month,to_day,now_year,now_month,now_day)
pass
static func date_CMOS(from_year:int,from_month:int,from_day:int,to_year:int,to_month:int,to_day:int):
if from_year>to_year:
return true
elif from_year==to_year:
if from_month>to_month:
return true
elif from_month==to_month:
return from_day>=to_day
else:
return false
pass
else:
return false
pass
static func is_in_time(data:Dictionary,now_time:Dictionary)->bool:
var from_time:Dictionary
if data.has("from"):
from_time=data["from"]
else:
from_time={
"hour":-1,
"minute":-1
}
var to_time:Dictionary
if data.has("to"):
to_time=data["to"]
else:
to_time={
"hour":25,
"minute":61
}
return time_limit(from_time,to_time,now_time)
static func time_limit(from:Dictionary,to:Dictionary,now_time:Dictionary)->bool:
var dic:Dictionary=now_time
var from_hour=from["hour"]
var from_minute
if from.has("minute"):
from_minute=from["minute"]
else:
from_minute=0
var to_hour=to["hour"]
var to_minute
if to.has("minute"):
to_minute=to["minute"]
else:
to_minute=0
var now_hour=dic["hour"]
var now_minute=dic["minute"]
return time_CMOS(now_hour,now_minute,from_hour,from_minute) and time_CMOS(to_hour,to_minute,now_hour,now_minute)
pass
static func time_CMOS(from_hour:int,from_minute:int,to_hour:int,to_minute:int)->bool:
if from_hour>to_hour:
return true
elif from_hour==to_hour:
if from_minute>=to_minute:
return true
else:
return false
pass
else:
return false

View File

@ -67,12 +67,46 @@
"touch":{
"测试互动点1":{
"triger":[],
"event":["event_01"]
"condition":[
{
"type":"time_limit",
"data":{
"from":{
"hour":18
}
}
}
],
"position":[100,100],
"event":"event_01"
},
"测试互动点2":{
"triger":[],
"character":[]
"condition":[
{
"type":"date_limit",
"data":{
"from":{
"year":1970,
"month":1,
"day":2
}
}
}
],
"position":[200,200],
"event":"event_02"
},
"测试互动点3":{
"condition":[
{
"type":"rand",
"data":{
"condition":0.5
}
}
],
"position":[300,300],
"event":"event_02"
}
}

View File

@ -45,17 +45,31 @@ func set_scene(id:String):
new_place.set_data(i)
new_place.pressed.connect(place_pressed)
pass
for i in scene_data["touch"]:
if scene_data.has("touch"):
var touch_data:Dictionary=scene_data["touch"].duplicate()
for i in touch_data.keys():
var new_touch=GAME_FLOW_TOUCH.instantiate()
touch_add_pos.add_child(new_touch)
touch_data[i]["scene_id"]=id
touch_data[i]["name"]=i
new_touch.set_data(touch_data[i])
new_touch.judge()
pass
func judge_touch():
for i in touch_add_pos.get_children():
i.judge()
func touch_click(data:Dictionary):
pass
func update_date():
var time_dic=Global.get_time_dictionary()
date.text=str(time_dic["year"])+"/"+str(time_dic["month"])+"/"+str(time_dic["day"])
judge_touch()
func place_pressed(data:Dictionary):
Global.move_scene(data["id"],data["distance"])

View File

@ -1,10 +1,37 @@
extends MarginContainer
@onready var name_debug: Label = $name_debug
signal touch_click()
signal touch_click(data:Dictionary)
var data:Dictionary
var scene_id:String
var ind:String
func set_data(_data:Dictionary):
data=_data
name_debug.text==data["name"]
position=Vector2(data["position"][0],data["position"][1])
pass
func judge():
func update_time():
pass
func judge():
var res:bool=true
if data.has("condition"):
var condition_data:Array=data["condition"]
for i in condition_data.size():
var new_condition_data:Dictionary=condition_data[i].duplicate()
var type:String=new_condition_data["type"]
var _data:Dictionary=new_condition_data["data"]
_data["scene_id"]=data["scene_id"]
_data["touch_id"]=data["name"]
_data["index"]=str(i)
res=res and Global.call_condition_triger(type,_data)
if res:
self.show()
else:
self.hide()
print(data["name"]+"判定结果:"+str(res))
func _on_tool_button_pressed() -> void:
pass # Replace with function body.

View File

@ -63,5 +63,12 @@ size_flags_horizontal = 8
size_flags_vertical = 4
texture = ExtResource("5_oqc0n")
[node name="name_debug" type="Label" parent="."]
layout_mode = 2
[node name="ToolButton" parent="." instance=ExtResource("7_xebjv")]
layout_mode = 2
[node name="breath" type="AnimationPlayer" parent="."]
[connection signal="pressed" from="ToolButton" to="." method="_on_tool_button_pressed"]

View File

@ -109,9 +109,7 @@ func update_pointer():
var now_scene_id=Global.get_now_scene()
var pos=map_now.get_scene_global_pos(now_scene_id)-Vector2(pointer.size.x/2,pointer.size.y)
pointer.global_position=pos
print(pos)
func click(scene_id:String):
print(scene_id)
if scene_id==Global.get_now_scene():
return
scene_change.emit(scene_id)