mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 15:33:12 +09:00
Add suport for color mod setting (#568)
Implement the color-setting type in ModPack and display a color picker for it in the Web UI. This type of setting was added in Factorio 1.1.77.
This commit is contained in:
1 parent
d6d6c052aa
commit
72264f0c53
7 files changed
+114
-13
No files matched your search
@@ -81,6 +81,10 @@ async function getUsers() {
|
||||
return new Map(users.map(user => [user.name, user]));
|
||||
}
|
||||
|
||||
function jsonArg(value) {
|
||||
return `"${JSON.stringify(value).replace(/"/g, process.platform === "win32" ? '""' : '\\"')}"`;
|
||||
}
|
||||
|
||||
describe("Integration of Clusterio", function() {
|
||||
describe("clusteriocontroller", function() {
|
||||
describe("bootstrap generate-user-token", function() {
|
||||
@@ -502,8 +506,7 @@ describe("Integration of Clusterio", function() {
|
||||
];
|
||||
|
||||
for (let [prop, value] of testConfigs) {
|
||||
value = `"${JSON.stringify(value).replace(/"/g, process.platform === "win32" ? '""' : '\\"')}"`;
|
||||
let args = `test factorio.settings ${prop} ${value}`;
|
||||
let args = `test factorio.settings ${prop} ${jsonArg(value)}`;
|
||||
await execCtl(`instance config set-prop ${args}`);
|
||||
}
|
||||
|
||||
@@ -876,6 +879,7 @@ describe("Integration of Clusterio", function() {
|
||||
assert(modPacks.some(modPack => modPack.name === "empty-pack"), "created pack is not in the list");
|
||||
});
|
||||
it("should allow setting all fields", async function() {
|
||||
const color = { r: 1, g: 0, b: 1, a: 0 };
|
||||
await execCtl(
|
||||
"mod-pack create full-pack 0.17.59 " +
|
||||
"--description Description " +
|
||||
@@ -883,7 +887,8 @@ describe("Integration of Clusterio", function() {
|
||||
"--bool-setting startup MyBool true " +
|
||||
"--int-setting runtime-global MyInt 1235 " +
|
||||
"--double-setting runtime-global MyDouble 12.25 " +
|
||||
"--string-setting runtime-per-user MyString a-string"
|
||||
"--string-setting runtime-per-user MyString a-string " +
|
||||
`--color-setting runtime-per-user MyColor ${jsonArg(color)}`
|
||||
);
|
||||
let modPacks = await getControl().send(new lib.ModPackListRequest());
|
||||
let modPack = modPacks.find(entry => entry.name === "full-pack");
|
||||
@@ -898,6 +903,7 @@ describe("Integration of Clusterio", function() {
|
||||
reference.settings["runtime-global"].set("MyInt", { value: 1235 });
|
||||
reference.settings["runtime-global"].set("MyDouble", { value: 12.25 });
|
||||
reference.settings["runtime-per-user"].set("MyString", { value: "a-string" });
|
||||
reference.settings["runtime-per-user"].set("MyColor", { value: color });
|
||||
reference.updatedAtMs = modPack.updatedAtMs;
|
||||
assert.deepEqual(modPack, reference);
|
||||
});
|
||||
|
||||
@@ -39,6 +39,7 @@ describe("lib/data/ModPack", function() {
|
||||
},
|
||||
"runtime-per-user": {
|
||||
"string-setting": { "value": "a string" },
|
||||
"color-setting": { "value": { "r": 1, "g": 1, "b": 0, "a": 1 } },
|
||||
},
|
||||
}}));
|
||||
check(ModPack.fromJSON({ export_manifest: { assets: { setting: "settings.json" }}}));
|
||||
@@ -60,6 +61,7 @@ describe("lib/data/ModPack", function() {
|
||||
},
|
||||
"runtime-per-user": {
|
||||
"string-setting": { "value": "a string" },
|
||||
"color-setting": { "value": { "r": 1, "g": 1, "b": 0, "a": 1 } },
|
||||
},
|
||||
},
|
||||
export_manifest: { assets: { setting: "settings.json" }},
|
||||
@@ -101,6 +103,14 @@ describe("lib/data/ModPack", function() {
|
||||
default_value: "a string",
|
||||
},
|
||||
},
|
||||
"color-setting": {
|
||||
"color": {
|
||||
name: "color",
|
||||
type: "color-setting",
|
||||
setting_type: "runtime-per-user",
|
||||
default_value: { "r": 1, "g": 1, "b": 1, "a": 1 },
|
||||
},
|
||||
},
|
||||
};
|
||||
const mockLogger = { warn: () => {} };
|
||||
it("should fill in defaults for settings", function() {
|
||||
@@ -115,6 +125,7 @@ describe("lib/data/ModPack", function() {
|
||||
},
|
||||
"runtime-per-user": {
|
||||
"string": { "value": "a string" },
|
||||
"color": { "value": { "r": 1, "g": 1, "b": 1, "a": 1 } },
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -128,6 +139,7 @@ describe("lib/data/ModPack", function() {
|
||||
},
|
||||
"runtime-per-user": {
|
||||
"string": { "value": "spam" },
|
||||
"color": { "value": { "r": 0, "g": 0.5, "b": 1, "a": 1 } },
|
||||
},
|
||||
}});
|
||||
pack.fillDefaultSettings(prototypes, mockLogger);
|
||||
@@ -140,6 +152,7 @@ describe("lib/data/ModPack", function() {
|
||||
},
|
||||
"runtime-per-user": {
|
||||
"string": { "value": "spam" },
|
||||
"color": { "value": { "r": 0, "g": 0.5, "b": 1, "a": 1 } },
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -204,6 +217,7 @@ describe("lib/data/ModPack", function() {
|
||||
},
|
||||
"runtime-per-user": {
|
||||
"string-setting": { "value": "a string" },
|
||||
"color-setting": { "value": { "r": 1, "g": 0.5, "b": 0, "a": 1 } },
|
||||
},
|
||||
}});
|
||||
|
||||
@@ -248,7 +262,7 @@ describe("lib/data/ModPack", function() {
|
||||
|
||||
...istr("runtime-per-user"), // name
|
||||
Uint8Array.from([5, 0]), // dictionary
|
||||
new Uint8Array(Uint32Array.from([1]).buffer), // items
|
||||
new Uint8Array(Uint32Array.from([2]).buffer), // items
|
||||
|
||||
...istr("string-setting"), // name
|
||||
Uint8Array.from([5, 0]), // dictinary
|
||||
@@ -257,6 +271,30 @@ describe("lib/data/ModPack", function() {
|
||||
...istr("value"), // name
|
||||
Uint8Array.from([3, 0, 0, "a string".length]), // string
|
||||
Buffer.from("a string"),
|
||||
|
||||
...istr("color-setting"), // name
|
||||
Uint8Array.from([5, 0]), // dictinary
|
||||
new Uint8Array(Uint32Array.from([1]).buffer), // items
|
||||
|
||||
...istr("value"), // name
|
||||
Uint8Array.from([5, 0]), // dictinary
|
||||
new Uint8Array(Uint32Array.from([4]).buffer), // items
|
||||
|
||||
...istr("r"), // name
|
||||
Uint8Array.from([2, 0]), // number
|
||||
new Uint8Array(Float64Array.from([1]).buffer),
|
||||
|
||||
...istr("g"), // name
|
||||
Uint8Array.from([2, 0]), // number
|
||||
new Uint8Array(Float64Array.from([0.5]).buffer),
|
||||
|
||||
...istr("b"), // name
|
||||
Uint8Array.from([2, 0]), // number
|
||||
new Uint8Array(Float64Array.from([0]).buffer),
|
||||
|
||||
...istr("a"), // name
|
||||
Uint8Array.from([2, 0]), // number
|
||||
new Uint8Array(Float64Array.from([1]).buffer),
|
||||
])
|
||||
);
|
||||
/* eslint-enable indent */
|
||||
|
||||
Reference in new issue
Block a user