mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Merge branch 'master' of github.com:tobspr/shapez.io
This commit is contained in:
commit
bbeb5b1158
@ -93,9 +93,6 @@ module.exports = ({ watch = false, standalone = false, chineseVersion = false, w
|
|||||||
end: "typehints:end",
|
end: "typehints:end",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
loader: path.resolve(__dirname, "mod.js"),
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -230,9 +230,6 @@ module.exports = ({
|
|||||||
{ pattern: /globalConfig\.debug/g, replacement: () => "''" },
|
{ pattern: /globalConfig\.debug/g, replacement: () => "''" },
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
{
|
|
||||||
loader: path.resolve(__dirname, "mod.js"),
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -120,11 +120,10 @@ class Mod extends shapez.Mod {
|
|||||||
this.modInterface.registerSprite("sprites/fluids/water.png", RESOURCES["water.png"]);
|
this.modInterface.registerSprite("sprites/fluids/water.png", RESOURCES["water.png"]);
|
||||||
|
|
||||||
// Make the item spawn on the map
|
// Make the item spawn on the map
|
||||||
this.modInterface.runAfterMethod(shapez.MapChunk, "generatePatches", function ({
|
this.modInterface.runAfterMethod(
|
||||||
rng,
|
shapez.MapChunk,
|
||||||
chunkCenter,
|
"generatePatches",
|
||||||
distanceToOriginInChunks,
|
function ({ rng, chunkCenter, distanceToOriginInChunks }) {
|
||||||
}) {
|
|
||||||
// Generate a simple patch
|
// Generate a simple patch
|
||||||
// ALWAYS use rng and NEVER use Math.random() otherwise the map will look different
|
// ALWAYS use rng and NEVER use Math.random() otherwise the map will look different
|
||||||
// every time you resume the game
|
// every time you resume the game
|
||||||
@ -132,7 +131,10 @@ class Mod extends shapez.Mod {
|
|||||||
const fluidType = rng.choice(Array.from(Object.keys(enumFluidType)));
|
const fluidType = rng.choice(Array.from(Object.keys(enumFluidType)));
|
||||||
this.internalGeneratePatch(rng, 4, FLUID_ITEM_SINGLETONS[fluidType]);
|
this.internalGeneratePatch(rng, 4, FLUID_ITEM_SINGLETONS[fluidType]);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
this.modInterface.registerItem(FluidItem, itemData => FLUID_ITEM_SINGLETONS[itemData]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ export class BaseItem extends BasicSerializableObject {
|
|||||||
return "base_item";
|
return "base_item";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @returns {object} */
|
/** @returns {import("../savegame/serialization").Schema} */
|
||||||
static getSchema() {
|
static getSchema() {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ import { BooleanItem, BOOL_TRUE_SINGLETON, BOOL_FALSE_SINGLETON } from "./items/
|
|||||||
import { ShapeItem } from "./items/shape_item";
|
import { ShapeItem } from "./items/shape_item";
|
||||||
import { ColorItem, COLOR_ITEM_SINGLETONS } from "./items/color_item";
|
import { ColorItem, COLOR_ITEM_SINGLETONS } from "./items/color_item";
|
||||||
|
|
||||||
|
export const MODS_ADDITIONAL_ITEMS = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves items so we share instances
|
* Resolves items so we share instances
|
||||||
* @param {import("../savegame/savegame_serializer").GameRoot} root
|
* @param {import("../savegame/savegame_serializer").GameRoot} root
|
||||||
@ -13,6 +15,10 @@ export function itemResolverSingleton(root, data) {
|
|||||||
const itemType = data.$;
|
const itemType = data.$;
|
||||||
const itemData = data.data;
|
const itemData = data.data;
|
||||||
|
|
||||||
|
if (MODS_ADDITIONAL_ITEMS[itemType]) {
|
||||||
|
return MODS_ADDITIONAL_ITEMS[itemType](itemData);
|
||||||
|
}
|
||||||
|
|
||||||
switch (itemType) {
|
switch (itemType) {
|
||||||
case BooleanItem.getId(): {
|
case BooleanItem.getId(): {
|
||||||
return itemData ? BOOL_TRUE_SINGLETON : BOOL_FALSE_SINGLETON;
|
return itemData ? BOOL_TRUE_SINGLETON : BOOL_FALSE_SINGLETON;
|
||||||
|
@ -17,7 +17,7 @@ import { Loader } from "../core/loader";
|
|||||||
import { LANGUAGES } from "../languages";
|
import { LANGUAGES } from "../languages";
|
||||||
import { matchDataRecursive, T } from "../translations";
|
import { matchDataRecursive, T } from "../translations";
|
||||||
import { gBuildingVariants, registerBuildingVariant } from "../game/building_codes";
|
import { gBuildingVariants, registerBuildingVariant } from "../game/building_codes";
|
||||||
import { gComponentRegistry, gMetaBuildingRegistry } from "../core/global_registries";
|
import { gComponentRegistry, gItemRegistry, gMetaBuildingRegistry } from "../core/global_registries";
|
||||||
import { MODS_ADDITIONAL_SHAPE_MAP_WEIGHTS } from "../game/map_chunk";
|
import { MODS_ADDITIONAL_SHAPE_MAP_WEIGHTS } from "../game/map_chunk";
|
||||||
import { MODS_ADDITIONAL_SYSTEMS } from "../game/game_system_manager";
|
import { MODS_ADDITIONAL_SYSTEMS } from "../game/game_system_manager";
|
||||||
import { MOD_CHUNK_DRAW_HOOKS } from "../game/map_chunk_view";
|
import { MOD_CHUNK_DRAW_HOOKS } from "../game/map_chunk_view";
|
||||||
@ -28,6 +28,8 @@ import { ModMetaBuilding } from "./mod_meta_building";
|
|||||||
import { BaseHUDPart } from "../game/hud/base_hud_part";
|
import { BaseHUDPart } from "../game/hud/base_hud_part";
|
||||||
import { Vector } from "../core/vector";
|
import { Vector } from "../core/vector";
|
||||||
import { GameRoot } from "../game/root";
|
import { GameRoot } from "../game/root";
|
||||||
|
import { BaseItem } from "../game/base_item";
|
||||||
|
import { MODS_ADDITIONAL_ITEMS } from "../game/item_resolver";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{new(...args: any[]): any, prototype: any}} constructable
|
* @typedef {{new(...args: any[]): any, prototype: any}} constructable
|
||||||
@ -190,6 +192,15 @@ export class ModInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {typeof BaseItem} item
|
||||||
|
* @param {(itemData: any) => BaseItem} resolver
|
||||||
|
*/
|
||||||
|
registerItem(item, resolver) {
|
||||||
|
gItemRegistry.register(item);
|
||||||
|
MODS_ADDITIONAL_ITEMS[item.getId()] = resolver;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {typeof Component} component
|
* @param {typeof Component} component
|
||||||
|
@ -112,8 +112,7 @@ export class ModLoader {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const module = modules(key);
|
const module = modules(key);
|
||||||
for (const member in module) {
|
for (const member in module) {
|
||||||
if (member === "default" || member === "$s") {
|
if (member === "default") {
|
||||||
// Setter
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (exports[member]) {
|
if (exports[member]) {
|
||||||
@ -125,7 +124,7 @@ export class ModLoader {
|
|||||||
return module[member];
|
return module[member];
|
||||||
},
|
},
|
||||||
set(v) {
|
set(v) {
|
||||||
module["$s"](member, v);
|
throw new Error("Overriding the shapez exports is currently not possible");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ export class BasicSerializableObject {
|
|||||||
return schema;
|
return schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @returns {object} */
|
/** @returns {object | string | number} */
|
||||||
serialize() {
|
serialize() {
|
||||||
return serializeSchema(
|
return serializeSchema(
|
||||||
this,
|
this,
|
||||||
|
Loading…
Reference in New Issue
Block a user