1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

Merge remote-tracking branch 'origin/master' into better-building-variants

This commit is contained in:
Exund 2020-09-18 18:52:22 +02:00
commit f924882b62
23 changed files with 1662 additions and 1352 deletions

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

After

Width:  |  Height:  |  Size: 1.3 MiB

View File

@ -1471,6 +1471,6 @@
"format": "RGBA8888",
"size": {"w":512,"h":1024},
"scale": "0.25",
"smartupdate": "$TexturePacker:SmartUpdate:d21082eda6f288e04b0739186004794d:0912211652d1c400e2846013f9de057b:908b89f5ca8ff73e331a35a3b14d0604$"
"smartupdate": "$TexturePacker:SmartUpdate:64d35c8d649d4bb41c7539e7e89c0865:2a9399f9a7c16dc686a4fb0941b02e6b:908b89f5ca8ff73e331a35a3b14d0604$"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 280 KiB

After

Width:  |  Height:  |  Size: 281 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 677 KiB

After

Width:  |  Height:  |  Size: 661 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -1,360 +1,393 @@
import { DrawParameters } from "./draw_parameters";
import { Rectangle } from "./rectangle";
import { round3Digits } from "./utils";
const floorSpriteCoordinates = false;
export const ORIGINAL_SPRITE_SCALE = "0.75";
export class BaseSprite {
/**
* Returns the raw handle
* @returns {HTMLImageElement|HTMLCanvasElement}
*/
getRawTexture() {
abstract;
return null;
}
/**
* Draws the sprite
* @param {CanvasRenderingContext2D} context
* @param {number} x
* @param {number} y
* @param {number} w
* @param {number} h
*/
draw(context, x, y, w, h) {
// eslint-disable-line no-unused-vars
abstract;
}
}
/**
* Position of a sprite within an atlas
*/
export class SpriteAtlasLink {
/**
*
* @param {object} param0
* @param {number} param0.packedX
* @param {number} param0.packedY
* @param {number} param0.packOffsetX
* @param {number} param0.packOffsetY
* @param {number} param0.packedW
* @param {number} param0.packedH
* @param {number} param0.w
* @param {number} param0.h
* @param {HTMLImageElement|HTMLCanvasElement} param0.atlas
*/
constructor({ w, h, packedX, packedY, packOffsetX, packOffsetY, packedW, packedH, atlas }) {
this.packedX = packedX;
this.packedY = packedY;
this.packedW = packedW;
this.packedH = packedH;
this.packOffsetX = packOffsetX;
this.packOffsetY = packOffsetY;
this.atlas = atlas;
this.w = w;
this.h = h;
}
}
export class AtlasSprite extends BaseSprite {
/**
*
* @param {string} spriteName
*/
constructor(spriteName = "sprite") {
super();
/** @type {Object.<string, SpriteAtlasLink>} */
this.linksByResolution = {};
this.spriteName = spriteName;
}
getRawTexture() {
return this.linksByResolution[ORIGINAL_SPRITE_SCALE].atlas;
}
/**
* Draws the sprite onto a regular context using no contexts
* @see {BaseSprite.draw}
*/
draw(context, x, y, w, h) {
if (G_IS_DEV) {
assert(context instanceof CanvasRenderingContext2D, "Not a valid context");
}
const link = this.linksByResolution[ORIGINAL_SPRITE_SCALE];
assert(
link,
"Link not known: " +
ORIGINAL_SPRITE_SCALE +
" (having " +
Object.keys(this.linksByResolution) +
")"
);
const width = w || link.w;
const height = h || link.h;
const scaleW = width / link.w;
const scaleH = height / link.h;
context.drawImage(
link.atlas,
link.packedX,
link.packedY,
link.packedW,
link.packedH,
x + link.packOffsetX * scaleW,
y + link.packOffsetY * scaleH,
link.packedW * scaleW,
link.packedH * scaleH
);
}
/**
*
* @param {DrawParameters} parameters
* @param {number} x
* @param {number} y
* @param {number} size
* @param {boolean=} clipping
*/
drawCachedCentered(parameters, x, y, size, clipping = true) {
this.drawCached(parameters, x - size / 2, y - size / 2, size, size, clipping);
}
/**
*
* @param {CanvasRenderingContext2D} context
* @param {number} x
* @param {number} y
* @param {number} size
*/
drawCentered(context, x, y, size) {
this.draw(context, x - size / 2, y - size / 2, size, size);
}
/**
* Draws the sprite
* @param {DrawParameters} parameters
* @param {number} x
* @param {number} y
* @param {number} w
* @param {number} h
* @param {boolean=} clipping Whether to perform culling
*/
drawCached(parameters, x, y, w = null, h = null, clipping = true) {
if (G_IS_DEV) {
assert(parameters instanceof DrawParameters, "Not a valid context");
assert(!!w && w > 0, "Not a valid width:" + w);
assert(!!h && h > 0, "Not a valid height:" + h);
}
const visibleRect = parameters.visibleRect;
const scale = parameters.desiredAtlasScale;
const link = this.linksByResolution[scale];
if (!link) {
assert(false, `Link not known: ${scale} (having ${Object.keys(this.linksByResolution)})`);
}
const scaleW = w / link.w;
const scaleH = h / link.h;
let destX = x + link.packOffsetX * scaleW;
let destY = y + link.packOffsetY * scaleH;
let destW = link.packedW * scaleW;
let destH = link.packedH * scaleH;
let srcX = link.packedX;
let srcY = link.packedY;
let srcW = link.packedW;
let srcH = link.packedH;
let intersection = null;
if (clipping) {
const rect = new Rectangle(destX, destY, destW, destH);
intersection = rect.getIntersection(visibleRect);
if (!intersection) {
return;
}
srcX += (intersection.x - destX) / scaleW;
srcY += (intersection.y - destY) / scaleH;
srcW *= intersection.w / destW;
srcH *= intersection.h / destH;
destX = intersection.x;
destY = intersection.y;
destW = intersection.w;
destH = intersection.h;
}
if (floorSpriteCoordinates) {
parameters.context.drawImage(
link.atlas,
// atlas src pos
Math.floor(srcX),
Math.floor(srcY),
// atlas src size
Math.floor(srcW),
Math.floor(srcH),
// dest pos
Math.floor(destX),
Math.floor(destY),
// dest size
Math.floor(destW),
Math.floor(destH)
);
} else {
parameters.context.drawImage(
link.atlas,
// atlas src pos
srcX,
srcY,
// atlas src siize
srcW,
srcH,
// dest pos and size
destX,
destY,
destW,
destH
);
}
}
/**
* Renders into an html element
* @param {HTMLElement} element
* @param {number} w
* @param {number} h
*/
renderToHTMLElement(element, w = 1, h = 1) {
element.style.position = "relative";
element.innerHTML = this.getAsHTML(w, h);
}
/**
* Returns the html to render as icon
* @param {number} w
* @param {number} h
*/
getAsHTML(w, h) {
const link = this.linksByResolution["0.5"];
// Find out how much we have to scale it so that it fits
const scaleX = w / link.w;
const scaleY = h / link.h;
// Find out how big the scaled atlas is
const atlasW = link.atlas.width * scaleX;
const atlasH = link.atlas.height * scaleY;
// @ts-ignore
const srcSafe = link.atlas.src.replaceAll("\\", "/");
// Find out how big we render the sprite
const widthAbsolute = scaleX * link.packedW;
const heightAbsolute = scaleY * link.packedH;
// Compute the position in the relative container
const leftRelative = (link.packOffsetX * scaleX) / w;
const topRelative = (link.packOffsetY * scaleY) / h;
const widthRelative = widthAbsolute / w;
const heightRelative = heightAbsolute / h;
// Scale the atlas relative to the width and height of the element
const bgW = atlasW / widthAbsolute;
const bgH = atlasH / heightAbsolute;
// Figure out what the position of the atlas is
const bgX = link.packedX * scaleX;
const bgY = link.packedY * scaleY;
// Fuck you, whoever thought its a good idea to make background-position work like it does now
const bgXRelative = -bgX / (widthAbsolute - atlasW);
const bgYRelative = -bgY / (heightAbsolute - atlasH);
return `
<span class="spritesheetImage" style="
background-image: url('${srcSafe}');
left: ${round3Digits(leftRelative * 100.0)}%;
top: ${round3Digits(topRelative * 100.0)}%;
width: ${round3Digits(widthRelative * 100.0)}%;
height: ${round3Digits(heightRelative * 100.0)}%;
background-repeat: repeat;
background-position: ${round3Digits(bgXRelative * 100.0)}% ${round3Digits(
bgYRelative * 100.0
)}%;
background-size: ${round3Digits(bgW * 100.0)}% ${round3Digits(bgH * 100.0)}%;
"></span>
`;
}
}
export class RegularSprite extends BaseSprite {
constructor(sprite, w, h) {
super();
this.w = w;
this.h = h;
this.sprite = sprite;
}
getRawTexture() {
return this.sprite;
}
/**
* Draws the sprite, do *not* use this for sprites which are rendered! Only for drawing
* images into buffers
* @param {CanvasRenderingContext2D} context
* @param {number} x
* @param {number} y
* @param {number} w
* @param {number} h
*/
draw(context, x, y, w, h) {
assert(context, "No context given");
assert(x !== undefined, "No x given");
assert(y !== undefined, "No y given");
assert(w !== undefined, "No width given");
assert(h !== undefined, "No height given");
context.drawImage(this.sprite, x, y, w, h);
}
/**
* Draws the sprite, do *not* use this for sprites which are rendered! Only for drawing
* images into buffers
* @param {CanvasRenderingContext2D} context
* @param {number} x
* @param {number} y
* @param {number} w
* @param {number} h
*/
drawCentered(context, x, y, w, h) {
assert(context, "No context given");
assert(x !== undefined, "No x given");
assert(y !== undefined, "No y given");
assert(w !== undefined, "No width given");
assert(h !== undefined, "No height given");
context.drawImage(this.sprite, x - w / 2, y - h / 2, w, h);
}
}
import { DrawParameters } from "./draw_parameters";
import { Rectangle } from "./rectangle";
import { round3Digits } from "./utils";
export const ORIGINAL_SPRITE_SCALE = "0.75";
export const FULL_CLIP_RECT = new Rectangle(0, 0, 1, 1);
export class BaseSprite {
/**
* Returns the raw handle
* @returns {HTMLImageElement|HTMLCanvasElement}
*/
getRawTexture() {
abstract;
return null;
}
/**
* Draws the sprite
* @param {CanvasRenderingContext2D} context
* @param {number} x
* @param {number} y
* @param {number} w
* @param {number} h
*/
draw(context, x, y, w, h) {
// eslint-disable-line no-unused-vars
abstract;
}
}
/**
* Position of a sprite within an atlas
*/
export class SpriteAtlasLink {
/**
*
* @param {object} param0
* @param {number} param0.packedX
* @param {number} param0.packedY
* @param {number} param0.packOffsetX
* @param {number} param0.packOffsetY
* @param {number} param0.packedW
* @param {number} param0.packedH
* @param {number} param0.w
* @param {number} param0.h
* @param {HTMLImageElement|HTMLCanvasElement} param0.atlas
*/
constructor({ w, h, packedX, packedY, packOffsetX, packOffsetY, packedW, packedH, atlas }) {
this.packedX = packedX;
this.packedY = packedY;
this.packedW = packedW;
this.packedH = packedH;
this.packOffsetX = packOffsetX;
this.packOffsetY = packOffsetY;
this.atlas = atlas;
this.w = w;
this.h = h;
}
}
export class AtlasSprite extends BaseSprite {
/**
*
* @param {string} spriteName
*/
constructor(spriteName = "sprite") {
super();
/** @type {Object.<string, SpriteAtlasLink>} */
this.linksByResolution = {};
this.spriteName = spriteName;
}
getRawTexture() {
return this.linksByResolution[ORIGINAL_SPRITE_SCALE].atlas;
}
/**
* Draws the sprite onto a regular context using no contexts
* @see {BaseSprite.draw}
*/
draw(context, x, y, w, h) {
if (G_IS_DEV) {
assert(context instanceof CanvasRenderingContext2D, "Not a valid context");
}
const link = this.linksByResolution[ORIGINAL_SPRITE_SCALE];
assert(
link,
"Link not known: " +
ORIGINAL_SPRITE_SCALE +
" (having " +
Object.keys(this.linksByResolution) +
")"
);
const width = w || link.w;
const height = h || link.h;
const scaleW = width / link.w;
const scaleH = height / link.h;
context.drawImage(
link.atlas,
link.packedX,
link.packedY,
link.packedW,
link.packedH,
x + link.packOffsetX * scaleW,
y + link.packOffsetY * scaleH,
link.packedW * scaleW,
link.packedH * scaleH
);
}
/**
*
* @param {DrawParameters} parameters
* @param {number} x
* @param {number} y
* @param {number} size
* @param {boolean=} clipping
*/
drawCachedCentered(parameters, x, y, size, clipping = true) {
this.drawCached(parameters, x - size / 2, y - size / 2, size, size, clipping);
}
/**
*
* @param {CanvasRenderingContext2D} context
* @param {number} x
* @param {number} y
* @param {number} size
*/
drawCentered(context, x, y, size) {
this.draw(context, x - size / 2, y - size / 2, size, size);
}
/**
* Draws the sprite
* @param {DrawParameters} parameters
* @param {number} x
* @param {number} y
* @param {number} w
* @param {number} h
* @param {boolean=} clipping Whether to perform culling
*/
drawCached(parameters, x, y, w = null, h = null, clipping = true) {
if (G_IS_DEV) {
assert(parameters instanceof DrawParameters, "Not a valid context");
assert(!!w && w > 0, "Not a valid width:" + w);
assert(!!h && h > 0, "Not a valid height:" + h);
}
const visibleRect = parameters.visibleRect;
const scale = parameters.desiredAtlasScale;
const link = this.linksByResolution[scale];
if (!link) {
assert(false, `Link not known: ${scale} (having ${Object.keys(this.linksByResolution)})`);
}
const scaleW = w / link.w;
const scaleH = h / link.h;
let destX = x + link.packOffsetX * scaleW;
let destY = y + link.packOffsetY * scaleH;
let destW = link.packedW * scaleW;
let destH = link.packedH * scaleH;
let srcX = link.packedX;
let srcY = link.packedY;
let srcW = link.packedW;
let srcH = link.packedH;
let intersection = null;
if (clipping) {
const rect = new Rectangle(destX, destY, destW, destH);
intersection = rect.getIntersection(visibleRect);
if (!intersection) {
return;
}
srcX += (intersection.x - destX) / scaleW;
srcY += (intersection.y - destY) / scaleH;
srcW *= intersection.w / destW;
srcH *= intersection.h / destH;
destX = intersection.x;
destY = intersection.y;
destW = intersection.w;
destH = intersection.h;
}
parameters.context.drawImage(
link.atlas,
// atlas src pos
srcX,
srcY,
// atlas src siize
srcW,
srcH,
// dest pos and size
destX,
destY,
destW,
destH
);
}
/**
* Draws a subset of the sprite. Does NO culling
* @param {DrawParameters} parameters
* @param {number} x
* @param {number} y
* @param {number} w
* @param {number} h
* @param {Rectangle=} clipRect The rectangle in local space (0 ... 1) to draw of the image
*/
drawCachedWithClipRect(parameters, x, y, w = null, h = null, clipRect = FULL_CLIP_RECT) {
if (G_IS_DEV) {
assert(parameters instanceof DrawParameters, "Not a valid context");
assert(!!w && w > 0, "Not a valid width:" + w);
assert(!!h && h > 0, "Not a valid height:" + h);
assert(clipRect, "No clip rect given!");
}
const scale = parameters.desiredAtlasScale;
const link = this.linksByResolution[scale];
if (!link) {
assert(false, `Link not known: ${scale} (having ${Object.keys(this.linksByResolution)})`);
}
const scaleW = w / link.w;
const scaleH = h / link.h;
let destX = x + link.packOffsetX * scaleW + clipRect.x * w;
let destY = y + link.packOffsetY * scaleH + clipRect.y * h;
let destW = link.packedW * scaleW * clipRect.w;
let destH = link.packedH * scaleH * clipRect.h;
let srcX = link.packedX + clipRect.x * link.packedW;
let srcY = link.packedY + clipRect.y * link.packedH;
let srcW = link.packedW * clipRect.w;
let srcH = link.packedH * clipRect.h;
parameters.context.drawImage(
link.atlas,
// atlas src pos
srcX,
srcY,
// atlas src siize
srcW,
srcH,
// dest pos and size
destX,
destY,
destW,
destH
);
}
/**
* Renders into an html element
* @param {HTMLElement} element
* @param {number} w
* @param {number} h
*/
renderToHTMLElement(element, w = 1, h = 1) {
element.style.position = "relative";
element.innerHTML = this.getAsHTML(w, h);
}
/**
* Returns the html to render as icon
* @param {number} w
* @param {number} h
*/
getAsHTML(w, h) {
const link = this.linksByResolution["0.5"];
// Find out how much we have to scale it so that it fits
const scaleX = w / link.w;
const scaleY = h / link.h;
// Find out how big the scaled atlas is
const atlasW = link.atlas.width * scaleX;
const atlasH = link.atlas.height * scaleY;
// @ts-ignore
const srcSafe = link.atlas.src.replaceAll("\\", "/");
// Find out how big we render the sprite
const widthAbsolute = scaleX * link.packedW;
const heightAbsolute = scaleY * link.packedH;
// Compute the position in the relative container
const leftRelative = (link.packOffsetX * scaleX) / w;
const topRelative = (link.packOffsetY * scaleY) / h;
const widthRelative = widthAbsolute / w;
const heightRelative = heightAbsolute / h;
// Scale the atlas relative to the width and height of the element
const bgW = atlasW / widthAbsolute;
const bgH = atlasH / heightAbsolute;
// Figure out what the position of the atlas is
const bgX = link.packedX * scaleX;
const bgY = link.packedY * scaleY;
// Fuck you, whoever thought its a good idea to make background-position work like it does now
const bgXRelative = -bgX / (widthAbsolute - atlasW);
const bgYRelative = -bgY / (heightAbsolute - atlasH);
return `
<span class="spritesheetImage" style="
background-image: url('${srcSafe}');
left: ${round3Digits(leftRelative * 100.0)}%;
top: ${round3Digits(topRelative * 100.0)}%;
width: ${round3Digits(widthRelative * 100.0)}%;
height: ${round3Digits(heightRelative * 100.0)}%;
background-repeat: repeat;
background-position: ${round3Digits(bgXRelative * 100.0)}% ${round3Digits(
bgYRelative * 100.0
)}%;
background-size: ${round3Digits(bgW * 100.0)}% ${round3Digits(bgH * 100.0)}%;
"></span>
`;
}
}
export class RegularSprite extends BaseSprite {
constructor(sprite, w, h) {
super();
this.w = w;
this.h = h;
this.sprite = sprite;
}
getRawTexture() {
return this.sprite;
}
/**
* Draws the sprite, do *not* use this for sprites which are rendered! Only for drawing
* images into buffers
* @param {CanvasRenderingContext2D} context
* @param {number} x
* @param {number} y
* @param {number} w
* @param {number} h
*/
draw(context, x, y, w, h) {
assert(context, "No context given");
assert(x !== undefined, "No x given");
assert(y !== undefined, "No y given");
assert(w !== undefined, "No width given");
assert(h !== undefined, "No height given");
context.drawImage(this.sprite, x, y, w, h);
}
/**
* Draws the sprite, do *not* use this for sprites which are rendered! Only for drawing
* images into buffers
* @param {CanvasRenderingContext2D} context
* @param {number} x
* @param {number} y
* @param {number} w
* @param {number} h
*/
drawCentered(context, x, y, w, h) {
assert(context, "No context given");
assert(x !== undefined, "No x given");
assert(y !== undefined, "No y given");
assert(w !== undefined, "No width given");
assert(h !== undefined, "No height given");
context.drawImage(this.sprite, x - w / 2, y - h / 2, w, h);
}
}

