forked from y3-editor/y3-lualib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
152 lines (133 loc) · 5 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
pcall(function ()
LDBG = require "y3.debugger":start "127.0.0.1:12399"
end)
pcall(function ()
io.popen(('mkdir "%s"'):format(lua_script_path .. '\\log'))
local waitdbg = io.open(lua_script_path .. '\\log\\waitdbg')
if waitdbg then
waitdbg:close()
io.popen(('del "%s"'):format(lua_script_path .. '\\log\\waitdbg'))
end
if LDBG and waitdbg then
LDBG:event 'wait'
end
end)
-- 全局方法类,提供各种全局方法
---@class Y3
y3 = {}
y3.proxy = require 'y3.tools.proxy'
y3.class = require 'y3.tools.class'
y3.util = require 'y3.tools.utility'
y3.json = require 'y3.tools.json'
pcall(function ()
y3.doctor = require 'y3.tools.doctor'
end)
Class = y3.class.declare
New = y3.class.new
---@deprecated
---@diagnostic disable-next-line: deprecated
Super = y3.class.super
Extends = y3.class.extends
Delete = y3.class.delete
IsValid = y3.class.isValid
require 'y3.util.log'
y3.reload = require 'y3.tools.reload'
y3.sandbox = require 'y3.tools.sandbox'
---@diagnostic disable-next-line: lowercase-global
include = y3.reload.include
require 'y3.tools.linked_table'
require 'y3.tools.pool'
require 'y3.tools.gc'
require 'y3.util.eca_function'
require 'y3.util.trigger'
require 'y3.util.event'
require 'y3.util.event_manager'
require 'y3.util.custom_event'
require 'y3.util.ref'
require 'y3.util.storage'
print = log.debug
y3.const = require 'y3.game.const'
y3.math = require 'y3.game.math'
y3.game = require 'y3.game.game'
y3.py_converter = require 'y3.game.py_converter'
y3.py_event_sub = require 'y3.game.py_event_subscribe'
y3.helper = require 'y3.game.helper'
y3.ground = require 'y3.game.ground'
y3.config = require 'y3.game.config'
y3.kv = require 'y3.game.kv'
y3.unit = require 'y3.object.editable_object.unit'
y3.ability = require 'y3.object.editable_object.ability'
y3.destructible = require 'y3.object.editable_object.destructible'
y3.item = require 'y3.object.editable_object.item'
y3.buff = require 'y3.object.editable_object.buff'
y3.projectile = require 'y3.object.editable_object.projectile'
y3.technology = require 'y3.object.editable_object.technology'
y3.beam = require 'y3.object.runtime_object.beam'
y3.item_group = require 'y3.object.runtime_object.item_group'
y3.mover = require 'y3.object.runtime_object.mover'
y3.particle = require 'y3.object.runtime_object.particle'
y3.player = require 'y3.object.runtime_object.player'
y3.player_group = require 'y3.object.runtime_object.player_group'
y3.timer = require 'y3.object.runtime_object.timer'
y3.unit_group = require 'y3.object.runtime_object.unit_group'
y3.projectile_group = require 'y3.object.runtime_object.projectile_group'
y3.selector = require 'y3.object.runtime_object.selector'
y3.cast = require 'y3.object.runtime_object.cast'
y3.damage_instance = require 'y3.object.runtime_object.damage_instance'
y3.heal_instance = require 'y3.object.runtime_object.heal_instance'
y3.sound = require 'y3.object.runtime_object.sound'
require 'y3.object.runtime_object.local_player'
y3.area = require 'y3.object.scene_object.area'
y3.camera = require 'y3.object.scene_object.camera'
y3.light = require 'y3.object.scene_object.light'
y3.road = require 'y3.object.scene_object.road'
y3.point = require 'y3.object.scene_object.point'
y3.scene_ui = require 'y3.object.scene_object.scene_ui'
y3.ui = require 'y3.object.scene_object.ui'
y3.ui_prefab = require 'y3.object.scene_object.ui_prefab'
y3.shape = require 'y3.object.scene_object.shape'
y3.object = require 'y3.util.object'
y3.ltimer = require 'y3.util.local_timer'
y3.save_data = require 'y3.util.save_data'
y3.dump = require 'y3.util.dump'
y3.sync = require 'y3.util.sync'
y3.develop = {}
y3.develop.command = include 'y3.develop.command'
-- TODO 给目前的Lua垃圾回收过慢的问题打个临时补丁
local function fixGC()
local mem = collectgarbage 'count'
y3.ltimer.loop_frame(10, function ()
local new_mem = collectgarbage 'count'
local delta = new_mem - mem
mem = new_mem
if delta > 0 then
collectgarbage 'restart'
collectgarbage('step', math.ceil(delta))
end
end)
end
-- TODO 访问不存在的 GameAPI 和 GlobalAPI 不要报错,返回 nil
local function safeGetter(t)
local nilMap = {}
return setmetatable({}, { __index = function (self, k)
if nilMap[k] then
return nil
end
local suc, res = pcall(function ()
return t[k]
end)
if not suc or res == nil then
nilMap[k] = true
return nil
else
self[k] = res
return res
end
end })
end
fixGC()
-- TODO 临时补丁,防止访问不存在的 GameAPI 和 GlobalAPI 时报错。预计3月7号版本修复。
---@class py.GameAPI
GameAPI = safeGetter(GameAPI)
---@class py.GlobalAPI
GlobalAPI = safeGetter(GlobalAPI)