Add on_server_startup event

Add startup event to the Clusterio module API which is raised at startup
of a Factorio server.  This is to server as a replacement for the
on_init and on_configuration_changed events which cannot be used in
modules.

Adds clusterio_patch_number global from the patcher in order to
implement this.  This is a number that's incremented every time the save
is patched.
This commit is contained in:
Hornwitser committed 2020-01-05 23:19:34 +01:00
1 parent b8fb73f863
commit 892c803496
6 files changed
+46 -9

No files matched your search

+4
View File
@@ -65,6 +65,7 @@ function generateLoader(patchInfo) {
let lines = [
'-- Auto generated scenario module loader created by Clusterio',
'-- Modifications to this file will be lost when loaded in Clusterio',
`clusterio_patch_number = ${patchInfo.patch_number}`,
'',
'local event_handler = require("event_handler")',
'',
@@ -226,6 +227,9 @@ async function patch(savePath, modules) {
}
}
// Increment patch number
patchInfo["patch_number"] = (patchInfo["patch_number"] || 0) + 1;
// Remove any existing modules from the save
patchInfo["modules"] = [];
for (let file of root.file(/^modules\//)) {