Skip to content

Commit 42cedc9

Browse files
committed
Update to 0.2.4
1 parent d6c0161 commit 42cedc9

File tree

11 files changed

+170
-34
lines changed

11 files changed

+170
-34
lines changed

changelog.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
---------------------------------------------------------------------------------------------------
2+
Version: 0.2.4
3+
Date: 2021-06-18
4+
Changes:
5+
- Added example scenario
6+
- Changed examples slightly
7+
---------------------------------------------------------------------------------------------------
28
Version: 0.2.3
39
Date: 2021-06-18
410
Changes:

control.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ local modules = {}
88
modules.command_wrapper = require("models/command-wrapper/control")
99
modules.example_module = require("models/example-module")
1010
-- modules.empty_module = require("models.empty-module")
11-
-- modules.stop_another_script_example = require("models/stop-another-script-example")
1211

1312

1413
-- Safe disabling of this mod remotely on init stage

defines.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Change everything in this file in your mod!
22

33
MOD_NAME = "example-mod"
4-
MOD_PATH = "__" .. MOD_NAME .. "__"
4+
MOD_PATH = "__example-mod__"
55

66
-- Don't use symbols like '-' etc (it'll break pattern of regular expressions)
77
MOD_SHORT_NAME = "em_"

info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "example-mod",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"factorio_version": "1.1",
55
"title": "Example mod",
66
"author": "Put your nickname",

models/command-wrapper/control.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ local module = {}
88

99

1010
local MAX_INPUT_LENGTH = 500 -- set any number
11-
local CONST_COMMANDS = require("const-commands")
12-
local SWITCHABLE_COMMANDS = require("switchable-commands")
11+
local CONST_COMMANDS = require(MOD_PATH .. "/const-commands")
12+
local SWITCHABLE_COMMANDS = require(MOD_PATH .. "/switchable-commands")
1313

1414

1515
---@param s string

models/empty-module.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ module.update_global_data_on_disabling = update_global_data -- for safe disablin
5454
--#endregion
5555

5656

