mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-03-02 03:39:21 +00:00
Add support for different building variants
This commit is contained in:
@@ -63,6 +63,10 @@ export class BeltSystem extends GameSystemWithFilter {
|
||||
* @param {Entity} entity
|
||||
*/
|
||||
updateSurroundingBeltPlacement(entity) {
|
||||
if (!this.root.gameInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
if (!staticComp) {
|
||||
return;
|
||||
|
||||
@@ -16,11 +16,6 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
constructor(root) {
|
||||
super(root, [ItemProcessorComponent]);
|
||||
|
||||
this.sprites = {};
|
||||
for (const key in enumItemProcessorTypes) {
|
||||
this.sprites[key] = Loader.getSprite("sprites/buildings/" + key + ".png");
|
||||
}
|
||||
|
||||
this.underlayBeltSprites = [
|
||||
Loader.getSprite("sprites/belt/forward_0.png"),
|
||||
Loader.getSprite("sprites/belt/forward_1.png"),
|
||||
@@ -121,6 +116,12 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
const items = processorComp.inputSlots;
|
||||
processorComp.inputSlots = [];
|
||||
|
||||
/** @type {Object.<string, { item: BaseItem, sourceSlot: number }>} */
|
||||
const itemsBySlot = {};
|
||||
for (let i = 0; i < items.length; ++i) {
|
||||
itemsBySlot[items[i].sourceSlot] = items[i];
|
||||
}
|
||||
|
||||
const baseSpeed = this.root.hubGoals.getProcessorBaseSpeed(processorComp.type);
|
||||
processorComp.secondsUntilEject = 1 / baseSpeed;
|
||||
|
||||
@@ -185,11 +186,9 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
// STACKER
|
||||
|
||||
case enumItemProcessorTypes.stacker: {
|
||||
const item1 = items[0];
|
||||
const item2 = items[1];
|
||||
const lowerItem = /** @type {ShapeItem} */ (itemsBySlot[0].item);
|
||||
const upperItem = /** @type {ShapeItem} */ (itemsBySlot[1].item);
|
||||
|
||||
const lowerItem = /** @type {ShapeItem} */ (item1.sourceSlot === 0 ? item1.item : item2.item);
|
||||
const upperItem = /** @type {ShapeItem} */ (item1.sourceSlot === 1 ? item1.item : item2.item);
|
||||
assert(lowerItem instanceof ShapeItem, "Input for lower stack is not a shape");
|
||||
assert(upperItem instanceof ShapeItem, "Input for upper stack is not a shape");
|
||||
|
||||
@@ -238,11 +237,8 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
// PAINTER
|
||||
|
||||
case enumItemProcessorTypes.painter: {
|
||||
const item1 = items[0];
|
||||
const item2 = items[1];
|
||||
|
||||
const shapeItem = /** @type {ShapeItem} */ (item1.sourceSlot === 0 ? item1.item : item2.item);
|
||||
const colorItem = /** @type {ColorItem} */ (item1.sourceSlot === 1 ? item1.item : item2.item);
|
||||
const shapeItem = /** @type {ShapeItem} */ (itemsBySlot[0].item);
|
||||
const colorItem = /** @type {ColorItem} */ (itemsBySlot[1].item);
|
||||
|
||||
const colorizedDefinition = this.root.shapeDefinitionMgr.shapeActionPaintWith(
|
||||
shapeItem.definition,
|
||||
@@ -256,6 +252,38 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
break;
|
||||
}
|
||||
|
||||
// PAINTER (DOUBLE)
|
||||
|
||||
case enumItemProcessorTypes.painterDouble: {
|
||||
console.log("YUP");
|
||||
const shapeItem1 = /** @type {ShapeItem} */ (itemsBySlot[0].item);
|
||||
const shapeItem2 = /** @type {ShapeItem} */ (itemsBySlot[1].item);
|
||||
const colorItem = /** @type {ColorItem} */ (itemsBySlot[2].item);
|
||||
|
||||
assert(shapeItem1 instanceof ShapeItem, "Input for painter is not a shape");
|
||||
assert(shapeItem2 instanceof ShapeItem, "Input for painter is not a shape");
|
||||
assert(colorItem instanceof ColorItem, "Input for painter is not a color");
|
||||
|
||||
const colorizedDefinition1 = this.root.shapeDefinitionMgr.shapeActionPaintWith(
|
||||
shapeItem1.definition,
|
||||
colorItem.color
|
||||
);
|
||||
|
||||
const colorizedDefinition2 = this.root.shapeDefinitionMgr.shapeActionPaintWith(
|
||||
shapeItem2.definition,
|
||||
colorItem.color
|
||||
);
|
||||
outItems.push({
|
||||
item: new ShapeItem(colorizedDefinition1),
|
||||
});
|
||||
|
||||
outItems.push({
|
||||
item: new ShapeItem(colorizedDefinition2),
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// HUB
|
||||
|
||||
case enumItemProcessorTypes.hub: {
|
||||
|
||||
@@ -4,6 +4,9 @@ import { MinerComponent } from "../components/miner";
|
||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||
import { MapChunkView } from "../map_chunk_view";
|
||||
import { ShapeItem } from "../items/shape_item";
|
||||
import { enumDirectionToVector } from "../../core/vector";
|
||||
import { Entity } from "../entity";
|
||||
import { BaseItem } from "../base_item";
|
||||
|
||||
export class MinerSystem extends GameSystemWithFilter {
|
||||
constructor(root) {
|
||||
@@ -19,35 +22,76 @@ export class MinerSystem extends GameSystemWithFilter {
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
const ejectComp = entity.components.ItemEjector;
|
||||
|
||||
if (this.root.time.isIngameTimerExpired(minerComp.lastMiningTime, 1 / miningSpeed)) {
|
||||
if (!ejectComp.canEjectOnSlot(0)) {
|
||||
// We can't eject further
|
||||
// First, try to get rid of chained items
|
||||
if (minerComp.itemChainBuffer.length > 0) {
|
||||
if (this.tryPerformMinerEject(entity, minerComp.itemChainBuffer[0])) {
|
||||
minerComp.itemChainBuffer.shift();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Actually mine
|
||||
minerComp.lastMiningTime = this.root.time.now();
|
||||
|
||||
if (this.root.time.isIngameTimerExpired(minerComp.lastMiningTime, 1 / miningSpeed)) {
|
||||
const lowerLayerItem = this.root.map.getLowerLayerContentXY(
|
||||
staticComp.origin.x,
|
||||
staticComp.origin.y
|
||||
);
|
||||
|
||||
// TODO: Should not be required actually
|
||||
if (!lowerLayerItem) {
|
||||
// Nothing below;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Analytics hook
|
||||
this.root.signals.itemProduced.dispatch(lowerLayerItem);
|
||||
if (this.tryPerformMinerEject(entity, lowerLayerItem)) {
|
||||
// Analytics hook
|
||||
this.root.signals.itemProduced.dispatch(lowerLayerItem);
|
||||
|
||||
// Try actually ejecting
|
||||
if (!ejectComp.tryEject(0, lowerLayerItem)) {
|
||||
assert(false, "Failed to eject");
|
||||
// Actually mine
|
||||
minerComp.lastMiningTime = this.root.time.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Entity} entity
|
||||
* @param {BaseItem} item
|
||||
*/
|
||||
tryPerformMinerEject(entity, item) {
|
||||
const minerComp = entity.components.Miner;
|
||||
const ejectComp = entity.components.ItemEjector;
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
|
||||
// Check if we are a chained miner
|
||||
if (minerComp.chainable) {
|
||||
const ejectingSlot = ejectComp.slots[0];
|
||||
const ejectingPos = staticComp.localTileToWorld(ejectingSlot.pos);
|
||||
const ejectingDirection = staticComp.localDirectionToWorld(ejectingSlot.direction);
|
||||
|
||||
const targetTile = ejectingPos.add(enumDirectionToVector[ejectingDirection]);
|
||||
const targetContents = this.root.map.getTileContent(targetTile);
|
||||
|
||||
// Check if we are connected to another miner and thus do not eject directly
|
||||
if (targetContents) {
|
||||
const targetMinerComp = targetContents.components.Miner;
|
||||
if (targetMinerComp) {
|
||||
if (targetMinerComp.tryAcceptChainedItem(item)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Seems we are a regular miner or at the end of a row, try actually ejecting
|
||||
if (ejectComp.tryEject(0, item)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {DrawParameters} parameters
|
||||
|
||||
Reference in New Issue
Block a user