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:
@@ -88,6 +88,11 @@ export class AtlasSprite extends BaseSprite {
|
||||
|
||||
const link = this.linksByResolution[ORIGINAL_SCALE];
|
||||
|
||||
assert(
|
||||
link,
|
||||
"Link not known: " + ORIGINAL_SCALE + " (having " + Object.keys(this.linksByResolution) + ")"
|
||||
);
|
||||
|
||||
const width = w || link.w;
|
||||
const height = h || link.h;
|
||||
|
||||
@@ -152,6 +157,9 @@ export class AtlasSprite extends BaseSprite {
|
||||
|
||||
const scale = parameters.desiredAtlasScale;
|
||||
const link = this.linksByResolution[scale];
|
||||
|
||||
assert(link, "Link not known: " + scale + " (having " + Object.keys(this.linksByResolution) + ")");
|
||||
|
||||
const scaleW = w / link.w;
|
||||
const scaleH = h / link.h;
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ export class WiredPinsComponent extends Component {
|
||||
* @param {object} param0
|
||||
* @param {Array<WirePinSlotDefinition>} param0.slots
|
||||
*/
|
||||
constructor({ slots }) {
|
||||
constructor({ slots = [] }) {
|
||||
super();
|
||||
this.setSlots(slots);
|
||||
}
|
||||
|
||||
@@ -406,12 +406,13 @@ export class GameCore {
|
||||
systems.storage.draw(params);
|
||||
}
|
||||
|
||||
// WIRES
|
||||
// root.hud.parts.wiresOverlay.draw(params);
|
||||
/* wires:start */
|
||||
root.hud.parts.wiresOverlay.draw(params);
|
||||
|
||||
if (this.root.editMode === enumEditMode.wires) {
|
||||
systems.wiredPins.drawWiresLayer(params);
|
||||
}
|
||||
/* wires:end */
|
||||
|
||||
if (G_IS_DEV) {
|
||||
root.map.drawStaticEntityDebugOverlays(params);
|
||||
|
||||
@@ -102,7 +102,9 @@ export class GameSystemManager {
|
||||
|
||||
add("staticMapEntities", StaticMapEntitySystem);
|
||||
|
||||
/* wires:start */
|
||||
add("wiredPins", WiredPinsSystem);
|
||||
/* wires:end */
|
||||
|
||||
// IMPORTANT: Must be after belt system since belt system can change the
|
||||
// orientation of an entity after it is placed -> the item acceptor cache
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -24,8 +24,9 @@ const toolbarBuildings = [
|
||||
MetaPainterBuilding,
|
||||
MetaTrashBuilding,
|
||||
|
||||
// WIRES
|
||||
// MetaEnergyGenerator,
|
||||
/* wires:start */
|
||||
MetaEnergyGenerator,
|
||||
/* wires:end */
|
||||
];
|
||||
|
||||
export class HUDBuildingsToolbar extends HUDBaseToolbar {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,9 @@ export const KEYMAPPINGS = {
|
||||
exportScreenshot: { keyCode: 114 }, // F3PS
|
||||
toggleFPSInfo: { keyCode: 115 }, // F4
|
||||
|
||||
// WIRES
|
||||
// switchLayers: { keyCode: key("Y") },
|
||||
/* wires:start */
|
||||
switchLayers: { keyCode: key("Y") },
|
||||
/* wires:end */
|
||||
},
|
||||
|
||||
navigation: {
|
||||
@@ -55,8 +56,9 @@ export const KEYMAPPINGS = {
|
||||
painter: { keyCode: key("9") },
|
||||
trash: { keyCode: key("0") },
|
||||
|
||||
// WIRES
|
||||
// energy_generator: { keyCode: key("O") },
|
||||
/* wires:start */
|
||||
energy_generator: { keyCode: key("O") },
|
||||
/* wires:end */
|
||||
},
|
||||
|
||||
placement: {
|
||||
|
||||
@@ -133,6 +133,10 @@ export class GameRoot {
|
||||
/** @type {enumEditMode} */
|
||||
this.editMode = enumEditMode.regular;
|
||||
|
||||
if (G_IS_DEV) {
|
||||
this.editMode = enumEditMode.wires;
|
||||
}
|
||||
|
||||
this.signals = {
|
||||
// Entities
|
||||
entityManuallyPlaced: /** @type {TypedSignal<[Entity]>} */ (new Signal()),
|
||||
|
||||
@@ -4,6 +4,7 @@ import { EnergyGeneratorComponent } from "../components/energy_generator";
|
||||
import { Entity } from "../entity";
|
||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||
import { ShapeDefinition } from "../shape_definition";
|
||||
import { formatBigNumber } from "../../core/utils";
|
||||
|
||||
export class EnergyGeneratorSystem extends GameSystemWithFilter {
|
||||
constructor(root) {
|
||||
@@ -62,15 +63,14 @@ export class EnergyGeneratorSystem extends GameSystemWithFilter {
|
||||
|
||||
// deliver: Deliver
|
||||
// toGenerateEnergy: For <x> energy
|
||||
context.font = "bold 7px GameFont";
|
||||
context.font = "bold 9px GameFont";
|
||||
context.fillStyle = "#64666e";
|
||||
context.textAlign = "left";
|
||||
context.fillText(T.buildings.energy_generator.deliver.toUpperCase(), pos.x - 25, pos.y - 18);
|
||||
context.fillText(T.buildings.energy_generator.toGenerateEnergy.toUpperCase(), pos.x - 25, pos.y + 27);
|
||||
|
||||
context.fillText(
|
||||
T.buildings.energy_generator.toGenerateEnergy.replace("<x>", "" + energyGenerated).toUpperCase(),
|
||||
pos.x - 25,
|
||||
pos.y + 28
|
||||
);
|
||||
context.font = "700 9px GameFont";
|
||||
context.fillStyle = "#dee1ea";
|
||||
context.fillText("" + formatBigNumber(energyGenerated), pos.x + 1, pos.y + 27);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||
import { WiredPinsComponent } from "../components/wired_pins";
|
||||
import { WiredPinsComponent, enumPinSlotType } from "../components/wired_pins";
|
||||
import { DrawParameters } from "../../core/draw_parameters";
|
||||
import { Entity } from "../entity";
|
||||
import { THEME } from "../theme";
|
||||
import { Loader } from "../../core/loader";
|
||||
import { globalConfig } from "../../core/config";
|
||||
|
||||
export class WiredPinsSystem extends GameSystemWithFilter {
|
||||
constructor(root) {
|
||||
super(root, [WiredPinsComponent]);
|
||||
|
||||
this.pinSprites = {
|
||||
[enumPinSlotType.energyEjector]: [Loader.getSprite("sprites/wires/pin-energy-on.png")],
|
||||
};
|
||||
}
|
||||
|
||||
update() {
|
||||
@@ -39,13 +45,12 @@ export class WiredPinsSystem extends GameSystemWithFilter {
|
||||
|
||||
const worldPos = tile.toWorldSpaceCenterOfTile();
|
||||
|
||||
parameters.context.fillStyle = THEME.map.wires.pins[slot.type];
|
||||
parameters.context.beginCircle(worldPos.x, worldPos.y, 5);
|
||||
parameters.context.fill();
|
||||
|
||||
parameters.context.lineWidth = 2;
|
||||
parameters.context.fillStyle = "rgba(0, 0, 0, 0.1)";
|
||||
parameters.context.stroke();
|
||||
this.pinSprites[slot.type][0].drawCachedCentered(
|
||||
parameters,
|
||||
worldPos.x,
|
||||
worldPos.y,
|
||||
globalConfig.tileSize
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
},
|
||||
|
||||
"wires": {
|
||||
"overlay": "rgba(52, 150, 128, 0.5)",
|
||||
"pins": {
|
||||
"energyEjector": "#c425d7"
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
},
|
||||
|
||||
"wires": {
|
||||
"overlay": "rgba(52, 150, 128, 0.8)",
|
||||
"pins": {
|
||||
"energyEjector": "#c425d7"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user