mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-03-02 03:39:21 +00:00
Initial take on wires
This commit is contained in:
@@ -13,6 +13,9 @@ import { Entity } from "../entity";
|
||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||
import { MapChunkView } from "../map_chunk_view";
|
||||
import { defaultBuildingVariant } from "../meta_building";
|
||||
import { enumLayer } from "../root";
|
||||
import { MetaWireBaseBuilding } from "../buildings/wire_base";
|
||||
import { enumItemType } from "../base_item";
|
||||
|
||||
export const BELT_ANIM_COUNT = 28;
|
||||
|
||||
@@ -33,6 +36,15 @@ export class BeltSystem extends GameSystemWithFilter {
|
||||
[enumDirection.right]: Loader.getSprite("sprites/belt/right_0.png"),
|
||||
};
|
||||
|
||||
/**
|
||||
* @type {Object.<enumDirection, Array<AtlasSprite>>}
|
||||
*/
|
||||
this.wireSprites = {
|
||||
[enumDirection.top]: Loader.getSprite("sprites/buildings/wire_top.png"),
|
||||
[enumDirection.left]: Loader.getSprite("sprites/buildings/wire_left.png"),
|
||||
[enumDirection.right]: Loader.getSprite("sprites/buildings/wire_right.png"),
|
||||
};
|
||||
|
||||
/**
|
||||
* @type {Object.<enumDirection, Array<AtlasSprite>>}
|
||||
*/
|
||||
@@ -120,7 +132,10 @@ export class BeltSystem extends GameSystemWithFilter {
|
||||
return;
|
||||
}
|
||||
|
||||
const metaBelt = gMetaBuildingRegistry.findByClass(MetaBeltBaseBuilding);
|
||||
/* BIG HACK: We don't actually store the meta building */
|
||||
const metaBelt = gMetaBuildingRegistry.findByClass(
|
||||
entity.layer === enumLayer.regular ? MetaBeltBaseBuilding : MetaWireBaseBuilding
|
||||
);
|
||||
|
||||
// Compute affected area
|
||||
const originalRect = staticComp.getTileSpaceBounds();
|
||||
@@ -133,7 +148,7 @@ export class BeltSystem extends GameSystemWithFilter {
|
||||
continue;
|
||||
}
|
||||
|
||||
const targetEntity = this.root.map.getTileContentXY(x, y);
|
||||
const targetEntity = this.root.map.getLayerContentXY(x, y, entity.layer);
|
||||
if (!targetEntity) {
|
||||
// Empty tile
|
||||
continue;
|
||||
@@ -296,10 +311,14 @@ export class BeltSystem extends GameSystemWithFilter {
|
||||
/**
|
||||
* Draws all belt paths
|
||||
* @param {DrawParameters} parameters
|
||||
* @param {enumLayer} layer
|
||||
*/
|
||||
draw(parameters) {
|
||||
drawLayer(parameters, layer) {
|
||||
for (let i = 0; i < this.beltPaths.length; ++i) {
|
||||
this.beltPaths[i].draw(parameters);
|
||||
const path = this.beltPaths[i];
|
||||
if (path.layer === layer) {
|
||||
path.draw(parameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,7 +355,7 @@ export class BeltSystem extends GameSystemWithFilter {
|
||||
const followUpVector = enumDirectionToVector[followUpDirection];
|
||||
|
||||
const followUpTile = staticComp.origin.add(followUpVector);
|
||||
const followUpEntity = this.root.map.getTileContent(followUpTile);
|
||||
const followUpEntity = this.root.map.getLayerContentXY(followUpTile.x, followUpTile.y, entity.layer);
|
||||
|
||||
// Check if theres a belt at the tile we point to
|
||||
if (followUpEntity) {
|
||||
@@ -349,6 +368,12 @@ export class BeltSystem extends GameSystemWithFilter {
|
||||
const acceptorSlots = followUpAcceptor.slots;
|
||||
for (let i = 0; i < acceptorSlots.length; ++i) {
|
||||
const slot = acceptorSlots[i];
|
||||
|
||||
// Make sure the acceptor slot is on the same layer
|
||||
if (slot.layer !== entity.layer) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (let k = 0; k < slot.directions.length; ++k) {
|
||||
const localDirection = followUpStatic.localDirectionToWorld(slot.directions[k]);
|
||||
if (enumInvertedDirections[localDirection] === followUpDirection) {
|
||||
@@ -374,7 +399,7 @@ export class BeltSystem extends GameSystemWithFilter {
|
||||
const supplyVector = enumDirectionToVector[supplyDirection];
|
||||
|
||||
const supplyTile = staticComp.origin.add(supplyVector);
|
||||
const supplyEntity = this.root.map.getTileContent(supplyTile);
|
||||
const supplyEntity = this.root.map.getLayerContentXY(supplyTile.x, supplyTile.y, entity.layer);
|
||||
|
||||
// Check if theres a belt at the tile we point to
|
||||
if (supplyEntity) {
|
||||
@@ -387,6 +412,11 @@ export class BeltSystem extends GameSystemWithFilter {
|
||||
const ejectorSlots = supplyEjector.slots;
|
||||
for (let i = 0; i < ejectorSlots.length; ++i) {
|
||||
const slot = ejectorSlots[i];
|
||||
|
||||
// Make sure the ejector slot is on the same layer
|
||||
if (slot.layer !== entity.layer) {
|
||||
continue;
|
||||
}
|
||||
const localDirection = supplyStatic.localDirectionToWorld(slot.direction);
|
||||
if (enumInvertedDirections[localDirection] === supplyDirection) {
|
||||
return supplyEntity;
|
||||
@@ -510,6 +540,45 @@ export class BeltSystem extends GameSystemWithFilter {
|
||||
1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a given chunk
|
||||
* @param {DrawParameters} parameters
|
||||
* @param {MapChunkView} chunk
|
||||
*/
|
||||
drawWiresChunk(parameters, chunk) {
|
||||
if (parameters.zoomLevel < globalConfig.mapChunkOverviewMinZoom) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Limit speed to avoid belts going backwards
|
||||
const speedMultiplier = Math.min(this.root.hubGoals.getBeltBaseSpeed(), 10);
|
||||
|
||||
// SYNC with systems/item_acceptor.js:drawEntityUnderlays!
|
||||
// 126 / 42 is the exact animation speed of the png animation
|
||||
const animationIndex = Math.floor(
|
||||
((this.root.time.realtimeNow() * speedMultiplier * BELT_ANIM_COUNT * 126) / 42) *
|
||||
globalConfig.itemSpacingOnBelts
|
||||
);
|
||||
const contents = chunk.wireContents;
|
||||
for (let y = 0; y < globalConfig.mapChunkSize; ++y) {
|
||||
for (let x = 0; x < globalConfig.mapChunkSize; ++x) {
|
||||
const entity = contents[x][y];
|
||||
|
||||
if (entity && entity.components.Belt) {
|
||||
const direction = entity.components.Belt.direction;
|
||||
const sprite = this.wireSprites[direction];
|
||||
entity.components.StaticMapEntity.drawSpriteOnFullEntityBounds(
|
||||
parameters,
|
||||
sprite,
|
||||
0,
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the belt path debug overlays
|
||||
* @param {DrawParameters} parameters
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { DrawParameters } from "../../core/draw_parameters";
|
||||
import { formatBigNumber } from "../../core/utils";
|
||||
import { T } from "../../translations";
|
||||
import { EnergyGeneratorComponent } from "../components/energy_generator";
|
||||
import { EnergyGeneratorComponent, ENERGY_GENERATOR_EJECT_SLOT } from "../components/energy_generator";
|
||||
import { Entity } from "../entity";
|
||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||
import { POSITIVE_ENERGY_ITEM_SINGLETON } from "../items/positive_energy_item";
|
||||
import { ShapeDefinition } from "../shape_definition";
|
||||
import { formatBigNumber } from "../../core/utils";
|
||||
|
||||
export class EnergyGeneratorSystem extends GameSystemWithFilter {
|
||||
constructor(root) {
|
||||
@@ -27,11 +28,18 @@ export class EnergyGeneratorSystem extends GameSystemWithFilter {
|
||||
for (let i = 0; i < this.allEntities.length; ++i) {
|
||||
const entity = this.allEntities[i];
|
||||
const energyGenComp = entity.components.EnergyGenerator;
|
||||
const ejectorComp = entity.components.ItemEjector;
|
||||
|
||||
if (!energyGenComp.requiredKey) {
|
||||
// Compute required key for this generator
|
||||
energyGenComp.requiredKey = this.getShapeRequiredForGenerator(entity);
|
||||
}
|
||||
|
||||
if (energyGenComp.itemsInQueue > 0) {
|
||||
if (ejectorComp.tryEject(ENERGY_GENERATOR_EJECT_SLOT, POSITIVE_ENERGY_ITEM_SINGLETON)) {
|
||||
energyGenComp.itemsInQueue -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Loader } from "../../core/loader";
|
||||
import { drawRotatedSprite } from "../../core/draw_utils";
|
||||
import { BELT_ANIM_COUNT } from "./belt";
|
||||
import { fastArrayDelete } from "../../core/utils";
|
||||
import { enumLayer } from "../root";
|
||||
|
||||
export class ItemAcceptorSystem extends GameSystemWithFilter {
|
||||
constructor(root) {
|
||||
@@ -49,19 +50,30 @@ export class ItemAcceptorSystem extends GameSystemWithFilter {
|
||||
}
|
||||
}
|
||||
|
||||
draw(parameters) {
|
||||
this.forEachMatchingEntityOnScreen(parameters, this.drawEntity.bind(this));
|
||||
}
|
||||
|
||||
drawUnderlays(parameters) {
|
||||
this.forEachMatchingEntityOnScreen(parameters, this.drawEntityUnderlays.bind(this));
|
||||
/**
|
||||
* Draws the acceptor items
|
||||
* @param {DrawParameters} parameters
|
||||
* @param {enumLayer} layer
|
||||
*/
|
||||
drawLayer(parameters, layer) {
|
||||
this.forEachMatchingEntityOnScreen(parameters, this.drawEntityRegularLayer.bind(this, layer));
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the acceptor underlays
|
||||
* @param {DrawParameters} parameters
|
||||
* @param {enumLayer} layer
|
||||
*/
|
||||
drawUnderlays(parameters, layer) {
|
||||
this.forEachMatchingEntityOnScreen(parameters, this.drawEntityUnderlays.bind(this, layer));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {enumLayer} layer
|
||||
* @param {DrawParameters} parameters
|
||||
* @param {Entity} entity
|
||||
*/
|
||||
drawEntity(parameters, entity) {
|
||||
drawEntityRegularLayer(layer, parameters, entity) {
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
const acceptorComp = entity.components.ItemAcceptor;
|
||||
|
||||
@@ -75,8 +87,12 @@ export class ItemAcceptorSystem extends GameSystemWithFilter {
|
||||
];
|
||||
|
||||
const slotData = acceptorComp.slots[slotIndex];
|
||||
const slotWorldPos = staticComp.applyRotationToVector(slotData.pos).add(staticComp.origin);
|
||||
if (slotData.layer !== layer) {
|
||||
// Don't draw non-regular slots for now
|
||||
continue;
|
||||
}
|
||||
|
||||
const slotWorldPos = staticComp.applyRotationToVector(slotData.pos).add(staticComp.origin);
|
||||
const fadeOutDirection = enumDirectionToVector[staticComp.localDirectionToWorld(direction)];
|
||||
const finalTile = slotWorldPos.subScalars(
|
||||
fadeOutDirection.x * (animProgress / 2 - 0.5),
|
||||
@@ -91,10 +107,11 @@ export class ItemAcceptorSystem extends GameSystemWithFilter {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {enumLayer} layer
|
||||
* @param {DrawParameters} parameters
|
||||
* @param {Entity} entity
|
||||
*/
|
||||
drawEntityUnderlays(parameters, entity) {
|
||||
drawEntityUnderlays(layer, parameters, entity) {
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
const acceptorComp = entity.components.ItemAcceptor;
|
||||
|
||||
@@ -107,7 +124,11 @@ export class ItemAcceptorSystem extends GameSystemWithFilter {
|
||||
|
||||
const underlays = acceptorComp.beltUnderlays;
|
||||
for (let i = 0; i < underlays.length; ++i) {
|
||||
const { pos, direction } = underlays[i];
|
||||
const { pos, direction, layer: underlayLayer } = underlays[i];
|
||||
if (underlayLayer !== layer) {
|
||||
// Not our layer
|
||||
continue;
|
||||
}
|
||||
|
||||
const transformedPos = staticComp.localTileToWorld(pos);
|
||||
const angle = enumDirectionToAngle[staticComp.localDirectionToWorld(direction)];
|
||||
|
||||
@@ -7,6 +7,7 @@ import { BaseItem } from "../base_item";
|
||||
import { ItemEjectorComponent } from "../components/item_ejector";
|
||||
import { Entity } from "../entity";
|
||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||
import { enumLayer } from "../root";
|
||||
|
||||
const logger = createLogger("systems/ejector");
|
||||
|
||||
@@ -96,8 +97,10 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
||||
|
||||
for (let x = area.x; x < area.right(); ++x) {
|
||||
for (let y = area.y; y < area.bottom(); ++y) {
|
||||
const entity = this.root.map.getTileContentXY(x, y);
|
||||
if (entity) {
|
||||
const entities = this.root.map.getLayersContentsMultipleXY(x, y);
|
||||
for (let i = 0; i < entities.length; ++i) {
|
||||
const entity = entities[i];
|
||||
|
||||
// Recompute the entity in case its relevant for this system and it
|
||||
// hasn't already been computed
|
||||
if (!recomputedEntities.has(entity.uid) && entity.components.ItemEjector) {
|
||||
@@ -134,37 +137,45 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
||||
const ejectSlotTargetWsTile = ejectSlotWsTile.add(ejectSlotWsDirectionVector);
|
||||
|
||||
// Try to find the given acceptor component to take the item
|
||||
const targetEntity = this.root.map.getTileContent(ejectSlotTargetWsTile);
|
||||
if (!targetEntity) {
|
||||
// No consumer for item
|
||||
continue;
|
||||
}
|
||||
|
||||
const targetAcceptorComp = targetEntity.components.ItemAcceptor;
|
||||
const targetStaticComp = targetEntity.components.StaticMapEntity;
|
||||
if (!targetAcceptorComp) {
|
||||
// Entity doesn't accept items
|
||||
continue;
|
||||
}
|
||||
|
||||
const matchingSlot = targetAcceptorComp.findMatchingSlot(
|
||||
targetStaticComp.worldToLocalTile(ejectSlotTargetWsTile),
|
||||
targetStaticComp.worldDirectionToLocal(ejectSlotWsDirection)
|
||||
// Since there can be cross layer dependencies, check on all layers
|
||||
const targetEntities = this.root.map.getLayersContentsMultipleXY(
|
||||
ejectSlotTargetWsTile.x,
|
||||
ejectSlotTargetWsTile.y
|
||||
);
|
||||
|
||||
if (!matchingSlot) {
|
||||
// No matching slot found
|
||||
continue;
|
||||
}
|
||||
for (let i = 0; i < targetEntities.length; ++i) {
|
||||
const targetEntity = targetEntities[i];
|
||||
|
||||
// Ok we found a connection
|
||||
if (ejectorComp.cachedConnectedSlots) {
|
||||
ejectorComp.cachedConnectedSlots.push(ejectorSlot);
|
||||
} else {
|
||||
ejectorComp.cachedConnectedSlots = [ejectorSlot];
|
||||
const targetAcceptorComp = targetEntity.components.ItemAcceptor;
|
||||
const targetStaticComp = targetEntity.components.StaticMapEntity;
|
||||
if (!targetAcceptorComp) {
|
||||
// Entity doesn't accept items
|
||||
continue;
|
||||
}
|
||||
|
||||
const matchingSlot = targetAcceptorComp.findMatchingSlot(
|
||||
targetStaticComp.worldToLocalTile(ejectSlotTargetWsTile),
|
||||
targetStaticComp.worldDirectionToLocal(ejectSlotWsDirection),
|
||||
ejectorSlot.layer
|
||||
);
|
||||
|
||||
if (!matchingSlot) {
|
||||
// No matching slot found
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ok we found a connection
|
||||
if (ejectorComp.cachedConnectedSlots) {
|
||||
ejectorComp.cachedConnectedSlots.push(ejectorSlot);
|
||||
} else {
|
||||
ejectorComp.cachedConnectedSlots = [ejectorSlot];
|
||||
}
|
||||
|
||||
// A slot can always be connected to one other slot only
|
||||
ejectorSlot.cachedTargetEntity = targetEntity;
|
||||
ejectorSlot.cachedDestSlot = matchingSlot;
|
||||
break;
|
||||
}
|
||||
ejectorSlot.cachedTargetEntity = targetEntity;
|
||||
ejectorSlot.cachedDestSlot = matchingSlot;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,7 +303,7 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
||||
|
||||
const energyGeneratorComp = receiver.components.EnergyGenerator;
|
||||
if (energyGeneratorComp) {
|
||||
if (energyGeneratorComp.tryTakeItem(item)) {
|
||||
if (energyGeneratorComp.tryTakeItem(item, slotIndex)) {
|
||||
// Passed it over
|
||||
return true;
|
||||
}
|
||||
@@ -304,15 +315,21 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
||||
return false;
|
||||
}
|
||||
|
||||
draw(parameters) {
|
||||
this.forEachMatchingEntityOnScreen(parameters, this.drawSingleEntity.bind(this));
|
||||
/**
|
||||
* Draws the given layer
|
||||
* @param {DrawParameters} parameters
|
||||
* @param {enumLayer} layer
|
||||
*/
|
||||
drawLayer(parameters, layer) {
|
||||
this.forEachMatchingEntityOnScreen(parameters, this.drawSingleEntity.bind(this, layer));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {enumLayer} layer
|
||||
* @param {DrawParameters} parameters
|
||||
* @param {Entity} entity
|
||||
*/
|
||||
drawSingleEntity(parameters, entity) {
|
||||
drawSingleEntity(layer, parameters, entity) {
|
||||
const ejectorComp = entity.components.ItemEjector;
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
|
||||
@@ -323,11 +340,17 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
||||
for (let i = 0; i < ejectorComp.slots.length; ++i) {
|
||||
const slot = ejectorComp.slots[i];
|
||||
const ejectedItem = slot.item;
|
||||
|
||||
if (!ejectedItem) {
|
||||
// No item
|
||||
continue;
|
||||
}
|
||||
|
||||
if (slot.layer !== layer) {
|
||||
// Not our layer
|
||||
continue;
|
||||
}
|
||||
|
||||
const realPosition = slot.pos.rotateFastMultipleOf90(staticComp.rotation);
|
||||
const realDirection = Vector.transformDirectionFromMultipleOf90(
|
||||
slot.direction,
|
||||
|
||||
@@ -6,6 +6,7 @@ import { Entity } from "../entity";
|
||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||
import { ColorItem } from "../items/color_item";
|
||||
import { ShapeItem } from "../items/shape_item";
|
||||
import { enumLayer } from "../root";
|
||||
|
||||
export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
constructor(root) {
|
||||
@@ -48,11 +49,14 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
if (ejectorComp.canEjectOnSlot(preferredSlot)) {
|
||||
slot = preferredSlot;
|
||||
} else {
|
||||
slot = ejectorComp.getFirstFreeSlot();
|
||||
/* FIXME: WIRES */
|
||||
slot = ejectorComp.getFirstFreeSlot(enumLayer.regular);
|
||||
}
|
||||
} else {
|
||||
/* FIXME: WIRES */
|
||||
|
||||
// We can eject on any slot
|
||||
slot = ejectorComp.getFirstFreeSlot();
|
||||
slot = ejectorComp.getFirstFreeSlot(enumLayer.regular);
|
||||
}
|
||||
|
||||
if (slot !== null) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import { MinerComponent } from "../components/miner";
|
||||
import { Entity } from "../entity";
|
||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||
import { MapChunkView } from "../map_chunk_view";
|
||||
import { enumLayer } from "../root";
|
||||
|
||||
export class MinerSystem extends GameSystemWithFilter {
|
||||
constructor(root) {
|
||||
@@ -74,7 +75,7 @@ export class MinerSystem extends GameSystemWithFilter {
|
||||
const ejectingDirection = staticComp.localDirectionToWorld(ejectingSlot.direction);
|
||||
|
||||
const targetTile = ejectingPos.add(enumDirectionToVector[ejectingDirection]);
|
||||
const targetContents = this.root.map.getTileContent(targetTile);
|
||||
const targetContents = this.root.map.getTileContent(targetTile, enumLayer.regular);
|
||||
|
||||
// Check if we are connected to another miner and thus do not eject directly
|
||||
if (targetContents) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { globalConfig } from "../../core/config";
|
||||
import { MapChunkView } from "../map_chunk_view";
|
||||
import { Loader } from "../../core/loader";
|
||||
import { enumDirection } from "../../core/vector";
|
||||
import { enumLayer } from "../root";
|
||||
|
||||
export class StaticMapEntitySystem extends GameSystem {
|
||||
constructor(root) {
|
||||
@@ -40,7 +41,6 @@ export class StaticMapEntitySystem extends GameSystem {
|
||||
continue;
|
||||
}
|
||||
drawnUids.add(entity.uid);
|
||||
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
if (drawOutlinesOnly) {
|
||||
const rect = staticComp.getTileSpaceBounds();
|
||||
@@ -68,4 +68,36 @@ export class StaticMapEntitySystem extends GameSystem {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the static wire entities
|
||||
* @param {DrawParameters} parameters
|
||||
* @param {MapChunkView} chunk
|
||||
*/
|
||||
drawWiresChunk(parameters, chunk) {
|
||||
if (G_IS_DEV && globalConfig.debug.doNotRenderStatics) {
|
||||
return;
|
||||
}
|
||||
|
||||
const drawnUids = new Set();
|
||||
const contents = chunk.wireContents;
|
||||
for (let y = 0; y < globalConfig.mapChunkSize; ++y) {
|
||||
for (let x = 0; x < globalConfig.mapChunkSize; ++x) {
|
||||
const entity = contents[x][y];
|
||||
if (entity) {
|
||||
if (drawnUids.has(entity.uid)) {
|
||||
continue;
|
||||
}
|
||||
drawnUids.add(entity.uid);
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
|
||||
const spriteKey = staticComp.spriteKey;
|
||||
if (spriteKey) {
|
||||
const sprite = Loader.getSprite(spriteKey);
|
||||
staticComp.drawSpriteOnFullEntityBounds(parameters, sprite, 2, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Entity } from "../entity";
|
||||
import { DrawParameters } from "../../core/draw_parameters";
|
||||
import { formatBigNumber, lerp } from "../../core/utils";
|
||||
import { Loader } from "../../core/loader";
|
||||
import { enumLayer } from "../root";
|
||||
|
||||
export class StorageSystem extends GameSystemWithFilter {
|
||||
constructor(root) {
|
||||
@@ -20,7 +21,9 @@ export class StorageSystem extends GameSystemWithFilter {
|
||||
// Eject from storage
|
||||
if (storageComp.storedItem && storageComp.storedCount > 0) {
|
||||
const ejectorComp = entity.components.ItemEjector;
|
||||
const nextSlot = ejectorComp.getFirstFreeSlot();
|
||||
|
||||
/* FIXME: WIRES */
|
||||
const nextSlot = ejectorComp.getFirstFreeSlot(enumLayer.regular);
|
||||
if (nextSlot !== null) {
|
||||
if (ejectorComp.tryEject(nextSlot, storageComp.storedItem)) {
|
||||
storageComp.storedCount--;
|
||||
|
||||
@@ -13,6 +13,7 @@ import { enumUndergroundBeltMode, UndergroundBeltComponent } from "../components
|
||||
import { Entity } from "../entity";
|
||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||
import { fastArrayDelete } from "../../core/utils";
|
||||
import { enumLayer } from "../root";
|
||||
|
||||
const logger = createLogger("tunnels");
|
||||
|
||||
@@ -95,7 +96,7 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
||||
let matchingEntrance = null;
|
||||
for (let i = 0; i < range; ++i) {
|
||||
currentPos.addInplace(offset);
|
||||
const contents = this.root.map.getTileContent(currentPos);
|
||||
const contents = this.root.map.getTileContent(currentPos, entity.layer);
|
||||
if (!contents) {
|
||||
continue;
|
||||
}
|
||||
@@ -128,7 +129,7 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
||||
for (let i = 0; i < matchingEntrance.range; ++i) {
|
||||
currentPos.addInplace(offset);
|
||||
|
||||
const contents = this.root.map.getTileContent(currentPos);
|
||||
const contents = this.root.map.getTileContent(currentPos, entity.layer);
|
||||
if (!contents) {
|
||||
allBeltsMatch = false;
|
||||
break;
|
||||
@@ -156,7 +157,7 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
||||
// All belts between this are obsolete, so drop them
|
||||
for (let i = 0; i < matchingEntrance.range; ++i) {
|
||||
currentPos.addInplace(offset);
|
||||
const contents = this.root.map.getTileContent(currentPos);
|
||||
const contents = this.root.map.getTileContent(currentPos, entity.layer);
|
||||
assert(contents, "Invalid smart underground belt logic");
|
||||
this.root.logic.tryDeleteBuilding(contents);
|
||||
}
|
||||
@@ -169,8 +170,8 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
||||
const posBefore = currentPos.copy();
|
||||
currentPos.addInplace(offset);
|
||||
|
||||
const entityBefore = this.root.map.getTileContent(posBefore);
|
||||
const entityAfter = this.root.map.getTileContent(currentPos);
|
||||
const entityBefore = this.root.map.getTileContent(posBefore, entity.layer);
|
||||
const entityAfter = this.root.map.getTileContent(currentPos, entity.layer);
|
||||
|
||||
if (!entityBefore || !entityAfter) {
|
||||
continue;
|
||||
@@ -233,16 +234,16 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
||||
|
||||
for (let x = area.x; x < area.right(); ++x) {
|
||||
for (let y = area.y; y < area.bottom(); ++y) {
|
||||
const entity = this.root.map.getTileContentXY(x, y);
|
||||
if (!entity) {
|
||||
continue;
|
||||
}
|
||||
const undergroundComp = entity.components.UndergroundBelt;
|
||||
if (!undergroundComp) {
|
||||
continue;
|
||||
}
|
||||
const entities = this.root.map.getLayersContentsMultipleXY(x, y);
|
||||
for (let i = 0; i < entities.length; ++i) {
|
||||
const entity = entities[i];
|
||||
const undergroundComp = entity.components.UndergroundBelt;
|
||||
if (!undergroundComp) {
|
||||
continue;
|
||||
}
|
||||
|
||||
undergroundComp.cachedLinkedEntity = null;
|
||||
undergroundComp.cachedLinkedEntity = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -297,7 +298,7 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
||||
) {
|
||||
currentTile = currentTile.add(searchVector);
|
||||
|
||||
const potentialReceiver = this.root.map.getTileContent(currentTile);
|
||||
const potentialReceiver = this.root.map.getTileContent(currentTile, enumLayer.regular);
|
||||
if (!potentialReceiver) {
|
||||
// Empty tile
|
||||
continue;
|
||||
@@ -393,7 +394,8 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
||||
|
||||
if (remainingTime <= 0) {
|
||||
const ejectorComp = entity.components.ItemEjector;
|
||||
const nextSlotIndex = ejectorComp.getFirstFreeSlot();
|
||||
|
||||
const nextSlotIndex = ejectorComp.getFirstFreeSlot(entity.layer);
|
||||
if (nextSlotIndex !== null) {
|
||||
if (ejectorComp.tryEject(nextSlotIndex, nextItem)) {
|
||||
items.shift();
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||
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";
|
||||
import { DrawParameters } from "../../core/draw_parameters";
|
||||
import { WiredPinsComponent, enumPinSlotType } from "../components/wired_pins";
|
||||
import { Entity } from "../entity";
|
||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||
import { MapChunkView } from "../map_chunk_view";
|
||||
import { Loader } from "../../core/loader";
|
||||
|
||||
export class WiredPinsSystem extends GameSystemWithFilter {
|
||||
constructor(root) {
|
||||
super(root, [WiredPinsComponent]);
|
||||
|
||||
this.pinSprites = {
|
||||
[enumPinSlotType.energyEjector]: [Loader.getSprite("sprites/wires/pin-energy-on.png")],
|
||||
[enumPinSlotType.positiveEnergyEjector]: Loader.getSprite(
|
||||
"sprites/wires/pin-positive-energy.png"
|
||||
),
|
||||
[enumPinSlotType.negativeEnergyAcceptor]: Loader.getSprite(
|
||||
"sprites/wires/pin-negative-energy.png"
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -19,25 +24,22 @@ export class WiredPinsSystem extends GameSystemWithFilter {
|
||||
// TODO
|
||||
}
|
||||
|
||||
drawWiresLayer(parameters) {
|
||||
this.forEachMatchingEntityOnScreen(parameters, this.drawEntityPins.bind(this));
|
||||
/**
|
||||
* Draws the given layer
|
||||
* @param {DrawParameters} parameters
|
||||
*/
|
||||
draw(parameters) {
|
||||
this.forEachMatchingEntityOnScreen(parameters, this.drawSingleEntity.bind(this));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Draws a given chunk
|
||||
* @param {DrawParameters} parameters
|
||||
* @param {Entity} entity
|
||||
*/
|
||||
drawEntityPins(parameters, entity) {
|
||||
drawSingleEntity(parameters, entity) {
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
|
||||
if (!staticComp.shouldBeDrawn(parameters)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const pinsComp = entity.components.WiredPins;
|
||||
|
||||
const slots = pinsComp.slots;
|
||||
const slots = entity.components.WiredPins.slots;
|
||||
|
||||
for (let i = 0; i < slots.length; ++i) {
|
||||
const slot = slots[i];
|
||||
@@ -45,7 +47,7 @@ export class WiredPinsSystem extends GameSystemWithFilter {
|
||||
|
||||
const worldPos = tile.toWorldSpaceCenterOfTile();
|
||||
|
||||
this.pinSprites[slot.type][0].drawCachedCentered(
|
||||
this.pinSprites[slot.type].drawCachedCentered(
|
||||
parameters,
|
||||
worldPos.x,
|
||||
worldPos.y,
|
||||
|
||||
Reference in New Issue
Block a user