mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 23:33:13 +09:00
Share structured data types in export
Place shared types of the export functionality into lib and use in the web interface to make sure the data is not incorrectly handled. Resolves #526
This commit is contained in:
1 parent
bcabad567e
commit
076fb933dc
9 files changed
+143
-35
No files matched your search
@@ -5,6 +5,7 @@ import * as libSchema from "../schema";
|
||||
import * as libLuaTools from "../lua_tools";
|
||||
|
||||
import ExportManifest from "./ExportManifest";
|
||||
import type { ExportSettings } from "../export";
|
||||
import type { Logger } from "../logging";
|
||||
|
||||
import ModInfo, { ModDependencyUnsatisfiedReason } from "./ModInfo";
|
||||
@@ -357,7 +358,7 @@ export default class ModPack {
|
||||
* Setting prototypes exported from the game.
|
||||
* @param logger - Logger used to report warnings on.
|
||||
*/
|
||||
fillDefaultSettings(settingPrototypes: Record<string, object>, logger: Logger) {
|
||||
fillDefaultSettings(settingPrototypes: ExportSettings, logger: Logger) {
|
||||
const knownTypes = ["bool-setting", "int-setting", "double-setting", "string-setting", "color-setting"];
|
||||
let prototypes = Object.entries(settingPrototypes)
|
||||
.filter(([type, _]) => knownTypes.includes(type))
|
||||
@@ -370,7 +371,7 @@ export default class ModPack {
|
||||
logger.warn(`Ignoring ${prototype.name} with unknown setting_type ${settingType}`);
|
||||
continue;
|
||||
}
|
||||
if (prototype.default_value === undefined) {
|
||||
if ((prototype as any).default_value === undefined) {
|
||||
logger.warn(`Ignoring ${prototype.name} with missing default_value`);
|
||||
continue;
|
||||
}
|
||||
@@ -389,7 +390,7 @@ export default class ModPack {
|
||||
if (type === "color-setting") {
|
||||
value = libLuaTools.normalizeColor(value as object);
|
||||
}
|
||||
this.settings[settingType].set(prototype.name, { value });
|
||||
this.settings[settingType].set(prototype.name, { value } as ModSetting);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
import { FactorioColor } from "./lua_tools";
|
||||
|
||||
/**
|
||||
* A localised string.
|
||||
* @see [LocalisedString](https://lua-api.factorio.com/stable/types/LocalisedString.html)
|
||||
*/
|
||||
export type FactorioLocalisedString = string | [string, ...FactorioLocalisedString[]];
|
||||
|
||||
/**
|
||||
* Shared properties of all prototypes.
|
||||
* @see [PrototypeBase](https://lua-api.factorio.com/stable/types/PrototypeBase.html)
|
||||
*/
|
||||
export interface FactorioPrototypeBase {
|
||||
[index: string]: unknown,
|
||||
type: string,
|
||||
name: string,
|
||||
order?: string,
|
||||
localised_name?: FactorioLocalisedString,
|
||||
localised_description?: FactorioLocalisedString,
|
||||
factoriopedia_description?: FactorioLocalisedString,
|
||||
subgroup?: string,
|
||||
hidden?: boolean,
|
||||
hidden_in_factoriopedia?: boolean,
|
||||
parameter?: boolean,
|
||||
factoriopedia_simulation?: unknown,
|
||||
}
|
||||
|
||||
/**
|
||||
* Stage the mod setting is part of.
|
||||
* @see [settings_type property](https://wiki.factorio.com/Tutorial:Mod_settings#The_setting_type_property)
|
||||
*/
|
||||
export type FactorioModSettingType = "startup" | "runtime-global" | "runtime-per-user";
|
||||
|
||||
/**
|
||||
* Boolean mod setting prototype.
|
||||
* @see [bool-setting](https://wiki.factorio.com/Tutorial:Mod_settings#bool-setting)
|
||||
*/
|
||||
export interface FactorioBoolSettingPrototype extends FactorioPrototypeBase{
|
||||
type: "bool-setting",
|
||||
setting_type?: FactorioModSettingType,
|
||||
default_value: boolean,
|
||||
forced_value?: boolean,
|
||||
}
|
||||
|
||||
/**
|
||||
* Integer mod setting prototype.
|
||||
* @see [int-setting](https://wiki.factorio.com/Tutorial:Mod_settings#int-setting)
|
||||
*/
|
||||
export interface FactorioIntSettingPrototype extends FactorioPrototypeBase{
|
||||
type: "int-setting",
|
||||
setting_type?: FactorioModSettingType,
|
||||
default_value: number,
|
||||
minimum_value?: number,
|
||||
maximum_value?: number,
|
||||
allowed_values?: number[],
|
||||
}
|
||||
|
||||
/**
|
||||
* Real number mod setting prototype.
|
||||
* @see [double-setting](https://wiki.factorio.com/Tutorial:Mod_settings#double-setting)
|
||||
*/
|
||||
export interface FactorioDoubleSettingPrototype extends FactorioPrototypeBase{
|
||||
type: "double-setting",
|
||||
setting_type?: FactorioModSettingType,
|
||||
default_value: number,
|
||||
minimum_value?: number,
|
||||
maximum_value?: number,
|
||||
allowed_values?: number[],
|
||||
}
|
||||
|
||||
/**
|
||||
* String mod setting prototype.
|
||||
* @see [string-setting](https://wiki.factorio.com/Tutorial:Mod_settings#string-setting)
|
||||
*/
|
||||
export interface FactorioStringSettingPrototype extends FactorioPrototypeBase{
|
||||
type: "string-setting",
|
||||
setting_type?: FactorioModSettingType,
|
||||
default_value: string,
|
||||
allow_black?: boolean,
|
||||
auto_trim?: string,
|
||||
allowed_values?: string[],
|
||||
}
|
||||
|
||||
/**
|
||||
* Color mod setting prototype.
|
||||
* @see [color-setting](https://wiki.factorio.com/Tutorial:Mod_settings#color-setting)
|
||||
*/
|
||||
export interface FactorioColorSettingPrototype extends FactorioPrototypeBase{
|
||||
type: "color-setting",
|
||||
setting_type?: FactorioModSettingType,
|
||||
default_value: FactorioColor,
|
||||
forced_value?: boolean,
|
||||
}
|
||||
|
||||
export type FactorioModSettingPrototype =
|
||||
| FactorioBoolSettingPrototype
|
||||
| FactorioIntSettingPrototype
|
||||
| FactorioDoubleSettingPrototype
|
||||
| FactorioStringSettingPrototype
|
||||
| FactorioColorSettingPrototype
|
||||
;
|
||||
|
||||
/**
|
||||
* A list of prototypes as it appears in Factorio's Lua API.
|
||||
* @see [Data.raw](https://lua-api.factorio.com/stable/types/Data.html#raw)
|
||||
*/
|
||||
export type FactorioPrototypes<Prototype = FactorioPrototypeBase> = Record<string, Record<string, Prototype>>
|
||||
|
||||
export type ExportSettings = FactorioPrototypes<FactorioModSettingPrototype>;
|
||||
export type ExportPrototypes = FactorioPrototypes;
|
||||
export type ExportLocale = [string, string][];
|
||||
export interface ExportMetadataEntry {
|
||||
x: number,
|
||||
y: number,
|
||||
size: number,
|
||||
category: string,
|
||||
path?: string,
|
||||
}
|
||||
export type ExportMetadata = [string, ExportMetadataEntry][];
|
||||
Reference in new issue
Block a user