1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Further work on the energy generator

This commit is contained in:
tobspr
2020-06-28 11:44:30 +02:00
parent 97858b6eab
commit 17123fd7b9
37 changed files with 1188 additions and 1067 deletions

View File

@@ -73,8 +73,9 @@ export class GameHUD {
screenshotExporter: new HUDScreenshotExporter(this.root),
shapeViewer: new HUDShapeViewer(this.root),
// WIRES
// wiresOverlay: new HUDWiresOverlay(this.root),
/* wires:start */
wiresOverlay: new HUDWiresOverlay(this.root),
/* wires:end */
// Typing hints
/* typehints:start */

View File

@@ -24,8 +24,9 @@ const toolbarBuildings = [
MetaPainterBuilding,
MetaTrashBuilding,
// WIRES
// MetaEnergyGenerator,
/* wires:start */
MetaEnergyGenerator,
/* wires:end */
];
export class HUDBuildingsToolbar extends HUDBaseToolbar {

View File

@@ -8,6 +8,7 @@ import { THEME } from "../../theme";
import { globalConfig } from "../../../core/config";
import { T } from "../../../translations";
import { enumItemType } from "../../base_item";
import { enumEditMode } from "../../root";
export class HUDColorBlindHelper extends BaseHUDPart {
createElements(parent) {
@@ -40,6 +41,11 @@ export class HUDColorBlindHelper extends BaseHUDPart {
return null;
}
if (this.root.editMode !== enumEditMode.regular) {
// Not in regular mode
return null;
}
const worldPos = this.root.camera.screenToWorld(mousePosition);
const tile = worldPos.toTileSpace();
const contents = this.root.map.getTileContent(tile);

View File

@@ -255,13 +255,14 @@ export class HUDKeybindingOverlay extends BaseHUDPart {
condition: () => this.anythingSelectedOnMap,
},
// WIRES
// {
// // Switch layers
// label: T.ingame.keybindingsOverlay.switchLayers,
// keys: [k.ingame.switchLayers],
// condition: () => true,
// },
/* wires:start */
{
// Switch layers
label: T.ingame.keybindingsOverlay.switchLayers,
keys: [k.ingame.switchLayers],
condition: () => true,
},
/* wires:end */
];
if (!this.root.app.settings.getAllSettings().alwaysMultiplace) {

View File

@@ -5,8 +5,10 @@ import { KEYMAPPINGS } from "../../key_action_mapper";
import { enumEditMode } from "../../root";
import { THEME } from "../../theme";
import { BaseHUDPart } from "../base_hud_part";
import { Loader } from "../../../core/loader";
import { lerp } from "../../../core/utils";
const wiresBackgroundDpi = 3;
const wiresBackgroundDpi = 4;
export class HUDWiresOverlay extends BaseHUDPart {
createElements(parent) {}
@@ -16,6 +18,8 @@ export class HUDWiresOverlay extends BaseHUDPart {
this.root.keyMapper.getBinding(KEYMAPPINGS.ingame.switchLayers).add(this.switchLayers, this);
this.generateTilePattern();
this.currentAlpha = 0.0;
}
/**
@@ -34,31 +38,28 @@ export class HUDWiresOverlay extends BaseHUDPart {
* Generates the background pattern for the wires overlay
*/
generateTilePattern() {
const overlayTile = Loader.getSprite("sprites/misc/wires_overlay_tile.png");
const dims = globalConfig.tileSize * wiresBackgroundDpi;
const [canvas, context] = makeOffscreenBuffer(dims, dims, {
smooth: false,
reusable: false,
label: "wires-tile-pattern",
});
context.scale(wiresBackgroundDpi, wiresBackgroundDpi);
context.fillStyle = THEME.map.wires.overlay;
context.fillRect(0, 0, globalConfig.tileSize, globalConfig.tileSize);
const lineWidth = 1;
context.fillRect(0, 0, globalConfig.tileSize, lineWidth);
context.fillRect(0, lineWidth, lineWidth, globalConfig.tileSize);
overlayTile.draw(context, 0, 0, dims, dims);
this.tilePatternCanvas = canvas;
}
update() {
const desiredAlpha = this.root.editMode === enumEditMode.wires ? 1.0 : 0.0;
this.currentAlpha = lerp(this.currentAlpha, desiredAlpha, 0.08);
}
/**
*
* @param {DrawParameters} parameters
*/
draw(parameters) {
if (this.root.editMode !== enumEditMode.wires) {
if (this.currentAlpha < 0.02) {
return;
}
@@ -70,6 +71,8 @@ export class HUDWiresOverlay extends BaseHUDPart {
const scaleFactor = 1 / wiresBackgroundDpi;
parameters.context.globalAlpha = 0.7 * this.currentAlpha;
parameters.context.globalCompositeOperation = "darken";
parameters.context.scale(scaleFactor, scaleFactor);
parameters.context.fillStyle = this.cachedPatternBackground;
parameters.context.fillRect(
@@ -79,5 +82,12 @@ export class HUDWiresOverlay extends BaseHUDPart {
bounds.h / scaleFactor
);
parameters.context.scale(1 / scaleFactor, 1 / scaleFactor);
parameters.context.globalCompositeOperation = "source-over";
parameters.context.globalAlpha = 1;
parameters.context.fillStyle = "#3abf88";
parameters.context.globalAlpha = 0.3 * this.currentAlpha;
parameters.context.fillRect(bounds.x, bounds.y, bounds.w, bounds.h);
parameters.context.globalAlpha = 1;
}
}