@expcluster/legacy 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/dist/browser/package.json +40 -0
- package/dist/browser/tsconfig.browser.tsbuildinfo +1 -0
- package/dist/browser/web/index.d.ts +1 -0
- package/dist/browser/web/index.d.ts.map +1 -0
- package/dist/browser/web/index.js +2 -0
- package/dist/browser/web/index.js.map +1 -0
- package/dist/node/index.d.ts +3 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +10 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/instance.d.ts +4 -0
- package/dist/node/instance.d.ts.map +1 -0
- package/dist/node/instance.js +8 -0
- package/dist/node/instance.js.map +1 -0
- package/dist/node/tsconfig.node.tsbuildinfo +1 -0
- package/dist/web/manifest.json +7 -0
- package/dist/web/static/exp_legacy.9b6538559ed5e689539c.js +355 -0
- package/dist/web/static/index_ts.8f9d451c8d3f7f293da6.js +22 -0
- package/dist/web/static/main.94e1b48804112ca8bdfc.js +118 -0
- package/dist/web/static/package_json.a83729efdb0697b12396.js +22 -0
- package/dist/web/static/web_index_tsx.e5a01ac0e4b0a6f6517f.js +21 -0
- package/index.ts +8 -0
- package/instance.ts +7 -0
- package/module/config/_file_loader.lua +29 -0
- package/module/config/advanced_start.lua +112 -0
- package/module/config/afk_kick.lua +14 -0
- package/module/config/bonus.lua +105 -0
- package/module/config/chat_reply.lua +136 -0
- package/module/config/compilatron.lua +25 -0
- package/module/config/death_logger.lua +15 -0
- package/module/config/deconlog.lua +11 -0
- package/module/config/discord_alerts.lua +25 -0
- package/module/config/expcore/permission_groups.lua +143 -0
- package/module/config/graftorio.lua +7 -0
- package/module/config/gui/autofill.lua +129 -0
- package/module/config/gui/player_list_actions.lua +201 -0
- package/module/config/gui/rockets.lua +47 -0
- package/module/config/gui/science.lua +21 -0
- package/module/config/gui/tasks.lua +13 -0
- package/module/config/gui/warps.lua +52 -0
- package/module/config/inventory_clear.lua +9 -0
- package/module/config/join_messages.lua +8 -0
- package/module/config/lawnmower.lua +6 -0
- package/module/config/logging.lua +30 -0
- package/module/config/miner.lua +8 -0
- package/module/config/module.lua +86 -0
- package/module/config/nukeprotect.lua +30 -0
- package/module/config/pollution_grading.lua +9 -0
- package/module/config/popup_messages.lua +10 -0
- package/module/config/preset_player_colours.lua +33 -0
- package/module/config/preset_player_quickbar.lua +6 -0
- package/module/config/protection.lua +17 -0
- package/module/config/repair.lua +8 -0
- package/module/config/research.lua +179 -0
- package/module/config/scorched_earth.lua +116 -0
- package/module/config/spawn_area.lua +255 -0
- package/module/config/station_auto_name.lua +11 -0
- package/module/config/statistics.lua +46 -0
- package/module/config/vlayer.lua +180 -0
- package/module/config/warnings.lua +38 -0
- package/module/control.lua +46 -0
- package/module/expcore/datastore.lua +884 -0
- package/module/expcore/external.lua +146 -0
- package/module/expcore/permission_groups.lua +355 -0
- package/module/expcore/player_data.lua +152 -0
- package/module/locale/en/addons.cfg +31 -0
- package/module/locale/en/data.cfg +114 -0
- package/module/locale/en/expcore.cfg +16 -0
- package/module/locale/en/gui.cfg +114 -0
- package/module/locale/zh-CN/addons.cfg +31 -0
- package/module/locale/zh-CN/data.cfg +114 -0
- package/module/locale/zh-CN/expcore.cfg +16 -0
- package/module/locale/zh-CN/gui.cfg +122 -0
- package/module/locale/zh-TW/addons.cfg +31 -0
- package/module/locale/zh-TW/data.cfg +114 -0
- package/module/locale/zh-TW/expcore.cfg +16 -0
- package/module/locale/zh-TW/gui.cfg +122 -0
- package/module/module.json +14 -0
- package/module/module_exports.lua +3 -0
- package/module/modules/control/jail.lua +119 -0
- package/module/modules/control/protection.lua +204 -0
- package/module/modules/control/reports.lua +225 -0
- package/module/modules/control/spectate.lua +173 -0
- package/module/modules/control/vlayer.lua +807 -0
- package/module/modules/control/warnings.lua +331 -0
- package/module/modules/control/warps.lua +488 -0
- package/module/modules/data/alt-view.lua +26 -0
- package/module/modules/data/greetings.lua +45 -0
- package/module/modules/data/language.lua +21 -0
- package/module/modules/data/player-colours.lua +63 -0
- package/module/modules/data/quickbar.lua +72 -0
- package/module/modules/data/statistics.lua +181 -0
- package/module/modules/data/tag.lua +82 -0
- package/module/modules/data/toolbar.lua +31 -0
- package/module/modules/graftorio/forcestats.lua +196 -0
- package/module/modules/graftorio/general.lua +63 -0
- package/module/modules/graftorio/require.lua +28 -0
- package/module/modules/graftorio/statics.lua +36 -0
- package/module/modules/gui/vlayer.lua +547 -0
- package/module/modules/gui/warp-list.lua +909 -0
- package/module/utils/event.lua +86 -0
- package/package.json +38 -0
- package/tsconfig.browser.json +4 -0
- package/tsconfig.json +7 -0
- package/tsconfig.node.json +5 -0
- package/web/index.tsx +0 -0
- package/webpack.config.js +29 -0
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
--[[-- Control Module - Warps
|
|
2
|
+
- Stores warps for each force.
|
|
3
|
+
@control Warps
|
|
4
|
+
@alias Warps
|
|
5
|
+
|
|
6
|
+
@usage-- Making a new spawn warp
|
|
7
|
+
local player = game.player
|
|
8
|
+
local force = player.force
|
|
9
|
+
local spawn_id = Warps.add_warp(force.name, player.physical_surface, player.physical_position, player.name, 'Spawn')
|
|
10
|
+
|
|
11
|
+
Warps.set_spawn_warp(spawn_id, force)
|
|
12
|
+
Warps.make_warp_tag(spawn_id)
|
|
13
|
+
|
|
14
|
+
@usage-- Making a new warp with a warp area
|
|
15
|
+
local player = game.player
|
|
16
|
+
local force = player.force
|
|
17
|
+
local warp_id = Warps.add_warp(force.name, player.physical_surface, player.physical_position, player.name)
|
|
18
|
+
|
|
19
|
+
Warps.make_warp_area(warp_id)
|
|
20
|
+
Warps.make_warp_tag(warp_id)
|
|
21
|
+
|
|
22
|
+
]]
|
|
23
|
+
|
|
24
|
+
local Datastore = require("modules.exp_legacy.expcore.datastore") --- @dep expcore.datastore
|
|
25
|
+
local Storage = require("modules/exp_util/storage")
|
|
26
|
+
local config = require("modules.exp_legacy.config.gui.warps") --- @dep config.warps
|
|
27
|
+
|
|
28
|
+
--- Stores all data for the warp system
|
|
29
|
+
local WrapData = Datastore.connect("WrapData")
|
|
30
|
+
WrapData:set_serializer(function(raw_key) return raw_key.warp_id end)
|
|
31
|
+
|
|
32
|
+
local Warps = {}
|
|
33
|
+
|
|
34
|
+
--- @class ExpScenario_Warps.force_warps: { spawn: string, [number]: string }
|
|
35
|
+
|
|
36
|
+
-- Storage lookup table for force name to task ids
|
|
37
|
+
local force_warps = { _uid = 1 }
|
|
38
|
+
--- @cast force_warps table<string, ExpScenario_Warps.force_warps>
|
|
39
|
+
Storage.register(force_warps, function(tbl)
|
|
40
|
+
force_warps = tbl
|
|
41
|
+
end)
|
|
42
|
+
|
|
43
|
+
-- Create an array of entity names that will be added to the remove filter
|
|
44
|
+
local remove_warp_area_entity_names = {}
|
|
45
|
+
for _, entity in pairs(config.entities) do
|
|
46
|
+
table.insert(remove_warp_area_entity_names, entity[1])
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
-- When a warp is updated change its chat tag and restore the warp order
|
|
50
|
+
WrapData:on_update(function(warp_id, warp, old_warp)
|
|
51
|
+
if warp then
|
|
52
|
+
warp.updates = warp.updates + 1
|
|
53
|
+
-- Update the map chart tag if there is one
|
|
54
|
+
if warp.tag then
|
|
55
|
+
Warps.make_warp_tag(warp_id)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
-- Check that the name of the warp has been changed
|
|
59
|
+
if not old_warp or warp.name == old_warp.name then return end
|
|
60
|
+
|
|
61
|
+
-- Get the names of all the warp points for this force
|
|
62
|
+
local force_name = warp.force_name
|
|
63
|
+
local warp_ids = force_warps[force_name]
|
|
64
|
+
local spawn_id = warp_ids.spawn
|
|
65
|
+
|
|
66
|
+
local warp_names = {} --- @type table<string, string>
|
|
67
|
+
for _, next_warp_id in pairs(warp_ids) do
|
|
68
|
+
local next_warp = WrapData:get(next_warp_id)
|
|
69
|
+
if next_warp_id ~= spawn_id then
|
|
70
|
+
warp_names[next_warp.name .. next_warp_id] = next_warp_id
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
-- Sort the warp names in alphabetical order
|
|
75
|
+
local new_warp_ids = table.get_values(table.key_sort(warp_names))
|
|
76
|
+
--- @cast new_warp_ids ExpScenario_Warps.force_warps
|
|
77
|
+
table.insert(new_warp_ids, 1, spawn_id)
|
|
78
|
+
new_warp_ids.spawn = spawn_id
|
|
79
|
+
force_warps[force_name] = new_warp_ids
|
|
80
|
+
end
|
|
81
|
+
end)
|
|
82
|
+
|
|
83
|
+
--- Map Integration.
|
|
84
|
+
-- functions used to create and alter warps with in the map
|
|
85
|
+
-- @section mapIntegration
|
|
86
|
+
|
|
87
|
+
--[[-- Add or update the chat tag for this warp
|
|
88
|
+
@tparam string warp_id the uid of the warp you want the chart tag for
|
|
89
|
+
@treturn boolean true if a new tag was made, false if it was updated
|
|
90
|
+
|
|
91
|
+
@usage-- Adding a chart tag for a new warp
|
|
92
|
+
local tag_added = Warps.make_warp_tag(warp_id)
|
|
93
|
+
|
|
94
|
+
]]
|
|
95
|
+
function Warps.make_warp_tag(warp_id)
|
|
96
|
+
local warp = WrapData:get(warp_id)
|
|
97
|
+
local name = warp.name
|
|
98
|
+
local icon = warp.icon
|
|
99
|
+
|
|
100
|
+
-- Edit the existing tag if it is present
|
|
101
|
+
local tag = warp.tag
|
|
102
|
+
|
|
103
|
+
if tag and tag.valid then
|
|
104
|
+
tag.text = "Warp: " .. name
|
|
105
|
+
tag.icon = icon
|
|
106
|
+
return false
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
-- Make a new tag if one did not exist
|
|
110
|
+
local force = game.forces[warp.force_name]
|
|
111
|
+
local surface = warp.surface
|
|
112
|
+
local position = warp.position
|
|
113
|
+
|
|
114
|
+
tag = force.add_chart_tag(surface, {
|
|
115
|
+
position = { position.x + 0.5, position.y + 0.5 },
|
|
116
|
+
text = "Warp: " .. name,
|
|
117
|
+
icon = icon,
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
-- Add the tag to this warp, store.update not needed as we dont want it to trigger
|
|
121
|
+
warp.tag = tag
|
|
122
|
+
return true
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
--[[-- Remove the chart tag for this warp
|
|
126
|
+
@tparam string warp_id the uid for the warp that you want to remove the chart tag from
|
|
127
|
+
@treturn boolean true if the tag was valid and was removed, false if the tag was invalid
|
|
128
|
+
|
|
129
|
+
@usage-- Removing the chart tag from a warp
|
|
130
|
+
local removed = Warps.remove_warp_tag(warp_id)
|
|
131
|
+
|
|
132
|
+
]]
|
|
133
|
+
function Warps.remove_warp_tag(warp_id)
|
|
134
|
+
local warp = WrapData:get(warp_id)
|
|
135
|
+
|
|
136
|
+
-- Check there is a tag to remove
|
|
137
|
+
local tag = warp.tag
|
|
138
|
+
if not tag or not tag.valid then
|
|
139
|
+
warp.tag = nil
|
|
140
|
+
return false
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
-- Remove the warp chart tag if it is valid
|
|
144
|
+
tag.destroy()
|
|
145
|
+
warp.tag = nil
|
|
146
|
+
|
|
147
|
+
return true
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
--[[-- Add a warp area for the warp, purely cosmetic
|
|
151
|
+
@tparam string warp_id the uid of the warp you want the area for
|
|
152
|
+
|
|
153
|
+
@usage-- Adding a warp area for a warp
|
|
154
|
+
Warps.make_warp_area(warp_id)
|
|
155
|
+
|
|
156
|
+
]]
|
|
157
|
+
function Warps.make_warp_area(warp_id)
|
|
158
|
+
local warp = WrapData:get(warp_id)
|
|
159
|
+
local surface = warp.surface
|
|
160
|
+
local position = warp.position
|
|
161
|
+
local posx = position.x
|
|
162
|
+
local posy = position.y
|
|
163
|
+
|
|
164
|
+
-- Get the tile that is being replaced, store.update not needed as we don't want it to trigger
|
|
165
|
+
local old_tile = surface.get_tile(position).name
|
|
166
|
+
warp.old_tile = old_tile
|
|
167
|
+
|
|
168
|
+
-- Add a tile pattern on top of the base
|
|
169
|
+
local tiles = {}
|
|
170
|
+
for _, tile in pairs(config.tiles) do
|
|
171
|
+
table.insert(tiles, { name = tile[1], position = { tile[2] + posx, tile[3] + posy } })
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
surface.set_tiles(tiles)
|
|
175
|
+
|
|
176
|
+
-- Add entities to the warp structure
|
|
177
|
+
for _, entity in pairs(config.entities) do
|
|
178
|
+
entity = surface.create_entity{
|
|
179
|
+
name = entity[1],
|
|
180
|
+
position = { entity[2] + posx, entity[3] + posy },
|
|
181
|
+
force = "neutral",
|
|
182
|
+
}
|
|
183
|
+
entity.destructible = false
|
|
184
|
+
entity.health = 0
|
|
185
|
+
entity.minable_flag = false
|
|
186
|
+
entity.rotatable = false
|
|
187
|
+
|
|
188
|
+
-- Save reference of the last power pole
|
|
189
|
+
if entity.type == "electric-pole" then
|
|
190
|
+
warp.electric_pole = entity
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
--[[-- Remove the warp area for a warp
|
|
196
|
+
@tparam string warp_id the uid of the warp that you want to remove the area for
|
|
197
|
+
|
|
198
|
+
@usage-- Remove the warp area for a warp
|
|
199
|
+
Warps.remove_warp_area(warp_id)
|
|
200
|
+
|
|
201
|
+
]]
|
|
202
|
+
function Warps.remove_warp_area(warp_id)
|
|
203
|
+
local warp = WrapData:get(warp_id)
|
|
204
|
+
local position = warp.position
|
|
205
|
+
local surface = warp.surface
|
|
206
|
+
local radius = config.standard_proximity_radius
|
|
207
|
+
|
|
208
|
+
-- Check that a warp area was created previously
|
|
209
|
+
local old_tile = warp.old_tile
|
|
210
|
+
if not old_tile then return end
|
|
211
|
+
|
|
212
|
+
-- Restore the original tiles before the creation of the warp
|
|
213
|
+
local tiles = {}
|
|
214
|
+
|
|
215
|
+
for _, tile in pairs(config.tiles) do
|
|
216
|
+
table.insert(tiles, { name = old_tile, position = { tile[2] + position.x, tile[3] + position.y } })
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
surface.set_tiles(tiles)
|
|
220
|
+
|
|
221
|
+
local area = {
|
|
222
|
+
{ position.x - radius, position.y - radius },
|
|
223
|
+
{ position.x + radius, position.y + radius },
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
-- Remove warp structure entities
|
|
227
|
+
local entities = surface.find_entities_filtered{ force = "neutral", area = area, name = remove_warp_area_entity_names }
|
|
228
|
+
for _, entity in pairs(entities) do
|
|
229
|
+
-- Destroy them, this will leave corpses of the entities that it destroyed.
|
|
230
|
+
if entity and entity.valid and entity.destructible == false then
|
|
231
|
+
entity.destructible = true
|
|
232
|
+
entity.die(entity.force)
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
-- Rechart map area, useful if warp is not covered by a radar
|
|
237
|
+
game.forces[warp.force_name].chart(surface, area)
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
--[[-- Set a warp to be the spawn point for a force, force must own this warp
|
|
241
|
+
@tparam string warp_id the uid of the warp that you want to be the spawn for the force
|
|
242
|
+
@tparam LuaForce force the force that you want to set the spawn for
|
|
243
|
+
|
|
244
|
+
@usage-- Set your forces spawn to a warp
|
|
245
|
+
Warps.set_spawn_warp(warp_id, game.player.force)
|
|
246
|
+
|
|
247
|
+
]]
|
|
248
|
+
function Warps.set_spawn_warp(warp_id, force)
|
|
249
|
+
-- Check the force owns this warp
|
|
250
|
+
local warp = WrapData:get(warp_id)
|
|
251
|
+
if warp.force_name ~= force.name then
|
|
252
|
+
return
|
|
253
|
+
end
|
|
254
|
+
-- Set this warp as the spawn
|
|
255
|
+
local warp_ids = force_warps[warp.force_name]
|
|
256
|
+
if not warp_ids then
|
|
257
|
+
warp_ids = {}
|
|
258
|
+
force_warps[warp.force_name] = warp_ids
|
|
259
|
+
end
|
|
260
|
+
warp_ids.spawn = warp_id
|
|
261
|
+
-- Set the forces spawn to this warp
|
|
262
|
+
force.set_spawn_position(warp.position, warp.surface)
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
--[[-- Teleport a player to a warp point
|
|
266
|
+
@tparam string warp_id the uid of the warp to send the player to
|
|
267
|
+
@tparam LuaPlayer player the player to teleport to the warp
|
|
268
|
+
|
|
269
|
+
@usage-- Teleport yourself to a warp point
|
|
270
|
+
Warps.teleport_player(warp_id, game.player)
|
|
271
|
+
|
|
272
|
+
]]
|
|
273
|
+
function Warps.teleport_player(warp_id, player)
|
|
274
|
+
local warp = WrapData:get(warp_id)
|
|
275
|
+
local surface = warp.surface
|
|
276
|
+
local position = {
|
|
277
|
+
x = warp.position.x + 0.5,
|
|
278
|
+
y = warp.position.y + 0.5,
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if player.vehicle then
|
|
282
|
+
-- Teleport the entity
|
|
283
|
+
local entity = player.vehicle
|
|
284
|
+
local goto_position = surface.find_non_colliding_position(entity.name, position, 32, 1)
|
|
285
|
+
-- Surface teleport can only be done for players and cars at the moment. (with surface as an peramitor it gives this error)
|
|
286
|
+
if entity.type == "car" then
|
|
287
|
+
entity.teleport(goto_position, surface)
|
|
288
|
+
elseif surface.index == entity.surface.index then
|
|
289
|
+
-- Try teleport the entity
|
|
290
|
+
if not entity.teleport(goto_position) then
|
|
291
|
+
player.driving = false
|
|
292
|
+
-- Need to calculate new goto_position because entities have different collision boxes
|
|
293
|
+
goto_position = surface.find_non_colliding_position("character", position, 32, 1)
|
|
294
|
+
player.teleport(goto_position, surface)
|
|
295
|
+
end
|
|
296
|
+
end
|
|
297
|
+
else
|
|
298
|
+
-- Teleport the player
|
|
299
|
+
local goto_position = surface.find_non_colliding_position("character", position, 32, 1)
|
|
300
|
+
if player.driving then player.driving = false end
|
|
301
|
+
player.teleport(goto_position, surface)
|
|
302
|
+
end
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
--- Setters.
|
|
306
|
+
-- functions used to created and alter warps
|
|
307
|
+
-- @section setters
|
|
308
|
+
|
|
309
|
+
--[[-- Add a new warp for a force, the warp must have a surface and a position
|
|
310
|
+
@tparam string force_name the name of the force to add the warp for
|
|
311
|
+
@tparam LuaSurface surface the surface that the warp will be on
|
|
312
|
+
@tparam Concepts.Position position the position that the warp will be on
|
|
313
|
+
@tparam[opt] string player_name the name of the player that is adding the warp
|
|
314
|
+
@tparam[opt] string warp_name the name of the warp that is being added, if omited default is used
|
|
315
|
+
@treturn string the uid of the warp which was created
|
|
316
|
+
|
|
317
|
+
@usage-- Adding a new warp for your force at your position
|
|
318
|
+
local player = game.player
|
|
319
|
+
local warp_id = Warps.add_warp(player.force.name, player.physical_surface, player.physical_position, player.name)
|
|
320
|
+
|
|
321
|
+
]]
|
|
322
|
+
function Warps.add_warp(force_name, surface, position, player_name, warp_name)
|
|
323
|
+
-- Get new warp id
|
|
324
|
+
local warp_id = tostring(force_warps._uid)
|
|
325
|
+
force_warps._uid = force_warps._uid + 1
|
|
326
|
+
warp_name = warp_name or "New warp"
|
|
327
|
+
|
|
328
|
+
-- Get the existing warps for this force
|
|
329
|
+
local warp_ids = force_warps[force_name]
|
|
330
|
+
if not warp_ids then
|
|
331
|
+
warp_ids = {}
|
|
332
|
+
force_warps[force_name] = warp_ids
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
-- Insert the warp id into the force warps
|
|
336
|
+
table.insert(warp_ids, warp_id)
|
|
337
|
+
|
|
338
|
+
-- Create the editing table
|
|
339
|
+
local editing = {}
|
|
340
|
+
if player_name then
|
|
341
|
+
editing[player_name] = true
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
-- Add the new warp to the store
|
|
345
|
+
WrapData:set(warp_id, {
|
|
346
|
+
warp_id = warp_id,
|
|
347
|
+
force_name = force_name,
|
|
348
|
+
name = warp_name,
|
|
349
|
+
icon = { type = config.default_icon.type, name = config.default_icon.name },
|
|
350
|
+
surface = surface,
|
|
351
|
+
position = {
|
|
352
|
+
x = math.floor(position.x),
|
|
353
|
+
y = math.floor(position.y),
|
|
354
|
+
},
|
|
355
|
+
last_edit_name = player_name or "<server>",
|
|
356
|
+
last_edit_time = game.tick,
|
|
357
|
+
currently_editing = editing,
|
|
358
|
+
updates = 0,
|
|
359
|
+
})
|
|
360
|
+
|
|
361
|
+
return warp_id
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
--[[-- Removes a warp and any data linked to it
|
|
365
|
+
@tparam string warp_id the uid of the warp that you want to remove
|
|
366
|
+
|
|
367
|
+
@usage-- Removing a warp
|
|
368
|
+
Warps.remove_warp(warp_id)
|
|
369
|
+
|
|
370
|
+
]]
|
|
371
|
+
function Warps.remove_warp(warp_id)
|
|
372
|
+
local warp = WrapData:get(warp_id)
|
|
373
|
+
local force_name = warp.force_name
|
|
374
|
+
Warps.remove_warp_tag(warp_id)
|
|
375
|
+
Warps.remove_warp_area(warp_id)
|
|
376
|
+
WrapData:remove(warp_id)
|
|
377
|
+
table.remove_element(force_warps[force_name], warp_id)
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
--[[-- Update the name and icon for a warp
|
|
381
|
+
@tparam string warp_id the uid of the warp that you want to update
|
|
382
|
+
@tparam[opt] string new_name the new name that you want the warp to have
|
|
383
|
+
@tparam[opt] string new_icon the new icon that you want the warp to have
|
|
384
|
+
@tparam[opt='server'] string player_name the name of the player that made the edit
|
|
385
|
+
|
|
386
|
+
@usage-- Changing the name and icon for a warp
|
|
387
|
+
Warps.update_warp(warp_id, 'My Warp', 'iron-plate', game.player.name)
|
|
388
|
+
|
|
389
|
+
]]
|
|
390
|
+
function Warps.update_warp(warp_id, new_name, new_icon, player_name)
|
|
391
|
+
WrapData:update(warp_id, function(_, warp)
|
|
392
|
+
-- If the icon is not valid then replace with the old icon
|
|
393
|
+
if new_icon and not new_icon.name or not new_icon.type then
|
|
394
|
+
new_icon = warp.icon
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
warp.last_edit_name = player_name or "<server>"
|
|
398
|
+
warp.last_edit_time = game.tick
|
|
399
|
+
warp.name = new_name or warp.name
|
|
400
|
+
warp.icon = new_icon or warp.icon
|
|
401
|
+
end)
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
--[[-- Set the editing state for a player, can be used as a warning or to display a text field
|
|
405
|
+
@tparam string warp_id the uid of the warp that you want to effect
|
|
406
|
+
@tparam string player_name the name of the player you want to set the state for
|
|
407
|
+
@tparam boolean state the new state to set editing to
|
|
408
|
+
|
|
409
|
+
@usage-- Setting your editing state to true
|
|
410
|
+
Warps.set_editing(warp_id, game.player.name, true)
|
|
411
|
+
|
|
412
|
+
]]
|
|
413
|
+
function Warps.set_editing(warp_id, player_name, state)
|
|
414
|
+
WrapData:update(warp_id, function(_, warp)
|
|
415
|
+
warp.currently_editing[player_name] = state
|
|
416
|
+
end)
|
|
417
|
+
end
|
|
418
|
+
|
|
419
|
+
--[[-- Adds an update handler for when a warp is added, removed, or updated
|
|
420
|
+
@tparam function handler the handler which is called when a warp is updated
|
|
421
|
+
|
|
422
|
+
@usage-- Add a game print when a warp is updated
|
|
423
|
+
Warps.on_update(function(warp)
|
|
424
|
+
game.print(warp.force_name..' now has the warp: '..warp.name)
|
|
425
|
+
end)
|
|
426
|
+
|
|
427
|
+
]]
|
|
428
|
+
function Warps.on_update(handler)
|
|
429
|
+
WrapData:on_update(handler)
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
--- Getters.
|
|
433
|
+
-- function used to get information about warps
|
|
434
|
+
-- @section getters
|
|
435
|
+
|
|
436
|
+
--[[-- Gets the warp information that is linked with this id
|
|
437
|
+
@tparam string warp_id the uid of the warp you want to get
|
|
438
|
+
@treturn table the warp information
|
|
439
|
+
|
|
440
|
+
@usage-- Getting warp information outside of on_update
|
|
441
|
+
local warp = Warps.get_warp(warp_id)
|
|
442
|
+
|
|
443
|
+
]]
|
|
444
|
+
function Warps.get_warp(warp_id)
|
|
445
|
+
return WrapData:get(warp_id)
|
|
446
|
+
end
|
|
447
|
+
|
|
448
|
+
--[[-- Gets all the warp ids that a force has
|
|
449
|
+
@tparam string force_name the name of the force that you want the warp ids for
|
|
450
|
+
@treturn table an array of all the warp ids
|
|
451
|
+
|
|
452
|
+
@usage-- Getting the warp ids for a force
|
|
453
|
+
local warp_ids = Warps.get_force_warp_ids(game.player.force.name)
|
|
454
|
+
|
|
455
|
+
]]
|
|
456
|
+
function Warps.get_force_warp_ids(force_name)
|
|
457
|
+
return force_warps[force_name] or {}
|
|
458
|
+
end
|
|
459
|
+
|
|
460
|
+
--[[-- Get the id of the spawn warp
|
|
461
|
+
@tparam string force_name the name of the force that you want to get the spawn warp for
|
|
462
|
+
@treturn ?string|nil the uid of the spawn warp for this force if there is one
|
|
463
|
+
|
|
464
|
+
@usage-- Getting the spawn warp id
|
|
465
|
+
local spawn_id = Warps.get_spawn_warp_id(game.player.force.name)
|
|
466
|
+
|
|
467
|
+
]]
|
|
468
|
+
function Warps.get_spawn_warp_id(force_name)
|
|
469
|
+
local warp_ids = force_warps[force_name] or {}
|
|
470
|
+
return warp_ids.spawn
|
|
471
|
+
end
|
|
472
|
+
|
|
473
|
+
--[[-- Gets the editing state for a player
|
|
474
|
+
@tparam string warp_id the uid of the warp you want to check
|
|
475
|
+
@tparam string player_name the name of the player that you want to check
|
|
476
|
+
@treturn boolean weather the player is currently editing this warp
|
|
477
|
+
|
|
478
|
+
@usage-- Check if a player is editing a warp or not
|
|
479
|
+
local editing = Warps.get_editing(warp_id, game.player.name)
|
|
480
|
+
|
|
481
|
+
]]
|
|
482
|
+
function Warps.get_editing(warp_id, player_name)
|
|
483
|
+
local warp = WrapData:get(warp_id)
|
|
484
|
+
return warp.currently_editing[player_name]
|
|
485
|
+
end
|
|
486
|
+
|
|
487
|
+
-- Module return
|
|
488
|
+
return Warps
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
--- Stores if you use alt mode or not and auto applies it
|
|
2
|
+
-- @data Alt-View
|
|
3
|
+
|
|
4
|
+
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
|
5
|
+
|
|
6
|
+
--- Stores the visible state of alt mode
|
|
7
|
+
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
|
|
8
|
+
local UsesAlt = PlayerData.Settings:combine("UsesAlt")
|
|
9
|
+
UsesAlt:set_default(false)
|
|
10
|
+
UsesAlt:set_metadata{
|
|
11
|
+
stringify = function(value) return value and "Visible" or "Hidden" end,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
--- When your data loads apply alt view if you have it enabled
|
|
15
|
+
UsesAlt:on_load(function(player_name, uses_alt)
|
|
16
|
+
local player = game.players[player_name]
|
|
17
|
+
if uses_alt ~= nil then
|
|
18
|
+
player.game_view_settings.show_entity_info = uses_alt
|
|
19
|
+
end
|
|
20
|
+
end)
|
|
21
|
+
|
|
22
|
+
--- When alt view is toggled update this
|
|
23
|
+
Event.add(defines.events.on_player_toggled_alt_mode, function(event)
|
|
24
|
+
local player = game.players[event.player_index]
|
|
25
|
+
UsesAlt:set(player, player.game_view_settings.show_entity_info)
|
|
26
|
+
end)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
--- Greets players on join
|
|
2
|
+
-- @data Greetings
|
|
3
|
+
|
|
4
|
+
local config = require("modules.exp_legacy.config.join_messages") --- @dep config.join_messages
|
|
5
|
+
local Commands = require("modules/exp_commands")
|
|
6
|
+
|
|
7
|
+
--- Stores the join message that the player have
|
|
8
|
+
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
|
|
9
|
+
local CustomMessages = PlayerData.Settings:combine("JoinMessage")
|
|
10
|
+
CustomMessages:set_metadata{
|
|
11
|
+
permission = "exp_scenario.command.set_join_message",
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
--- When a players data loads show their message
|
|
15
|
+
CustomMessages:on_load(function(player_name, player_message)
|
|
16
|
+
local player = game.players[player_name]
|
|
17
|
+
local custom_message = player_message or config[player_name]
|
|
18
|
+
if custom_message then
|
|
19
|
+
game.print(custom_message, { color = player.color })
|
|
20
|
+
else
|
|
21
|
+
player.print{ "join-message.greet", { "links.discord" } }
|
|
22
|
+
end
|
|
23
|
+
end)
|
|
24
|
+
|
|
25
|
+
--- Set your custom join message
|
|
26
|
+
Commands.new("set-join-message", { "join-message.description-add" })
|
|
27
|
+
:optional("message", false, Commands.types.string_max_length(255))
|
|
28
|
+
:enable_auto_concatenation()
|
|
29
|
+
:add_aliases{ "join-message" }
|
|
30
|
+
:register(function(player, message)
|
|
31
|
+
--- @cast message string?
|
|
32
|
+
if message then
|
|
33
|
+
CustomMessages:set(player, message)
|
|
34
|
+
return Commands.status.success{ "join-message.message-set" }
|
|
35
|
+
else
|
|
36
|
+
return Commands.status.success{ "join-message.message-get", CustomMessages:get(player) }
|
|
37
|
+
end
|
|
38
|
+
end)
|
|
39
|
+
|
|
40
|
+
--- Removes your custom join message
|
|
41
|
+
Commands.new("remove-join-message", { "join-message.description-remove" })
|
|
42
|
+
:register(function(player)
|
|
43
|
+
CustomMessages:remove(player)
|
|
44
|
+
return Commands.status.success{ "join-message.message-cleared" }
|
|
45
|
+
end)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
--- Stores the language used to join the server
|
|
2
|
+
-- @data Language
|
|
3
|
+
|
|
4
|
+
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
|
5
|
+
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
|
|
6
|
+
local LocalLanguage = PlayerData.Statistics:combine("LocalLanguage")
|
|
7
|
+
LocalLanguage:set_default("Unknown")
|
|
8
|
+
LocalLanguage:set_metadata{
|
|
9
|
+
name = { "exp-statistics.Locale" },
|
|
10
|
+
tooltip = { "exp-statistics.Locale-tooltip" },
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
local function set_locale(event)
|
|
14
|
+
local player = game.players[event.player_index]
|
|
15
|
+
LocalLanguage:set(player, player.locale)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
--- Set the players language when they join and change language
|
|
19
|
+
Event.add(defines.events.on_player_created, set_locale)
|
|
20
|
+
Event.add(defines.events.on_player_joined_game, set_locale)
|
|
21
|
+
Event.add(defines.events.on_player_locale_changed, set_locale)
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
--- Gives players random colours when they join, also applies preset colours to those who have them
|
|
2
|
+
-- @data Player-Colours
|
|
3
|
+
|
|
4
|
+
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
|
5
|
+
local Colours = require("modules/exp_util/include/color")
|
|
6
|
+
local config = require("modules.exp_legacy.config.preset_player_colours") --- @dep config.preset_player_colours
|
|
7
|
+
|
|
8
|
+
--- Stores the colour that the player wants
|
|
9
|
+
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
|
|
10
|
+
local PlayerColours = PlayerData.Settings:combine("Colour")
|
|
11
|
+
PlayerColours:set_metadata{
|
|
12
|
+
stringify = function(value)
|
|
13
|
+
if not value then return "None set" end
|
|
14
|
+
local c = value[1]
|
|
15
|
+
return string.format("Red: %d Green: %d Blue: %d", c[1], c[2], c[3])
|
|
16
|
+
end,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
--- Used to compact player colours to take less space
|
|
20
|
+
local floor = math.floor
|
|
21
|
+
local function compact(colour)
|
|
22
|
+
return {
|
|
23
|
+
floor(colour.r * 255),
|
|
24
|
+
floor(colour.g * 255),
|
|
25
|
+
floor(colour.b * 255),
|
|
26
|
+
}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
--- Returns a colour that is a bit lighter than the one given
|
|
30
|
+
local function lighten(c)
|
|
31
|
+
return { r = 255 - (255 - c.r) * 0.5, g = 255 - (255 - c.g) * 0.5, b = 255 - (255 - c.b) * 0.5, a = 255 }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
--- When your data loads apply the players colour, or a random on if none is saved
|
|
35
|
+
PlayerColours:on_load(function(player_name, player_colour)
|
|
36
|
+
if not player_colour then
|
|
37
|
+
local preset = config.players[player_name]
|
|
38
|
+
if preset then
|
|
39
|
+
player_colour = { preset, lighten(preset) }
|
|
40
|
+
else
|
|
41
|
+
local colour_name = "white"
|
|
42
|
+
while config.disallow[colour_name] do
|
|
43
|
+
colour_name = table.get_random(Colours, true)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
player_colour = { Colours[colour_name], lighten(Colours[colour_name]) }
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
local player = game.players[player_name]
|
|
51
|
+
player.color = player_colour[1]
|
|
52
|
+
player.chat_color = player_colour[2]
|
|
53
|
+
end)
|
|
54
|
+
|
|
55
|
+
--- Save the players color when they use the color command
|
|
56
|
+
Event.add(defines.events.on_console_command, function(event)
|
|
57
|
+
if event.command ~= "color" then return end
|
|
58
|
+
if event.parameters == "" then return end
|
|
59
|
+
if not event.player_index then return end
|
|
60
|
+
local player = game.players[event.player_index]
|
|
61
|
+
if not player or not player.valid then return end
|
|
62
|
+
PlayerColours:set(player, { compact(player.color), compact(player.chat_color) })
|
|
63
|
+
end)
|