mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-13 18:21:51 +00:00
Add example for adding a new item type
This commit is contained in:
parent
54a69c9725
commit
1b931808eb
@ -4,7 +4,7 @@ const METADATA = {
|
|||||||
author: "tobspr",
|
author: "tobspr",
|
||||||
name: "Mod Example: Mod Settings",
|
name: "Mod Example: Mod Settings",
|
||||||
version: "1",
|
version: "1",
|
||||||
id: "base",
|
id: "mod-settings",
|
||||||
description: "Shows how to add settings to your mod",
|
description: "Shows how to add settings to your mod",
|
||||||
|
|
||||||
settings: {
|
settings: {
|
||||||
@ -18,7 +18,7 @@ class Mod extends shapez.Mod {
|
|||||||
this.settings.timesLaunched++;
|
this.settings.timesLaunched++;
|
||||||
this.saveSettings();
|
this.saveSettings();
|
||||||
|
|
||||||
// Show a dialog in the main menu wit the settings
|
// Show a dialog in the main menu with the settings
|
||||||
this.signals.stateEntered.add(state => {
|
this.signals.stateEntered.add(state => {
|
||||||
if (state instanceof shapez.MainMenuState) {
|
if (state instanceof shapez.MainMenuState) {
|
||||||
this.dialogs.showInfo(
|
this.dialogs.showInfo(
|
||||||
|
|||||||
146
mod_examples/new_item_type.js
Normal file
146
mod_examples/new_item_type.js
Normal file
File diff suppressed because one or more lines are too long
@ -2,9 +2,6 @@ import { globalConfig } from "../core/config";
|
|||||||
import { DrawParameters } from "../core/draw_parameters";
|
import { DrawParameters } from "../core/draw_parameters";
|
||||||
import { BasicSerializableObject } from "../savegame/serialization";
|
import { BasicSerializableObject } from "../savegame/serialization";
|
||||||
|
|
||||||
/** @type {ItemType[]} **/
|
|
||||||
export const itemTypes = ["shape", "color", "boolean"];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for items on belts etc. Not an entity for performance reasons
|
* Class for items on belts etc. Not an entity for performance reasons
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -283,6 +283,17 @@ export class MapChunk {
|
|||||||
const chunkCenter = new Vector(this.x, this.y).addScalar(0.5);
|
const chunkCenter = new Vector(this.x, this.y).addScalar(0.5);
|
||||||
const distanceToOriginInChunks = Math.round(chunkCenter.length());
|
const distanceToOriginInChunks = Math.round(chunkCenter.length());
|
||||||
|
|
||||||
|
this.generatePatches({ rng, chunkCenter, distanceToOriginInChunks });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {object} param0
|
||||||
|
* @param {RandomNumberGenerator} param0.rng
|
||||||
|
* @param {Vector} param0.chunkCenter
|
||||||
|
* @param {number} param0.distanceToOriginInChunks
|
||||||
|
*/
|
||||||
|
generatePatches({ rng, chunkCenter, distanceToOriginInChunks }) {
|
||||||
// Determine how likely it is that there is a color patch
|
// Determine how likely it is that there is a color patch
|
||||||
const colorPatchChance = 0.9 - clamp(distanceToOriginInChunks / 25, 0, 1) * 0.5;
|
const colorPatchChance = 0.9 - clamp(distanceToOriginInChunks / 25, 0, 1) * 0.5;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user