57-
---@type table<number, function>
58-
-- All events of https://lua-api.factorio.com/latest/events.html#All%20events except on_nth_tick
57+
---@type table<number|string, function>
5958
-- [optional]
59+
-- All events of https://lua-api.factorio.com/latest/events.html#All%20events except on_nth_tick
6060
module.events = {
6161
--[defines.events.on_game_created_from_scenario] = on_game_created_from_scenario,
6262
--[defines.events.on_gui_click] = on_gui_click,

models/example-module.lua

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,6 @@ local function on_player_created(event)
2121
player.print("Events of example mod works fine")
2222
end
2323

24-
local function on_game_created_from_scenario(event)
25-
-- ########
26-
-- Some examples of code what you can do with this event below
27-
-- Some interaction with game ignores (i.q: game.print("loaded scenario"))
28-
-- ########
29-
30-
-- disable_recipes()
31-
32-
-- if global.biters_destination == nil then
33-
-- local target = game.get_entity_by_tag("target")
34-
-- global.biters_destination = target.position
35-
-- biters_destination = global.biters_destination
36-
-- if global.target_id == nil and target then
37-
-- global.target_id = script.register_on_entity_destroyed(target)
38-
-- end
39-
-- end
40-
41-
-- local biters_spawn
42-
-- biters_spawn = game.get_entity_by_tag("biters_spawn_1")
43-
-- global.biters_spawn_position_1 = global.biters_spawn_position_1 or biters_spawn.position
44-
-- biters_spawn_position_1 = global.biters_spawn_position_1
45-
end
46-
4724
--#endregion
4825

4926

@@ -104,11 +81,11 @@ module.update_global_data_on_disabling = update_global_data -- for safe disablin
10481
--#endregion
10582

10683

107-
---@type table<number, function>
84+
---@type table<number|string, function>
10885
-- [optional]
10986
-- All events of https://lua-api.factorio.com/latest/events.html#All%20events except on_nth_tick
11087
module.events = {
111-
[defines.events.on_game_created_from_scenario] = on_game_created_from_scenario,
88+
-- [defines.events.on_game_created_from_scenario] = on_game_created_from_scenario,
11289
-- [defines.events.on_gui_click] = on_gui_click,
11390
[defines.events.on_player_created] = on_player_created,
11491
-- [defines.events.on_player_joined_game] = on_player_joined_game,

scenarios/example/control.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
require("__example-mod__/defines")
3+
local event_handler = require("event_handler")
4+
local modules = {}
5+
modules.command_wrapper = require(MOD_PATH .. "/models/command-wrapper/control")
6+
modules.example_module = require("models/example-module")
7+
modules.stop_example_mod = require("models/stop-example-mod")
8+
9+
10+
modules.command_wrapper.handle_custom_commands(modules.example_module) -- adds commands
11+
12+
event_handler.add_libraries(modules)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
scenario-name=[color=orange]example[/color]
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
2+
local module = {}
3+
4+
5+
--#region Global data
6+
local players_data
7+
--#endregion
8+
9+
10+
--#region Constants
11+
local ABS = math.abs
12+
--#endregion
13+
14+
15+
--#region Functions of events
16+
17+
local function on_player_created(event)
18+
local player = game.get_player(event.player_index)
19+
if not (player and player.valid) then return end
20+
21+
player.print("Events of example scenario works fine. Also, scripts of example mod has been disabled!")
22+
end
23+
24+
local function on_game_created_from_scenario(event)
25+
-- ########
26+
-- Some examples of code what you can do with this event below
27+
-- Some interaction with game ignores (i.q: game.print("loaded scenario"))
28+
-- ########
29+
30+
-- disable_recipes()
31+
32+
-- if global.biters_destination == nil then
33+
-- local target = game.get_entity_by_tag("target")
34+
-- global.biters_destination = target.position
35+
-- biters_destination = global.biters_destination
36+
-- if global.target_id == nil and target then
37+
-- global.target_id = script.register_on_entity_destroyed(target)
38+
-- end
39+
-- end
40+
41+
-- local biters_spawn
42+
-- biters_spawn = game.get_entity_by_tag("biters_spawn_1")
43+
-- global.biters_spawn_position_1 = global.biters_spawn_position_1 or biters_spawn.position
44+
-- biters_spawn_position_1 = global.biters_spawn_position_1
45+
end
46+
47+
--#endregion
48+
49+
50+
--#region Commands
51+
52+
local function delete_example_UI_command(cmd)
53+
if cmd.player_index == 0 then -- server
54+
print("Deleted UIs")
55+
else
56+
local player = game.get_player(cmd.player_index)
57+
if not player.admin then
58+
player.print({"command-output.parameters-require-admin"})
59+
return
60+
end
61+
player.print("Deleted UIs")
62+
end
63+
64+
for _, player in pairs(game.players) do
65+
if player.valid then
66+
-- destroy_UIs(player)
67+
end
68+
end
69+
end
70+
71+
--#endregion
72+
73+
74+
--#region Pre-game stage
75+
76+
local function link_data()
77+
players_data = global.players
78+
end
79+
80+
local function update_global_data()
81+
global.players = global.players or {}
82+
83+
for player_index, player in pairs(game.players) do
84+
-- delete UIs
85+
end
86+
end
87+
88+
89+
module.on_init = (function()
90+
update_global_data()
91+
link_data()
92+
end)
93+
94+
module.on_load = (function()
95+
link_data()
96+
end)
97+
98+
module.on_configuration_changed = (function()
99+
update_global_data()
100+
link_data()
101+
end)
102+
module.update_global_data_on_disabling = update_global_data -- for safe disabling of this mod
103+
104+
--#endregion
105+
106+
107+
---@type table<number|string, function>
108+
-- [optional]
109+
-- All events of https://lua-api.factorio.com/latest/events.html#All%20events except on_nth_tick
110+
module.events = {
111+
[defines.events.on_game_created_from_scenario] = on_game_created_from_scenario,
112+
-- [defines.events.on_gui_click] = on_gui_click,
113+
[defines.events.on_player_created] = on_player_created,
114+
-- [defines.events.on_player_joined_game] = on_player_joined_game,
115+
-- [defines.events.on_player_left_game] = on_player_left_game,
116+
-- [defines.events.on_player_removed] = delete_player_data,
117+
-- [defines.events.on_player_changed_surface] = clear_player_data,
118+
-- [defines.events.on_player_respawned] = clear_player_data,
119+
-- [defines.events.on_gui_value_changed] = on_gui_value_changed, -- please, don't use it. It impacts UPS significantly
120+
}
121+
122+
---@type table<number, function>
123+
-- [optional]
124+
-- module.on_nth_tick = {
125+
-- [50] = function()
126+
-- for player_index, _ in pairs(game.connected_players) do
127+
-- pcall(update_stuff, player_index)
128+
-- end
129+
-- end,
130+
-- }
131+
132+
133+
---@type table<string, function>
134+
-- [optional]
135+
-- Check "command-wrapper" folder
136+
module.commands = {
137+
delete_example_UI = delete_example_UI_command,
138+
}
139+
140+
141+
return module

0 commit comments

Comments
 (0)