Implement export of item icons and locale

Add mod and command for exporting the Factorio locale including mods,
and item icons assemled into a sprite sheet including mods.
This commit is contained in:
Hornwitser committed 2020-05-26 01:11:49 +02:00
1 parent d1b851d890
commit 260f976fa3
28 files changed
+642 -247

No files matched your search

@@ -1,4 +1,4 @@
; Test data for getLocale
; Test data for exportLocale
[test]
key-a=1
key-b=2
+8 -13
View File
@@ -8,19 +8,6 @@ const { slowTest, get, exec, controlConfigPath, instancesDir } = require("./inde
describe("Integration of Clusterio", function() {
describe("master http api", function() {
describe("GET /api/getFactorioLocale", function() {
it("should get the basegame factorio locale", async function() {
let res = await get("/api/getFactorioLocale");
let object = res.body;
// test that it is looks like a factorio locale
assert.equal(typeof object, "object");
assert.equal(object["entity-name"]["fish"], "Fish");
assert.equal(object["entity-name"]["small-lamp"], "Lamp");
});
});
});
parallel("master web interface", function() {
this.timeout(6000);
@@ -71,6 +58,14 @@ describe("Integration of Clusterio", function() {
});
});
describe("export-data", function() {
it("exports the data", async function() {
slowTest(this);
await exec(`node clusterctl --config ${controlConfigPath} export-data --instance test`);
assert(await fs.exists(path.join("temp", "export.zip")), "Export was not created");
});
});
describe("start-instance", function() {
it("starts the instance", async function() {
slowTest(this);
+33
View File
@@ -0,0 +1,33 @@
const assert = require("assert").strict;
const path = require("path");
const factorio = require("lib/factorio");
describe("Integration of lib/factorio/export", function() {
describe("exportLocale()", function() {
it("returns a nested Map with base game locale information", async function() {
let writePath = path.join("temp", "test", "server");
let testServer = new factorio.FactorioServer("factorio", writePath, {});
await testServer.init();
let locale = await factorio._exportLocale(testServer, new Map(), ["base"], "en");
assert(locale instanceof Map, "locale is not a map");
assert.equal(locale.get("entity-name.fish"), "Fish");
assert.equal(locale.get("entity-name.small-lamp"), "Lamp");
let empty_keys = 0;
for (let [key, value] of locale) {
// key is always a string
assert.equal(typeof key, "string");
// Value is always a string, nearly always truthy
if (!value) {
empty_keys++;
}
assert.equal(typeof value, "string");
}
assert(empty_keys < 10, `Got unusually high amount (${empty_keys}) of empty keys`);
});
});
});
-62
View File
@@ -1,62 +0,0 @@
const assert = require("assert").strict;
const path = require("path");
const factorio = require("lib/factorio");
describe("Integration of lib/factorio/locale", function() {
describe("getLocale()", function() {
let locale;
before(async function() {
locale = await factorio.getLocale(path.join("factorio", "data"), "en");
});
it("returns a nested object with base game locale information", async function() {
assert.equal(typeof locale, "object");
assert.equal(locale["entity-name"]["fish"], "Fish");
assert.equal(locale["entity-name"]["small-lamp"], "Lamp");
let empty_keys = 0;
Object.keys(locale).forEach(key => {
// first level of the nested object is always an object
assert.equal(typeof locale[key], "object");
Object.keys(locale[key]).forEach(key2 => {
// second level of the nested object is always a string, nearly always truthy
if (!locale[key][key2]) {
empty_keys++;
}
assert.equal(typeof locale[key][key2], "string");
});
});
assert(empty_keys < 10, `Got unusually high amount (${empty_keys}) of empty keys`);
});
it("has some duplicate keys", async function() {
let arrayOfKeys = [];
// collect all keys in a single array
Object.keys(locale).forEach(key => {
arrayOfKeys.push(key);
Object.keys(locale[key]).forEach(key2 => {
arrayOfKeys.push(key2);
});
});
// check for duplicates
let duplicateKeys = [];
let i = 0;
arrayOfKeys.forEach(key => {
let o = 0;
arrayOfKeys.forEach(key2 => {
if(i != o && key == key2){
duplicateKeys.push(key);
}
o++
});
i++;
});
// we got 704 but this is a very unexact number
assert(duplicateKeys.length > 10)
});
});
});
+21
View File
@@ -0,0 +1,21 @@
const assert = require("assert").strict;
const path = require("path");
const factorio = require("lib/factorio");
describe("lib/factorio/export", function() {
describe("exportLocale()", function() {
let testServer;
before(async function() {
let writePath = path.join("temp", "test", "server");
testServer = new factorio.FactorioServer(path.join("test", "file", "factorio"), writePath, {});
await testServer.init();
});
it("returns a flattened mapping with locale definitions", async function() {
let locale = await factorio._exportLocale(testServer, new Map(), ["base"], "en");
assert.deepEqual(locale, new Map([["test.key-a", "1"], ["test.key-b", "2"]]));
});
});;
});
-18
View File
@@ -1,18 +0,0 @@
const assert = require("assert").strict;
const path = require("path");
const factorio = require("lib/factorio");
describe("lib/factorio/locale", function() {
describe("getLocale()", function() {
it("verifies types of the arguments", async function() {
await assert.rejects(factorio.getLocale(1, "a"), new TypeError("dataDir must be a string"));
await assert.rejects(factorio.getLocale("a", 1), new TypeError("languageCode must be a string"));
});
it("returns a nested object with locale definitions", async function() {
let locale = await factorio.getLocale(path.join("test", "file", "factorio", "data"), "en");
assert.deepEqual(locale, { test: { "key-a": "1", "key-b": "2" } });
});
});;
});