From ccb07d6eab2a42fdaec9797f95f142a1ec0ea82f Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Mon, 6 Apr 2020 14:41:51 +0200 Subject: [PATCH] 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. --- .travis.yml | 2 ++ build-mod.js | 16 ++++++++++++++++ mod/changelog.txt | 4 ++++ mod/info.json | 2 +- modules/clusterio/serialize.lua | 20 ++++++++++++++++---- 5 files changed, 39 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index b915da86..89adafcb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/build-mod.js b/build-mod.js index ef47f8a4..2d1cb81d 100644 --- a/build-mod.js +++ b/build-mod.js @@ -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)); } } } diff --git a/mod/changelog.txt b/mod/changelog.txt index 50e3310e..fdce82ea 100644 --- a/mod/changelog.txt +++ b/mod/changelog.txt @@ -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 diff --git a/mod/info.json b/mod/info.json index e2c5ebe1..dd75e41f 100644 --- a/mod/info.json +++ b/mod/info.json @@ -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", diff --git a/modules/clusterio/serialize.lua b/modules/clusterio/serialize.lua index 1714e194..ee247e63 100644 --- a/modules/clusterio/serialize.lua +++ b/modules/clusterio/serialize.lua @@ -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