Compare commits

...
Author SHA1 Message Date
Hornwitser ccb07d6eab 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.
2020-04-06 14:41:51 +02:00
5 changed files with 39 additions and 5 deletions

No files matched your search

+2
View File
@@ -6,6 +6,8 @@ before_install:
- tar -xf factorio.tar.gz - tar -xf factorio.tar.gz
- npm install -g codecov - npm install -g codecov
script: 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 - npm run-script ci-cover
- cat temp/test/integration/log.txt - cat temp/test/integration/log.txt
- codecov -f coverage/lcov.info - codecov -f coverage/lcov.info
+16
View File
@@ -23,12 +23,24 @@ async function main() {
'build': { describe: "Build mod", type: 'boolean', default: true }, 'build': { describe: "Build mod", type: 'boolean', default: true },
'pack': { describe: "Pack into zip file", 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" }, '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 .argv
; ;
let info = JSON.parse(await fs.readFile(path.join(sourceDir, "info.json"))); 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) { if (args.clean) {
let splitter = /^(.*)_(\d+\.\d+\.\d+)(\.zip)?$/ let splitter = /^(.*)_(\d+\.\d+\.\d+)(\.zip)?$/
for (let entry of await fs.readdir(args.outputDir)) { 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, 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`); let modPath = path.join(args.outputDir, `${modName}.zip`);
console.log(`Writing ${modPath}`); console.log(`Writing ${modPath}`);
let writeStream = zip.generateNodeStream().pipe(fs.createWriteStream(modPath)); let writeStream = zip.generateNodeStream().pipe(fs.createWriteStream(modPath));
@@ -83,6 +97,8 @@ async function main() {
for (let filePath of additionalFiles) { for (let filePath of additionalFiles) {
await fs.copy(filePath, path.join(modDir, path.basename(filePath))); 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 Version: 0.1.0
Major Features: Major Features:
- API for mods to interact with Clusterio - API for mods to interact with Clusterio
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "clusterio_lib", "name": "clusterio_lib",
"version": "0.1.0", "version": "0.1.1",
"title": "Clusterio Library (Alpha)", "title": "Clusterio Library (Alpha)",
"author": "Clusterio Team", "author": "Clusterio Team",
"homepage": "https://github.com/clusterio/factorioClusterio", "homepage": "https://github.com/clusterio/factorioClusterio",
+16 -4
View File
@@ -2,6 +2,18 @@
-- Based on code from playerManager and trainTeleports -- Based on code from playerManager and trainTeleports
local serialize = {} 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 -- Equipment Grids are serialized into an array of equipment entries
-- where ench entry is a table with the following fields: -- where ench entry is a table with the following fields:
-- n: name -- n: name
@@ -181,8 +193,8 @@ end
-- It's also possible that the slot is empty but has a slot filter. -- It's also possible that the slot is empty but has a slot filter.
function serialize.serialize_inventory(inventory) function serialize.serialize_inventory(inventory)
local serialized = {} local serialized = {}
if inventory.hasbar() and inventory.getbar() <= #inventory then if inventory[supports_bar]() and inventory[get_bar]() <= #inventory then
serialized.b = inventory.getbar() serialized.b = inventory[get_bar]()
end end
serialized.i = {} serialized.i = {}
@@ -227,8 +239,8 @@ function serialize.serialize_inventory(inventory)
end end
function serialize.deserialize_inventory(inventory, serialized) function serialize.deserialize_inventory(inventory, serialized)
if serialized.b and inventory.hasbar() then if serialized.b and inventory[supports_bar]() then
inventory.setbar(serialized.b) inventory[set_bar](serialized.b)
end end
local last_slot_index = 0 local last_slot_index = 0