大更新,太多了,具体进游戏查看详细更新内容

反正很多
This commit is contained in:
2025-05-27 11:09:09 +08:00
parent a1e71a6a79
commit 8215cfa3ee
382 changed files with 13838 additions and 2974 deletions

View File

@@ -0,0 +1,76 @@
extends Node
# 全局通用功能脚本
# 使用方法:首先在项目设置的自动加载中添加此脚本,然后在任何地方使用 GlobalFunctions.函数名() 调用
func _ready():
print("全局函数库已加载")
# 写入 TXT 文件
func write_txt_file(file_path: String, text: String, append: bool = false) -> void:
var file
if append == true:
file = FileAccess.open(file_path, FileAccess.READ_WRITE) # 追加模式
if file:
file.seek_end() # 移动光标到文件末尾
else:
file = FileAccess.open(file_path, FileAccess.WRITE) # 覆盖模式
if file:
file.store_string(text)
file.close()
if has_node("/root/ToastScript"):
get_node("/root/ToastScript").show("游戏已保存!", Color.GREEN, 5.0, 1.0)
else:
print("写入文件时打开失败: ", file_path)
if has_node("/root/ToastScript"):
get_node("/root/ToastScript").show("写入文件时打开失败!", Color.RED, 5.0, 1.0)
# 读取 TXT 文件
func read_txt_file(file_path: String) -> String:
var file = FileAccess.open(file_path, FileAccess.READ)
if file:
var text = file.get_as_text()
file.close()
return text
else:
print("打开文件失败: ", file_path)
return "false"
#生成随机数-用于作物随机死亡
func random_probability(probability: float) -> bool:
# 确保传入的概率值在 0 到 1 之间
if probability*0.001 < 0.0 or probability*0.001 > 1.0:
print("概率值必须在 0 和 1 之间")
return false
# 生成一个 0 到 1 之间的随机数
var random_value = randf()
# 如果随机数小于等于概率值,则返回 true
return random_value <= (probability*0.001)
# 格式化时间为可读字符串
func format_time(seconds: int) -> String:
var minutes = seconds / 60
seconds = seconds % 60
var hours = minutes / 60
minutes = minutes % 60
if hours > 0:
return "%02d:%02d:%02d" % [hours, minutes, seconds]
else:
return "%02d:%02d" % [minutes, seconds]
#双击切换UI事件-比如按一下打开再按一下关闭
func double_click_close(node):
if node.visible == false:
node.show()
pass
else :
node.hide()
pass
pass

View File

@@ -0,0 +1 @@
uid://bv4lf4v2c73pb

View File

@@ -0,0 +1 @@
extends Node

View File

@@ -0,0 +1 @@
uid://co5rk48low4kq

12
GlobalScript/Toast.gd Normal file
View File

@@ -0,0 +1,12 @@
# toast.gd
extends Node
const ToastScene = preload("res://components/ToastShow.tscn")
static func show(text: String,
color: Color = Color.WHITE,
duration: float = 3.0,
fade: float = 1.0) -> void:
var toast = ToastScene.instantiate()
# 延迟设置参数确保节点初始化完成
toast.call_deferred("setup", text, color, duration, fade)

View File

@@ -0,0 +1 @@
uid://336lik63ehtt

6
GlobalScript/Toast.tscn Normal file
View File

@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://cvip7owyfmqav"]
[ext_resource type="Script" uid="uid://336lik63ehtt" path="res://Components/Toast.gd" id="1_rdgmi"]
[node name="Toast" type="Node"]
script = ExtResource("1_rdgmi")