Add support for Factorio 0.18.x

Add option to bump patch number and override factorio_version in the
generated mod and update the serialize library to support the inventory
bar access methods of both 0.17 and 0.18.
This commit is contained in:
Hornwitser committed 2020-04-06 14:41:51 +02:00
1 parent 75cd6d38db
commit ccb07d6eab
5 files changed
+39 -5

No files matched your search

+2
View File
@@ -6,6 +6,8 @@ before_install:
- tar -xf factorio.tar.gz
- npm install -g codecov
script:
- node build-mod --bump-patch --factorio-version 0.18 --output-dir sharedMods
- curl -o sharedMods/subspace_storage_1.99.1.zip -L https://github.com/clusterio/factorioClusterioMod/releases/download/1.99.1/subspace_storage_1.99.1.zip
- npm run-script ci-cover
- cat temp/test/integration/log.txt
- codecov -f coverage/lcov.info
+16
View File
@@ -23,12 +23,24 @@ async function main() {
'build': { describe: "Build mod", type: 'boolean', default: true },
'pack': { describe: "Pack into zip file", type: 'boolean', default: true },
'output-dir': { describe: "Path to output built mod", nargs: 1, type: 'string', default: "dist" },
"bump-patch": { describe: "Increment patch number of build", type: "boolean", default: false },
"factorio-version": { describe: "Override factorio_version", type: "string" },
})
.argv
;
let info = JSON.parse(await fs.readFile(path.join(sourceDir, "info.json")));
if (args.bumpPatch) {
let [major, minor, patch] = info.version.split(".");
patch = String(Number.parseInt(patch, 10) + 1);
info.version = [major, minor, patch].join(".");
}
if (args.factorioVersion) {
info.factorio_version = args.factorioVersion;
}
if (args.clean) {
let splitter = /^(.*)_(\d+\.\d+\.\d+)(\.zip)?$/
for (let entry of await fs.readdir(args.outputDir)) {
@@ -67,6 +79,8 @@ async function main() {
zip.file(path.posix.join(modName, path.basename(filePath)), fs.createReadStream(filePath));
}
zip.file(path.posix.join(modName, "info.json"), JSON.stringify(info, null, 4));
let modPath = path.join(args.outputDir, `${modName}.zip`);
console.log(`Writing ${modPath}`);
let writeStream = zip.generateNodeStream().pipe(fs.createWriteStream(modPath));
@@ -83,6 +97,8 @@ async function main() {
for (let filePath of additionalFiles) {
await fs.copy(filePath, path.join(modDir, path.basename(filePath)));
}
await fs.writeFile(path.join(modDir, "info.json"), JSON.stringify(info, null, 4));
}
}
}
+4
View File
@@ -1,4 +1,8 @@
---------------------------------------------------------------------------------------------------
Version: 0.1.1
Features:
- Added support for Factorio 0.18.x
---------------------------------------------------------------------------------------------------
Version: 0.1.0
Major Features:
- API for mods to interact with Clusterio
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "clusterio_lib",
"version": "0.1.0",
"version": "0.1.1",
"title": "Clusterio Library (Alpha)",
"author": "Clusterio Team",
"homepage": "https://github.com/clusterio/factorioClusterio",
+16 -4
View File
@@ -2,6 +2,18 @@
-- Based on code from playerManager and trainTeleports
local serialize = {}
-- 0.17 compatibility
local supports_bar, get_bar, has_bar
if (pcall(function() local mods = script.active_mods end)) then
supports_bar = "supports_bar"
get_bar = "get_bar"
set_bar = "set_bar"
else
supports_bar = "hasbar"
get_bar = "getbar"
set_bar = "setbar"
end
-- Equipment Grids are serialized into an array of equipment entries
-- where ench entry is a table with the following fields:
-- n: name
@@ -181,8 +193,8 @@ end
-- It's also possible that the slot is empty but has a slot filter.
function serialize.serialize_inventory(inventory)
local serialized = {}
if inventory.hasbar() and inventory.getbar() <= #inventory then
serialized.b = inventory.getbar()
if inventory[supports_bar]() and inventory[get_bar]() <= #inventory then
serialized.b = inventory[get_bar]()
end
serialized.i = {}
@@ -227,8 +239,8 @@ function serialize.serialize_inventory(inventory)
end
function serialize.deserialize_inventory(inventory, serialized)
if serialized.b and inventory.hasbar() then
inventory.setbar(serialized.b)
if serialized.b and inventory[supports_bar]() then
inventory[set_bar](serialized.b)
end
local last_slot_index = 0