View File

@ -1,50 +1,86 @@
import { createLogger } from "./logging";
import { Rectangle } from "./rectangle";
import { globalConfig } from "./config";
const logger = createLogger("stale_areas");
export class StaleAreaDetector {
/**
*
* @param {object} param0
* @param {import("../game/root").GameRoot} param0.root
* @param {string} param0.name The name for reference
* @param {(Rectangle) => void} param0.recomputeMethod Method which recomputes the given area
*/
constructor({ root, name, recomputeMethod }) {
this.root = root;
this.name = name;
this.recomputeMethod = recomputeMethod;
/** @type {Rectangle} */
this.staleArea = null;
}
/**
* Invalidates the given area
* @param {Rectangle} area
*/
invalidate(area) {
// logger.log(this.name, "invalidated", area.toString());
if (this.staleArea) {
this.staleArea = this.staleArea.getUnion(area);
} else {
this.staleArea = area.clone();
}
}
/**
* Updates the stale area
*/
update() {
if (this.staleArea) {
logger.log(this.name, "is recomputing", this.staleArea.toString());
if (G_IS_DEV && globalConfig.debug.renderChanges) {
this.root.hud.parts.changesDebugger.renderChange(this.name, this.staleArea, "#fd145b");
}
this.recomputeMethod(this.staleArea);
this.staleArea = null;
}
}
}
import { Component } from "../game/component";
import { Entity } from "../game/entity";
import { globalConfig } from "./config";
import { createLogger } from "./logging";
import { Rectangle } from "./rectangle";
const logger = createLogger("stale_areas");
export class StaleAreaDetector {
/**
*
* @param {object} param0
* @param {import("../game/root").GameRoot} param0.root
* @param {string} param0.name The name for reference
* @param {(Rectangle) => void} param0.recomputeMethod Method which recomputes the given area
*/
constructor({ root, name, recomputeMethod }) {
this.root = root;
this.name = name;
this.recomputeMethod = recomputeMethod;
/** @type {Rectangle} */
this.staleArea = null;
}
/**
* Invalidates the given area
* @param {Rectangle} area
*/
invalidate(area) {
// logger.log(this.name, "invalidated", area.toString());
if (this.staleArea) {
this.staleArea = this.staleArea.getUnion(area);
} else {
this.staleArea = area.clone();
}
}
/**
* Makes this detector recompute the area of an entity whenever
* it changes in any way
* @param {Array<typeof Component>} components
* @param {number} tilesAround
*/
recomputeOnComponentsChanged(components, tilesAround = 1) {
const componentIds = components.map(component => component.getId());
/**
* Internal checker method
* @param {Entity} entity
*/
const checker = entity => {
// Check for all components
for (let i = 0; i < componentIds.length; ++i) {
if (entity.components[componentIds[i]]) {
// Entity is relevant, compute affected area
const area = entity.components.StaticMapEntity.getTileSpaceBounds().expandedInAllDirections(
tilesAround
);
this.invalidate(area);
return;
}
}
};
this.root.signals.entityAdded.add(checker);
this.root.signals.entityChanged.add(checker);
this.root.signals.entityComponentRemoved.add(checker);
this.root.signals.entityGotNewComponent.add(checker);
this.root.signals.entityDestroyed.add(checker);
}
/**
* Updates the stale area
*/
update() {
if (this.staleArea) {
logger.log(this.name, "is recomputing", this.staleArea.toString());
if (G_IS_DEV && globalConfig.debug.renderChanges) {
this.root.hud.parts.changesDebugger.renderChange(this.name, this.staleArea, "#fd145b");
}
this.recomputeMethod(this.staleArea);
this.staleArea = null;
}
}
}

View File

@ -1,9 +1,24 @@
import { Loader } from "../../core/loader";
import { enumDirection } from "../../core/vector";
import { formatItemsPerSecond, generateMatrixRotations } from "../../core/utils";
import { enumAngleToDirection, enumDirection, Vector } from "../../core/vector";
import { SOUNDS } from "../../platform/sound";
import { arrayBeltVariantToRotation, DefaultBeltBaseVariant, MetaBeltBaseBuilding } from "./belt_base";
import { T } from "../../translations";
import { BeltComponent } from "../components/belt";
import { Entity } from "../entity";
import { MetaBuilding, MetaBuildingVariant, defaultBuildingVariant } from "../meta_building";
import { GameRoot } from "../root";
export class MetaBeltBuilding extends MetaBeltBaseBuilding {
export const arrayBeltVariantToRotation = [enumDirection.top, enumDirection.left, enumDirection.right];
export const beltOverlayMatrices = {
[enumDirection.top]: generateMatrixRotations([0, 1, 0, 0, 1, 0, 0, 1, 0]),
[enumDirection.left]: generateMatrixRotations([0, 0, 0, 1, 1, 0, 0, 1, 0]),
[enumDirection.right]: generateMatrixRotations([0, 0, 0, 0, 1, 1, 0, 1, 0]),
};
export class MetaBeltBaseBuilding extends MetaBuilding {}
export class MetaBeltBuilding extends MetaBuilding {
constructor() {
super("belt");
}
@ -16,12 +31,53 @@ export class MetaBeltBuilding extends MetaBeltBaseBuilding {
return SOUNDS.placeBelt;
}
getHasDirectionLockAvailable() {
return true;
}
getStayInPlacementMode() {
return true;
}
getIsReplaceable() {
return true;
}
getAvailableVariants() {
return [DefaultBeltVariant];
}
/**
* Creates the entity at the given location
* @param {Entity} entity
*/
setupEntityComponents(entity) {
entity.addComponent(
new BeltComponent({
direction: enumDirection.top, // updated later
})
);
}
}
export class DefaultBeltVariant extends DefaultBeltBaseVariant {
export class DefaultBeltVariant extends MetaBuildingVariant {
static getId() {
return defaultBuildingVariant;
}
/**
* @param {GameRoot} root
* @returns {Array<[string, string]>}
*/
static getAdditionalStatistics(root) {
const beltSpeed = root.hubGoals.getBeltBaseSpeed();
return [[T.ingame.buildingPlacement.infoTexts.speed, formatItemsPerSecond(beltSpeed)]];
}
static getRotateAutomaticallyWhilePlacing() {
return true;
}
static getPreviewSprite(rotationVariant) {
switch (arrayBeltVariantToRotation[rotationVariant]) {
case enumDirection.top: {
@ -39,6 +95,10 @@ export class DefaultBeltVariant extends DefaultBeltBaseVariant {
}
}
static getSprite() {
return null;
}
static getBlueprintSprite(rotationVariant) {
switch (arrayBeltVariantToRotation[rotationVariant]) {
case enumDirection.top: {
@ -55,4 +115,124 @@ export class DefaultBeltVariant extends DefaultBeltBaseVariant {
}
}
}
/**
*
* @param {number} rotation
* @param {number} rotationVariant
* @param {Entity} entity
*/
static getSpecialOverlayRenderMatrix(rotation, rotationVariant, entity) {
return beltOverlayMatrices[entity.components.Belt.direction][rotation];
}
/**
*
* @param {Entity} entity
* @param {number} rotationVariant
*/
static updateEntityComponents(entity, rotationVariant) {
entity.components.Belt.direction = arrayBeltVariantToRotation[rotationVariant];
}
/**
* Should compute the optimal rotation variant on the given tile
* @param {object} param0
* @param {GameRoot} param0.root
* @param {Vector} param0.tile
* @param {number} param0.rotation
* @param {Layer} param0.layer
* @return {{ rotation: number, rotationVariant: number, connectedEntities?: Array<Entity> }}
*/
static computeOptimalDirectionAndRotationVariantAtTile({ root, tile, rotation, layer }) {
const topDirection = enumAngleToDirection[rotation];
const rightDirection = enumAngleToDirection[(rotation + 90) % 360];
const bottomDirection = enumAngleToDirection[(rotation + 180) % 360];
const leftDirection = enumAngleToDirection[(rotation + 270) % 360];
const { ejectors, acceptors } = root.logic.getEjectorsAndAcceptorsAtTile(tile);
let hasBottomEjector = false;
let hasRightEjector = false;
let hasLeftEjector = false;
let hasTopAcceptor = false;
let hasLeftAcceptor = false;
let hasRightAcceptor = false;
// Check all ejectors
for (let i = 0; i < ejectors.length; ++i) {
const ejector = ejectors[i];
if (ejector.toDirection === topDirection) {
hasBottomEjector = true;
} else if (ejector.toDirection === leftDirection) {
hasRightEjector = true;
} else if (ejector.toDirection === rightDirection) {
hasLeftEjector = true;
}
}
// Check all acceptors
for (let i = 0; i < acceptors.length; ++i) {
const acceptor = acceptors[i];
if (acceptor.fromDirection === bottomDirection) {
hasTopAcceptor = true;
} else if (acceptor.fromDirection === rightDirection) {
hasLeftAcceptor = true;
} else if (acceptor.fromDirection === leftDirection) {
hasRightAcceptor = true;
}
}
// Soo .. if there is any ejector below us we always prioritize
// this ejector
if (!hasBottomEjector) {
// When something ejects to us from the left and nothing from the right,
// do a curve from the left to the top
if (hasRightEjector && !hasLeftEjector) {
return {
rotation: (rotation + 270) % 360,
rotationVariant: 2,
};
}
// When something ejects to us from the right and nothing from the left,
// do a curve from the right to the top
if (hasLeftEjector && !hasRightEjector) {
return {
rotation: (rotation + 90) % 360,
rotationVariant: 1,
};
}
}
// When there is a top acceptor, ignore sides
// NOTICE: This makes the belt prefer side turns *way* too much!
if (!hasTopAcceptor) {
// When there is an acceptor to the right but no acceptor to the left,
// do a turn to the right
if (hasRightAcceptor && !hasLeftAcceptor) {
return {
rotation,
rotationVariant: 2,
};
}
// When there is an acceptor to the left but no acceptor to the right,
// do a turn to the left
if (hasLeftAcceptor && !hasRightAcceptor) {
return {
rotation,
rotationVariant: 1,
};
}
}
return {
rotation,
rotationVariant: 0,
};
}
}

View File

@ -1,189 +0,0 @@
import { formatItemsPerSecond, generateMatrixRotations } from "../../core/utils";
import { enumAngleToDirection, enumDirection, Vector } from "../../core/vector";
import { SOUNDS } from "../../platform/sound";
import { T } from "../../translations";
import { BeltComponent } from "../components/belt";
import { Entity } from "../entity";
import { defaultBuildingVariant, MetaBuilding, MetaBuildingVariant } from "../meta_building";
import { GameRoot } from "../root";
export const arrayBeltVariantToRotation = [enumDirection.top, enumDirection.left, enumDirection.right];
export const beltOverlayMatrices = {
[enumDirection.top]: generateMatrixRotations([0, 1, 0, 0, 1, 0, 0, 1, 0]),
[enumDirection.left]: generateMatrixRotations([0, 0, 0, 1, 1, 0, 0, 1, 0]),
[enumDirection.right]: generateMatrixRotations([0, 0, 0, 0, 1, 1, 0, 1, 0]),
};
export class MetaBeltBaseBuilding extends MetaBuilding {
getHasDirectionLockAvailable() {
return true;
}
getStayInPlacementMode() {
return true;
}
getPlacementSound() {
return SOUNDS.placeBelt;
}
getIsReplaceable() {
return true;
}
/**
* Creates the entity at the given location
* @param {Entity} entity
*/
setupEntityComponents(entity) {
entity.addComponent(
new BeltComponent({
direction: enumDirection.top, // updated later
})
);
}
}
export class DefaultBeltBaseVariant extends MetaBuildingVariant {
static getId() {
return defaultBuildingVariant;
}
/**
* @param {GameRoot} root
* @returns {Array<[string, string]>}
*/
static getAdditionalStatistics(root) {
const beltSpeed = root.hubGoals.getBeltBaseSpeed();
return [[T.ingame.buildingPlacement.infoTexts.speed, formatItemsPerSecond(beltSpeed)]];
}
static getRotateAutomaticallyWhilePlacing() {
return true;
}
static getSprite() {
return null;
}
/**
*
* @param {number} rotation
* @param {number} rotationVariant
* @param {Entity} entity
*/
static getSpecialOverlayRenderMatrix(rotation, rotationVariant, entity) {
return beltOverlayMatrices[entity.components.Belt.direction][rotation];
}
/**
*
* @param {Entity} entity
* @param {number} rotationVariant
*/
static updateEntityComponents(entity, rotationVariant) {
entity.components.Belt.direction = arrayBeltVariantToRotation[rotationVariant];
}
/**
* Should compute the optimal rotation variant on the given tile
* @param {object} param0
* @param {GameRoot} param0.root
* @param {Vector} param0.tile
* @param {number} param0.rotation
* @param {Layer} param0.layer
* @return {{ rotation: number, rotationVariant: number, connectedEntities?: Array<Entity> }}
*/
static computeOptimalDirectionAndRotationVariantAtTile({ root, tile, rotation, layer }) {
const topDirection = enumAngleToDirection[rotation];
const rightDirection = enumAngleToDirection[(rotation + 90) % 360];
const bottomDirection = enumAngleToDirection[(rotation + 180) % 360];
const leftDirection = enumAngleToDirection[(rotation + 270) % 360];
const { ejectors, acceptors } = root.logic.getEjectorsAndAcceptorsAtTile(tile);
let hasBottomEjector = false;
let hasRightEjector = false;
let hasLeftEjector = false;
let hasTopAcceptor = false;
let hasLeftAcceptor = false;
let hasRightAcceptor = false;
// Check all ejectors
for (let i = 0; i < ejectors.length; ++i) {
const ejector = ejectors[i];
if (ejector.toDirection === topDirection) {
hasBottomEjector = true;
} else if (ejector.toDirection === leftDirection) {
hasRightEjector = true;
} else if (ejector.toDirection === rightDirection) {
hasLeftEjector = true;
}
}
// Check all acceptors
for (let i = 0; i < acceptors.length; ++i) {
const acceptor = acceptors[i];
if (acceptor.fromDirection === bottomDirection) {
hasTopAcceptor = true;
} else if (acceptor.fromDirection === rightDirection) {
hasLeftAcceptor = true;
} else if (acceptor.fromDirection === leftDirection) {
hasRightAcceptor = true;
}
}
// Soo .. if there is any ejector below us we always prioritize
// this ejector
if (!hasBottomEjector) {
// When something ejects to us from the left and nothing from the right,
// do a curve from the left to the top
if (hasRightEjector && !hasLeftEjector) {
return {
rotation: (rotation + 270) % 360,
rotationVariant: 2,
};
}
// When something ejects to us from the right and nothing from the left,
// do a curve from the right to the top
if (hasLeftEjector && !hasRightEjector) {
return {
rotation: (rotation + 90) % 360,
rotationVariant: 1,
};
}
}
// When there is a top acceptor, ignore sides
// NOTICE: This makes the belt prefer side turns *way* too much!
if (!hasTopAcceptor) {
// When there is an acceptor to the right but no acceptor to the left,
// do a turn to the right
if (hasRightAcceptor && !hasLeftAcceptor) {
return {
rotation,
rotationVariant: 2,
};
}
// When there is an acceptor to the left but no acceptor to the right,
// do a turn to the left
if (hasLeftAcceptor && !hasRightAcceptor) {
return {
rotation,
rotationVariant: 1,
};
}
}
return {
rotation,
rotationVariant: 0,
};
}
}

View File

@ -72,6 +72,7 @@ export class MetaSplitterBuilding extends MetaBuilding {
entity.addComponent(
new ItemEjectorComponent({
slots: [], // set later
renderFloatingItems: false,
})
);

View File

@ -1,33 +1,56 @@
import { Component } from "../component";
import { types } from "../../savegame/serialization";
import { enumDirection, Vector } from "../../core/vector";
export class BeltUnderlaysComponent extends Component {
static getId() {
return "BeltUnderlays";
}
duplicateWithoutContents() {
const beltUnderlaysCopy = [];
for (let i = 0; i < this.underlays.length; ++i) {
const underlay = this.underlays[i];
beltUnderlaysCopy.push({
pos: underlay.pos.copy(),
direction: underlay.direction,
});
}
return new BeltUnderlaysComponent({
underlays: beltUnderlaysCopy,
});
}
/**
* @param {object} param0
* @param {Array<{pos: Vector, direction: enumDirection}>=} param0.underlays Where to render belt underlays
*/
constructor({ underlays }) {
super();
this.underlays = underlays;
}
}
import { enumDirection, Vector } from "../../core/vector";
import { Component } from "../component";
/**
* Store which type an underlay is, this is cached so we can easily
* render it.
*
* Full: Render underlay at top and bottom of tile
* Bottom Only: Only render underlay at the bottom half
* Top Only:
* @enum {string}
*/
export const enumClippedBeltUnderlayType = {
full: "full",
bottomOnly: "bottomOnly",
topOnly: "topOnly",
none: "none",
};
/**
* @typedef {{
* pos: Vector,
* direction: enumDirection,
* cachedType?: enumClippedBeltUnderlayType
* }} BeltUnderlayTile
*/
export class BeltUnderlaysComponent extends Component {
static getId() {
return "BeltUnderlays";
}
duplicateWithoutContents() {
const beltUnderlaysCopy = [];
for (let i = 0; i < this.underlays.length; ++i) {
const underlay = this.underlays[i];
beltUnderlaysCopy.push({
pos: underlay.pos.copy(),
direction: underlay.direction,
});
}
return new BeltUnderlaysComponent({
underlays: beltUnderlaysCopy,
});
}
/**
* @param {object} param0
* @param {Array<BeltUnderlayTile>=} param0.underlays Where to render belt underlays
*/
constructor({ underlays = [] }) {
super();
this.underlays = underlays;
}
}

View File

@ -1,161 +1,159 @@
import { enumDirection, enumDirectionToVector, Vector } from "../../core/vector";
import { types } from "../../savegame/serialization";
import { BaseItem } from "../base_item";
import { BeltPath } from "../belt_path";
import { Component } from "../component";
import { Entity } from "../entity";
import { typeItemSingleton } from "../item_resolver";
/**
* @typedef {{
* pos: Vector,
* direction: enumDirection,
* item: BaseItem,
* progress: number?,
* cachedDestSlot?: import("./item_acceptor").ItemAcceptorLocatedSlot,
* cachedBeltPath?: BeltPath,
* cachedTargetEntity?: Entity
* }} ItemEjectorSlot
*/
export class ItemEjectorComponent extends Component {
static getId() {
return "ItemEjector";
}
static getSchema() {
// The cachedDestSlot, cachedTargetEntity fields are not serialized.
return {
slots: types.array(
types.structured({
item: types.nullable(typeItemSingleton),
progress: types.float,
})
),
};
}
duplicateWithoutContents() {
const slotsCopy = [];
for (let i = 0; i < this.slots.length; ++i) {
const slot = this.slots[i];
slotsCopy.push({
pos: slot.pos.copy(),
direction: slot.direction,
});
}
return new ItemEjectorComponent({
slots: slotsCopy,
});
}
/**
*
* @param {object} param0
* @param {Array<{pos: Vector, direction: enumDirection }>=} param0.slots The slots to eject on
*/
constructor({ slots = [] }) {
super();
this.setSlots(slots);
/**
* Whether this ejector slot is enabled
*/
this.enabled = true;
}
/**
* @param {Array<{pos: Vector, direction: enumDirection }>} slots The slots to eject on
*/
setSlots(slots) {
/** @type {Array<ItemEjectorSlot>} */
this.slots = [];
for (let i = 0; i < slots.length; ++i) {
const slot = slots[i];
this.slots.push({
pos: slot.pos,
direction: slot.direction,
item: null,
progress: 0,
cachedDestSlot: null,
cachedTargetEntity: null,
});
}
}
/**
* Returns where this slot ejects to
* @param {ItemEjectorSlot} slot
* @returns {Vector}
*/
getSlotTargetLocalTile(slot) {
const directionVector = enumDirectionToVector[slot.direction];
return slot.pos.add(directionVector);
}
/**
* Returns whether any slot ejects to the given local tile
* @param {Vector} tile
*/
anySlotEjectsToLocalTile(tile) {
for (let i = 0; i < this.slots.length; ++i) {
if (this.getSlotTargetLocalTile(this.slots[i]).equals(tile)) {
return true;
}
}
return false;
}
/**
* Returns if we can eject on a given slot
* @param {number} slotIndex
* @returns {boolean}
*/
canEjectOnSlot(slotIndex) {
assert(slotIndex >= 0 && slotIndex < this.slots.length, "Invalid ejector slot: " + slotIndex);
return !this.slots[slotIndex].item;
}
/**
* Returns the first free slot on this ejector or null if there is none
* @returns {number?}
*/
getFirstFreeSlot() {
for (let i = 0; i < this.slots.length; ++i) {
if (this.canEjectOnSlot(i)) {
return i;
}
}
return null;
}
/**
* Tries to eject a given item
* @param {number} slotIndex
* @param {BaseItem} item
* @returns {boolean}
*/
tryEject(slotIndex, item) {
if (!this.canEjectOnSlot(slotIndex)) {
return false;
}
this.slots[slotIndex].item = item;
this.slots[slotIndex].progress = 0;
return true;
}
/**
* Clears the given slot and returns the item it had
* @param {number} slotIndex
* @returns {BaseItem|null}
*/
takeSlotItem(slotIndex) {
const slot = this.slots[slotIndex];
const item = slot.item;
slot.item = null;
slot.progress = 0.0;
return item;
}
}
import { enumDirection, enumDirectionToVector, Vector } from "../../core/vector";
import { types } from "../../savegame/serialization";
import { BaseItem } from "../base_item";
import { BeltPath } from "../belt_path";
import { Component } from "../component";
import { Entity } from "../entity";
import { typeItemSingleton } from "../item_resolver";
/**
* @typedef {{
* pos: Vector,
* direction: enumDirection,
* item: BaseItem,
* progress: number?,
* cachedDestSlot?: import("./item_acceptor").ItemAcceptorLocatedSlot,
* cachedBeltPath?: BeltPath,
* cachedTargetEntity?: Entity
* }} ItemEjectorSlot
*/
export class ItemEjectorComponent extends Component {
static getId() {
return "ItemEjector";
}
static getSchema() {
// The cachedDestSlot, cachedTargetEntity fields are not serialized.
return {
slots: types.array(
types.structured({
item: types.nullable(typeItemSingleton),
progress: types.float,
})
),
};
}
duplicateWithoutContents() {
const slotsCopy = [];
for (let i = 0; i < this.slots.length; ++i) {
const slot = this.slots[i];
slotsCopy.push({
pos: slot.pos.copy(),
direction: slot.direction,
});
}
return new ItemEjectorComponent({
slots: slotsCopy,
renderFloatingItems: this.renderFloatingItems,
});
}
/**
*
* @param {object} param0
* @param {Array<{pos: Vector, direction: enumDirection }>=} param0.slots The slots to eject on
* @param {boolean=} param0.renderFloatingItems Whether to render items even if they are not connected
*/
constructor({ slots = [], renderFloatingItems = true }) {
super();
this.setSlots(slots);
this.renderFloatingItems = renderFloatingItems;
}
/**
* @param {Array<{pos: Vector, direction: enumDirection }>} slots The slots to eject on
*/
setSlots(slots) {
/** @type {Array<ItemEjectorSlot>} */
this.slots = [];
for (let i = 0; i < slots.length; ++i) {
const slot = slots[i];
this.slots.push({
pos: slot.pos,
direction: slot.direction,
item: null,
progress: 0,
cachedDestSlot: null,
cachedTargetEntity: null,
});
}
}
/**
* Returns where this slot ejects to
* @param {ItemEjectorSlot} slot
* @returns {Vector}
*/
getSlotTargetLocalTile(slot) {
const directionVector = enumDirectionToVector[slot.direction];
return slot.pos.add(directionVector);
}
/**
* Returns whether any slot ejects to the given local tile
* @param {Vector} tile
*/
anySlotEjectsToLocalTile(tile) {
for (let i = 0; i < this.slots.length; ++i) {
if (this.getSlotTargetLocalTile(this.slots[i]).equals(tile)) {
return true;
}
}
return false;
}
/**
* Returns if we can eject on a given slot
* @param {number} slotIndex
* @returns {boolean}
*/
canEjectOnSlot(slotIndex) {
assert(slotIndex >= 0 && slotIndex < this.slots.length, "Invalid ejector slot: " + slotIndex);
return !this.slots[slotIndex].item;
}
/**
* Returns the first free slot on this ejector or null if there is none
* @returns {number?}
*/
getFirstFreeSlot() {
for (let i = 0; i < this.slots.length; ++i) {
if (this.canEjectOnSlot(i)) {
return i;
}
}
return null;
}
/**
* Tries to eject a given item
* @param {number} slotIndex
* @param {BaseItem} item
* @returns {boolean}
*/
tryEject(slotIndex, item) {
if (!this.canEjectOnSlot(slotIndex)) {
return false;
}
this.slots[slotIndex].item = item;
this.slots[slotIndex].progress = 0;
return true;
}
/**
* Clears the given slot and returns the item it had
* @param {number} slotIndex
* @returns {BaseItem|null}
*/
takeSlotItem(slotIndex) {
const slot = this.slots[slotIndex];
const item = slot.item;
slot.item = null;
slot.progress = 0.0;
return item;
}
}

View File

@ -1,21 +1,21 @@
import { MetaBeltBaseBuilding } from "../../buildings/belt_base";
import { MetaBeltBuilding } from "../../buildings/belt";
import { MetaCutterBuilding } from "../../buildings/cutter";
import { MetaDisplayBuilding } from "../../buildings/display";
import { MetaFilterBuilding } from "../../buildings/filter";
import { MetaLeverBuilding } from "../../buildings/lever";
import { MetaMinerBuilding } from "../../buildings/miner";
import { MetaMixerBuilding } from "../../buildings/mixer";
import { MetaPainterBuilding } from "../../buildings/painter";
import { MetaReaderBuilding } from "../../buildings/reader";
import { MetaRotaterBuilding } from "../../buildings/rotater";
import { MetaSplitterBuilding } from "../../buildings/splitter";
import { MetaStackerBuilding } from "../../buildings/stacker";
import { MetaTrashBuilding } from "../../buildings/trash";
import { MetaUndergroundBeltBuilding } from "../../buildings/underground_belt";
import { HUDBaseToolbar } from "./base_toolbar";
import { MetaLeverBuilding } from "../../buildings/lever";
import { MetaFilterBuilding } from "../../buildings/filter";
import { MetaDisplayBuilding } from "../../buildings/display";
import { MetaReaderBuilding } from "../../buildings/reader";
const supportedBuildings = [
MetaBeltBaseBuilding,
MetaBeltBuilding,
MetaSplitterBuilding,
MetaUndergroundBeltBuilding,
MetaMinerBuilding,

View File

@ -67,7 +67,7 @@ export class HUDMinerHighlight extends BaseHUDPart {
const maxThroughput = this.root.hubGoals.getBeltBaseSpeed();
const screenPos = this.root.camera.screenToWorld(mousePos);
const tooltipLocation = this.root.camera.screenToWorld(mousePos);
const scale = (1 / this.root.camera.zoomLevel) * this.root.app.getEffectiveUiScale();
@ -76,8 +76,8 @@ export class HUDMinerHighlight extends BaseHUDPart {
// Background
parameters.context.fillStyle = THEME.map.connectedMiners.background;
parameters.context.beginRoundedRect(
screenPos.x + 5 * scale,
screenPos.y - 3 * scale,
tooltipLocation.x + 5 * scale,
tooltipLocation.y - 3 * scale,
(isCapped ? 100 : 65) * scale,
(isCapped ? 45 : 30) * scale,
2
@ -89,8 +89,8 @@ export class HUDMinerHighlight extends BaseHUDPart {
parameters.context.font = "bold " + scale * 10 + "px GameFont";
parameters.context.fillText(
formatItemsPerSecond(throughput),
screenPos.x + 10 * scale,
screenPos.y + 10 * scale
tooltipLocation.x + 10 * scale,
tooltipLocation.y + 10 * scale
);
// Amount of miners
@ -100,8 +100,8 @@ export class HUDMinerHighlight extends BaseHUDPart {
connectedEntities.length === 1
? T.ingame.connectedMiners.one_miner
: T.ingame.connectedMiners.n_miners.replace("<amount>", String(connectedEntities.length)),
screenPos.x + 10 * scale,
screenPos.y + 22 * scale
tooltipLocation.x + 10 * scale,
tooltipLocation.y + 22 * scale
);
parameters.context.globalAlpha = 1;
@ -113,8 +113,8 @@ export class HUDMinerHighlight extends BaseHUDPart {
"<max_throughput>",
formatItemsPerSecond(maxThroughput)
),
screenPos.x + 10 * scale,
screenPos.y + 34 * scale
tooltipLocation.x + 10 * scale,
tooltipLocation.y + 34 * scale
);
}
}

View File

@ -1,125 +1,122 @@
import { GameRoot } from "../root";
import { globalConfig } from "../../core/config";
import { Vector, mixVector } from "../../core/vector";
import { lerp } from "../../core/utils";
/* dev:start */
import trailerPoints from "./trailer_points";
import { gMetaBuildingRegistry } from "../../core/global_registries";
import { MetaBeltBaseBuilding } from "../buildings/belt_base";
import { MinerComponent } from "../components/miner";
const tickrate = 1 / 165;
export class TrailerMaker {
/**
*
* @param {GameRoot} root
*/
constructor(root) {
this.root = root;
this.markers = [];
this.playbackMarkers = null;
this.currentPlaybackOrigin = new Vector();
this.currentPlaybackZoom = 3;
window.addEventListener("keydown", ev => {
if (ev.key === "j") {
console.log("Record");
this.markers.push({
pos: this.root.camera.center.copy(),
zoom: this.root.camera.zoomLevel,
time: 1,
wait: 0,
});
} else if (ev.key === "k") {
console.log("Export");
const json = JSON.stringify(this.markers);
const handle = window.open("about:blank");
handle.document.write(json);
} else if (ev.key === "u") {
if (this.playbackMarkers && this.playbackMarkers.length > 0) {
this.playbackMarkers = [];
return;
}
console.log("Playback");
this.playbackMarkers = trailerPoints.map(p => Object.assign({}, p));
this.playbackMarkers.unshift(this.playbackMarkers[0]);
this.currentPlaybackOrigin = Vector.fromSerializedObject(this.playbackMarkers[0].pos);
this.currentPlaybackZoom = this.playbackMarkers[0].zoom;
this.root.camera.center = this.currentPlaybackOrigin.copy();
this.root.camera.zoomLevel = this.currentPlaybackZoom;
console.log("STart at", this.currentPlaybackOrigin);
// this.root.entityMgr.getAllWithComponent(MinerComponent).forEach(miner => {
// miner.components.Miner.itemChainBuffer = [];
// miner.components.Miner.lastMiningTime = this.root.time.now() + 5;
// miner.components.ItemEjector.slots.forEach(slot => (slot.item = null));
// });
// this.root.logic.tryPlaceBuilding({
// origin: new Vector(-428, -15),
// building: gMetaBuildingRegistry.findByClass(MetaBeltBaseBuilding),
// originalRotation: 0,
// rotation: 0,
// variant: "default",
// rotationVariant: 0,
// });
// this.root.logic.tryPlaceBuilding({
// origin: new Vector(-427, -15),
// building: gMetaBuildingRegistry.findByClass(MetaBeltBaseBuilding),
// originalRotation: 0,
// rotation: 0,
// variant: "default",
// rotationVariant: 0,
// });
}
});
}
update() {
if (this.playbackMarkers && this.playbackMarkers.length > 0) {
const nextMarker = this.playbackMarkers[0];
if (!nextMarker.startTime) {
console.log("Starting to approach", nextMarker.pos);
nextMarker.startTime = performance.now() / 1000.0;
}
const speed =
globalConfig.tileSize *
globalConfig.beltSpeedItemsPerSecond *
globalConfig.itemSpacingOnBelts;
// let time =
// this.currentPlaybackOrigin.distance(Vector.fromSerializedObject(nextMarker.pos)) / speed;
const time = nextMarker.time;
const progress = (performance.now() / 1000.0 - nextMarker.startTime) / time;
if (progress > 1.0) {
if (nextMarker.wait > 0) {
nextMarker.wait -= tickrate;
} else {
console.log("Approached");
this.currentPlaybackOrigin = this.root.camera.center.copy();
this.currentPlaybackZoom = this.root.camera.zoomLevel;
this.playbackMarkers.shift();
}
return;
}
const targetPos = Vector.fromSerializedObject(nextMarker.pos);
const targetZoom = nextMarker.zoom;
const pos = mixVector(this.currentPlaybackOrigin, targetPos, progress);
const zoom = lerp(this.currentPlaybackZoom, targetZoom, progress);
this.root.camera.zoomLevel = zoom;
this.root.camera.center = pos;
}
}
}
/* dev:end */
import { GameRoot } from "../root";
import { globalConfig } from "../../core/config";
import { Vector, mixVector } from "../../core/vector";
import { lerp } from "../../core/utils";
/* dev:start */
import trailerPoints from "./trailer_points";
const tickrate = 1 / 165;
export class TrailerMaker {
/**
*
* @param {GameRoot} root
*/
constructor(root) {
this.root = root;
this.markers = [];
this.playbackMarkers = null;
this.currentPlaybackOrigin = new Vector();
this.currentPlaybackZoom = 3;
window.addEventListener("keydown", ev => {
if (ev.key === "j") {
console.log("Record");
this.markers.push({
pos: this.root.camera.center.copy(),
zoom: this.root.camera.zoomLevel,
time: 1,
wait: 0,
});
} else if (ev.key === "k") {
console.log("Export");
const json = JSON.stringify(this.markers);
const handle = window.open("about:blank");
handle.document.write(json);
} else if (ev.key === "u") {
if (this.playbackMarkers && this.playbackMarkers.length > 0) {
this.playbackMarkers = [];
return;
}
console.log("Playback");
this.playbackMarkers = trailerPoints.map(p => Object.assign({}, p));
this.playbackMarkers.unshift(this.playbackMarkers[0]);
this.currentPlaybackOrigin = Vector.fromSerializedObject(this.playbackMarkers[0].pos);
this.currentPlaybackZoom = this.playbackMarkers[0].zoom;
this.root.camera.center = this.currentPlaybackOrigin.copy();
this.root.camera.zoomLevel = this.currentPlaybackZoom;
console.log("STart at", this.currentPlaybackOrigin);
// this.root.entityMgr.getAllWithComponent(MinerComponent).forEach(miner => {
// miner.components.Miner.itemChainBuffer = [];
// miner.components.Miner.lastMiningTime = this.root.time.now() + 5;
// miner.components.ItemEjector.slots.forEach(slot => (slot.item = null));
// });
// this.root.logic.tryPlaceBuilding({
// origin: new Vector(-428, -15),
// building: gMetaBuildingRegistry.findByClass(MetaBeltBaseBuilding),
// originalRotation: 0,
// rotation: 0,
// variant: "default",
// rotationVariant: 0,
// });
// this.root.logic.tryPlaceBuilding({
// origin: new Vector(-427, -15),
// building: gMetaBuildingRegistry.findByClass(MetaBeltBaseBuilding),
// originalRotation: 0,
// rotation: 0,
// variant: "default",
// rotationVariant: 0,
// });
}
});
}
update() {
if (this.playbackMarkers && this.playbackMarkers.length > 0) {
const nextMarker = this.playbackMarkers[0];
if (!nextMarker.startTime) {
console.log("Starting to approach", nextMarker.pos);
nextMarker.startTime = performance.now() / 1000.0;
}
const speed =
globalConfig.tileSize *
globalConfig.beltSpeedItemsPerSecond *
globalConfig.itemSpacingOnBelts;
// let time =
// this.currentPlaybackOrigin.distance(Vector.fromSerializedObject(nextMarker.pos)) / speed;
const time = nextMarker.time;
const progress = (performance.now() / 1000.0 - nextMarker.startTime) / time;
if (progress > 1.0) {
if (nextMarker.wait > 0) {
nextMarker.wait -= tickrate;
} else {
console.log("Approached");
this.currentPlaybackOrigin = this.root.camera.center.copy();
this.currentPlaybackZoom = this.root.camera.zoomLevel;
this.playbackMarkers.shift();
}
return;
}
const targetPos = Vector.fromSerializedObject(nextMarker.pos);
const targetZoom = nextMarker.zoom;
const pos = mixVector(this.currentPlaybackOrigin, targetPos, progress);
const zoom = lerp(this.currentPlaybackZoom, targetZoom, progress);
this.root.camera.zoomLevel = zoom;
this.root.camera.center = pos;
}
}
}
/* dev:end */

View File

@ -1,7 +1,6 @@
import { gMetaBuildingRegistry } from "../core/global_registries";
import { createLogger } from "../core/logging";
import { DefaultBeltVariant, MetaBeltBuilding } from "./buildings/belt";
import { DefaultBeltBaseVariant, MetaBeltBaseBuilding } from "./buildings/belt_base";
import {
DefaultCutterVariant,
enumCutterVariants,
@ -111,9 +110,9 @@ export function initMetaBuildingRegistry() {
gMetaBuildingRegistry.register(MetaReaderBuilding);
// Belt
registerBuildingVariant(1, MetaBeltBaseBuilding, DefaultBeltVariant, 0);
registerBuildingVariant(2, MetaBeltBaseBuilding, DefaultBeltVariant, 1);
registerBuildingVariant(3, MetaBeltBaseBuilding, DefaultBeltVariant, 2);
registerBuildingVariant(1, MetaBeltBuilding, DefaultBeltVariant, 0);
registerBuildingVariant(2, MetaBeltBuilding, DefaultBeltVariant, 1);
registerBuildingVariant(3, MetaBeltBuilding, DefaultBeltVariant, 2);
// Splitter
registerBuildingVariant(4, MetaSplitterBuilding, DefaultSplitterVariant);

View File

@ -7,13 +7,13 @@ import { AtlasSprite } from "../../core/sprites";
import { fastArrayDeleteValue } from "../../core/utils";
import { enumDirection, enumDirectionToVector, enumInvertedDirections, Vector } from "../../core/vector";
import { BeltPath } from "../belt_path";
import { arrayBeltVariantToRotation, MetaBeltBaseBuilding } from "../buildings/belt_base";
import { BeltComponent } from "../components/belt";
import { Entity } from "../entity";
import { GameSystemWithFilter } from "../game_system_with_filter";
import { MapChunkView } from "../map_chunk_view";
import { defaultBuildingVariant } from "../meta_building";
import { getCodeFromBuildingData } from "../building_codes";
import { arrayBeltVariantToRotation, MetaBeltBuilding } from "../buildings/belt";
export const BELT_ANIM_COUNT = 14;
@ -123,7 +123,7 @@ export class BeltSystem extends GameSystemWithFilter {
return;
}
const metaBelt = gMetaBuildingRegistry.findByClass(MetaBeltBaseBuilding);
const metaBelt = gMetaBuildingRegistry.findByClass(MetaBeltBuilding);
// Compute affected area
const originalRect = staticComp.getTileSpaceBounds();
const affectedArea = originalRect.expandedInAllDirections(1);

View File

@ -1,84 +1,300 @@
import { globalConfig } from "../../core/config";
import { drawRotatedSprite } from "../../core/draw_utils";
import { Loader } from "../../core/loader";
import { enumDirectionToAngle } from "../../core/vector";
import { BeltUnderlaysComponent } from "../components/belt_underlays";
import { GameSystemWithFilter } from "../game_system_with_filter";
import { BELT_ANIM_COUNT } from "./belt";
import { MapChunkView } from "../map_chunk_view";
import { DrawParameters } from "../../core/draw_parameters";
export class BeltUnderlaysSystem extends GameSystemWithFilter {
constructor(root) {
super(root, [BeltUnderlaysComponent]);
this.underlayBeltSprites = [];
for (let i = 0; i < BELT_ANIM_COUNT; ++i) {
this.underlayBeltSprites.push(Loader.getSprite("sprites/belt/built/forward_" + i + ".png"));
}
}
/**
* Draws a given chunk
* @param {DrawParameters} parameters
* @param {MapChunkView} chunk
*/
drawChunk(parameters, chunk) {
// Limit speed to avoid belts going backwards
const speedMultiplier = Math.min(this.root.hubGoals.getBeltBaseSpeed(), 10);
const contents = chunk.containedEntitiesByLayer.regular;
for (let i = 0; i < contents.length; ++i) {
const entity = contents[i];
const underlayComp = entity.components.BeltUnderlays;
if (!underlayComp) {
continue;
}
const staticComp = entity.components.StaticMapEntity;
const underlays = underlayComp.underlays;
for (let i = 0; i < underlays.length; ++i) {
const { pos, direction } = underlays[i];
const transformedPos = staticComp.localTileToWorld(pos);
// Culling
if (!chunk.tileSpaceRectangle.containsPoint(transformedPos.x, transformedPos.y)) {
continue;
}
const destX = transformedPos.x * globalConfig.tileSize;
const destY = transformedPos.y * globalConfig.tileSize;
// Culling, #2
if (
!parameters.visibleRect.containsRect4Params(
destX,
destY,
globalConfig.tileSize,
globalConfig.tileSize
)
) {
continue;
}
const angle = enumDirectionToAngle[staticComp.localDirectionToWorld(direction)];
// SYNC with systems/belt.js:drawSingleEntity!
const animationIndex = Math.floor(
((this.root.time.realtimeNow() * speedMultiplier * BELT_ANIM_COUNT * 126) / 42) *
globalConfig.itemSpacingOnBelts
);
drawRotatedSprite({
parameters,
sprite: this.underlayBeltSprites[animationIndex % this.underlayBeltSprites.length],
x: destX + globalConfig.halfTileSize,
y: destY + globalConfig.halfTileSize,
angle: Math.radians(angle),
size: globalConfig.tileSize,
});
}
}
}
}
import { globalConfig } from "../../core/config";
import { DrawParameters } from "../../core/draw_parameters";
import { Loader } from "../../core/loader";
import { Rectangle } from "../../core/rectangle";
import { FULL_CLIP_RECT } from "../../core/sprites";
import { StaleAreaDetector } from "../../core/stale_area_detector";
import {
enumDirection,
enumDirectionToAngle,
enumDirectionToVector,
enumInvertedDirections,
Vector,
} from "../../core/vector";
import { BeltComponent } from "../components/belt";
import { BeltUnderlaysComponent, enumClippedBeltUnderlayType } from "../components/belt_underlays";
import { ItemAcceptorComponent } from "../components/item_acceptor";
import { ItemEjectorComponent } from "../components/item_ejector";
import { Entity } from "../entity";
import { GameSystemWithFilter } from "../game_system_with_filter";
import { MapChunkView } from "../map_chunk_view";
import { BELT_ANIM_COUNT } from "./belt";
/**
* Mapping from underlay type to clip rect
* @type {Object<enumClippedBeltUnderlayType, Rectangle>}
*/
const enumUnderlayTypeToClipRect = {
[enumClippedBeltUnderlayType.none]: null,
[enumClippedBeltUnderlayType.full]: FULL_CLIP_RECT,
[enumClippedBeltUnderlayType.topOnly]: new Rectangle(0, 0, 1, 0.5),
[enumClippedBeltUnderlayType.bottomOnly]: new Rectangle(0, 0.5, 1, 0.5),
};
export class BeltUnderlaysSystem extends GameSystemWithFilter {
constructor(root) {
super(root, [BeltUnderlaysComponent]);
this.underlayBeltSprites = [];
for (let i = 0; i < BELT_ANIM_COUNT; ++i) {
this.underlayBeltSprites.push(Loader.getSprite("sprites/belt/built/forward_" + i + ".png"));
}
// Automatically recompute areas
this.staleArea = new StaleAreaDetector({
root,
name: "belt-underlay",
recomputeMethod: this.recomputeStaleArea.bind(this),
});
this.staleArea.recomputeOnComponentsChanged(
[BeltUnderlaysComponent, BeltComponent, ItemAcceptorComponent, ItemEjectorComponent],
1
);
}
update() {
this.staleArea.update();
}
/**
* Called when an area changed - Resets all caches in the given area
* @param {Rectangle} area
*/
recomputeStaleArea(area) {
for (let x = 0; x < area.w; ++x) {
for (let y = 0; y < area.h; ++y) {
const tileX = area.x + x;
const tileY = area.y + y;
const entity = this.root.map.getLayerContentXY(tileX, tileY, "regular");
if (entity) {
const underlayComp = entity.components.BeltUnderlays;
if (underlayComp) {
for (let i = 0; i < underlayComp.underlays.length; ++i) {
underlayComp.underlays[i].cachedType = null;
}
}
}
}
}
}
/**
* Checks if a given tile is connected and has an acceptor
* @param {Vector} tile
* @param {enumDirection} fromDirection
* @returns {boolean}
*/
checkIsAcceptorConnected(tile, fromDirection) {
const contents = this.root.map.getLayerContentXY(tile.x, tile.y, "regular");
if (!contents) {
return false;
}
const staticComp = contents.components.StaticMapEntity;
// Check if its a belt, since then its simple
const beltComp = contents.components.Belt;
if (beltComp) {
return staticComp.localDirectionToWorld(enumDirection.bottom) === fromDirection;
}
// Check if there's an item acceptor
const acceptorComp = contents.components.ItemAcceptor;
if (acceptorComp) {
// Check each slot to see if its connected
for (let i = 0; i < acceptorComp.slots.length; ++i) {
const slot = acceptorComp.slots[i];
const slotTile = staticComp.localTileToWorld(slot.pos);
// Step 1: Check if the tile matches
if (!slotTile.equals(tile)) {
continue;
}
// Step 2: Check if any of the directions matches
for (let j = 0; j < slot.directions.length; ++j) {
const slotDirection = staticComp.localDirectionToWorld(slot.directions[j]);
if (slotDirection === fromDirection) {
return true;
}
}
}
}
return false;
}
/**
* Checks if a given tile is connected and has an ejector
* @param {Vector} tile
* @param {enumDirection} toDirection
* @returns {boolean}
*/
checkIsEjectorConnected(tile, toDirection) {
const contents = this.root.map.getLayerContentXY(tile.x, tile.y, "regular");
if (!contents) {
return false;
}
const staticComp = contents.components.StaticMapEntity;
// Check if its a belt, since then its simple
const beltComp = contents.components.Belt;
if (beltComp) {
return staticComp.localDirectionToWorld(beltComp.direction) === toDirection;
}
// Check for an ejector
const ejectorComp = contents.components.ItemEjector;
if (ejectorComp) {
// Check each slot to see if its connected
for (let i = 0; i < ejectorComp.slots.length; ++i) {
const slot = ejectorComp.slots[i];
const slotTile = staticComp.localTileToWorld(slot.pos);
// Step 1: Check if the tile matches
if (!slotTile.equals(tile)) {
continue;
}
// Step 2: Check if the direction matches
const slotDirection = staticComp.localDirectionToWorld(slot.direction);
if (slotDirection === toDirection) {
return true;
}
}
}
return false;
}
/**
* Computes the flag for a given tile
* @param {Entity} entity
* @param {import("../components/belt_underlays").BeltUnderlayTile} underlayTile
* @returns {enumClippedBeltUnderlayType} The type of the underlay
*/
computeBeltUnderlayType(entity, underlayTile) {
if (underlayTile.cachedType) {
return underlayTile.cachedType;
}
const staticComp = entity.components.StaticMapEntity;
const transformedPos = staticComp.localTileToWorld(underlayTile.pos);
const destX = transformedPos.x * globalConfig.tileSize;
const destY = transformedPos.y * globalConfig.tileSize;
// Extract direction and angle
const worldDirection = staticComp.localDirectionToWorld(underlayTile.direction);
const worldDirectionVector = enumDirectionToVector[worldDirection];
// Figure out if there is anything connected at the top
const connectedTop = this.checkIsAcceptorConnected(
transformedPos.add(worldDirectionVector),
enumInvertedDirections[worldDirection]
);
// Figure out if there is anything connected at the bottom
const connectedBottom = this.checkIsEjectorConnected(
transformedPos.sub(worldDirectionVector),
worldDirection
);
let flag = enumClippedBeltUnderlayType.none;
if (connectedTop && connectedBottom) {
flag = enumClippedBeltUnderlayType.full;
} else if (connectedTop) {
flag = enumClippedBeltUnderlayType.topOnly;
} else if (connectedBottom) {
flag = enumClippedBeltUnderlayType.bottomOnly;
}
return (underlayTile.cachedType = flag);
}
/**
* Draws a given chunk
* @param {DrawParameters} parameters
* @param {MapChunkView} chunk
*/
drawChunk(parameters, chunk) {
// Limit speed to avoid belts going backwards
const speedMultiplier = Math.min(this.root.hubGoals.getBeltBaseSpeed(), 10);
const contents = chunk.containedEntitiesByLayer.regular;
for (let i = 0; i < contents.length; ++i) {
const entity = contents[i];
const underlayComp = entity.components.BeltUnderlays;
if (!underlayComp) {
continue;
}
const staticComp = entity.components.StaticMapEntity;
const underlays = underlayComp.underlays;
for (let i = 0; i < underlays.length; ++i) {
// Extract underlay parameters
const { pos, direction } = underlays[i];
const transformedPos = staticComp.localTileToWorld(pos);
const destX = transformedPos.x * globalConfig.tileSize;
const destY = transformedPos.y * globalConfig.tileSize;
// Culling, Part 1: Check if the chunk contains the tile
if (!chunk.tileSpaceRectangle.containsPoint(transformedPos.x, transformedPos.y)) {
continue;
}
// Culling, Part 2: Check if the overlay is visible
if (
!parameters.visibleRect.containsRect4Params(
destX,
destY,
globalConfig.tileSize,
globalConfig.tileSize
)
) {
continue;
}
// Extract direction and angle
const worldDirection = staticComp.localDirectionToWorld(direction);
const angle = enumDirectionToAngle[worldDirection];
const underlayType = this.computeBeltUnderlayType(entity, underlays[i]);
const clipRect = enumUnderlayTypeToClipRect[underlayType];
if (!clipRect) {
// Empty
continue;
}
// Actually draw the sprite
const x = destX + globalConfig.halfTileSize;
const y = destY + globalConfig.halfTileSize;
const angleRadians = Math.radians(angle);
// SYNC with systems/belt.js:drawSingleEntity!
const animationIndex = Math.floor(
((this.root.time.realtimeNow() * speedMultiplier * BELT_ANIM_COUNT * 126) / 42) *
globalConfig.itemSpacingOnBelts
);
parameters.context.translate(x, y);
parameters.context.rotate(angleRadians);
this.underlayBeltSprites[
animationIndex % this.underlayBeltSprites.length
].drawCachedWithClipRect(
parameters,
-globalConfig.halfTileSize,
-globalConfig.halfTileSize,
globalConfig.tileSize,
globalConfig.tileSize,
clipRect
);
parameters.context.rotate(-angleRadians);
parameters.context.translate(-x, -y);
}
}
}
}

View File

@ -198,9 +198,6 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
for (let i = 0; i < this.allEntities.length; ++i) {
const sourceEntity = this.allEntities[i];
const sourceEjectorComp = sourceEntity.components.ItemEjector;
if (!sourceEjectorComp.enabled) {
continue;
}
const slots = sourceEjectorComp.slots;
for (let j = 0; j < slots.length; ++j) {
@ -211,8 +208,6 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
continue;
}
const targetEntity = sourceSlot.cachedTargetEntity;
// Advance items on the slot
sourceSlot.progress = Math.min(
1,
@ -245,15 +240,16 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
}
// Check if the target acceptor can actually accept this item
const destEntity = sourceSlot.cachedTargetEntity;
const destSlot = sourceSlot.cachedDestSlot;
if (destSlot) {
const targetAcceptorComp = targetEntity.components.ItemAcceptor;
const targetAcceptorComp = destEntity.components.ItemAcceptor;
if (!targetAcceptorComp.canAcceptItem(destSlot.index, item)) {
continue;
}
// Try to hand over the item
if (this.tryPassOverItem(item, targetEntity, destSlot.index)) {
if (this.tryPassOverItem(item, destEntity, destSlot.index)) {
// Handover successful, clear slot
targetAcceptorComp.onItemAccepted(destSlot.index, destSlot.acceptedDirection, item);
sourceSlot.item = null;
@ -357,6 +353,11 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
continue;
}
if (!ejectorComp.renderFloatingItems && !slot.cachedTargetEntity) {
// Not connected to any building
continue;
}
const realPosition = staticComp.localTileToWorld(slot.pos);
if (!chunk.tileSpaceRectangle.containsPoint(realPosition.x, realPosition.y)) {
// Not within this chunk

View File

@ -133,7 +133,7 @@ export class MainMenuState extends GameState {
!this.app.platformWrapper.getHasUnlimitedSavegames()
) {
this.app.analytics.trackUiClick("importgame_slot_limit_show");
this.dialogs.showWarning(T.dialogs.oneSavegameLimit.title, T.dialogs.oneSavegameLimit.desc);
this.showSavegameSlotLimit();
return;
}
@ -522,6 +522,21 @@ export class MainMenuState extends GameState {
});
}
/**
* Shows a hint that the slot limit has been reached
*/
showSavegameSlotLimit() {
const { getStandalone } = this.dialogs.showWarning(
T.dialogs.oneSavegameLimit.title,
T.dialogs.oneSavegameLimit.desc,
["cancel:bad", "getStandalone:good"]
);
getStandalone.add(() => {
this.app.analytics.trackUiClick("visit_steampage_from_slot_limit");
this.app.platformWrapper.openExternalLink(THIRDPARTY_URLS.standaloneStorePage);
});
}
onSettingsButtonClicked() {
this.moveToState("SettingsState");
}
@ -540,7 +555,7 @@ export class MainMenuState extends GameState {
!this.app.platformWrapper.getHasUnlimitedSavegames()
) {
this.app.analytics.trackUiClick("startgame_slot_limit_show");
this.dialogs.showWarning(T.dialogs.oneSavegameLimit.title, T.dialogs.oneSavegameLimit.desc);
this.showSavegameSlotLimit();
return;
}