1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-16 19:51:50 +00:00
tobspr_shapez.io/src/js/game/systems/item_acceptor.js

88 lines
3.4 KiB
JavaScript
Raw Normal View History

import { globalConfig } from "../../core/config";
import { DrawParameters } from "../../core/draw_parameters";
import { enumDirectionToVector } from "../../core/vector";
import { ACHIEVEMENTS } from "../../platform/achievement_provider";
2022-01-19 16:35:46 +00:00
import { ItemAcceptorComponent, InputCompletedArgs } from "../components/item_acceptor";
import { GameSystemWithFilter } from "../game_system_with_filter";
2022-01-18 17:39:02 +00:00
import { ShapeItem } from "../items/shape_item";
import { MapChunkView } from "../map_chunk_view";
export class ItemAcceptorSystem extends GameSystemWithFilter {
constructor(root) {
super(root, [ItemAcceptorComponent]);
2022-01-18 17:39:02 +00:00
}
2022-01-18 17:39:02 +00:00
update() {
2022-01-19 16:35:46 +00:00
// same code for belts, acceptors and ejectors - add helper method???
2022-01-18 17:39:02 +00:00
const progressGrowth =
this.root.dynamicTickrate.deltaSeconds *
this.root.hubGoals.getBeltBaseSpeed() *
2022-01-18 17:39:02 +00:00
globalConfig.itemSpacingOnBelts;
for (let i = 0; i < this.allEntities.length; ++i) {
const entity = this.allEntities[i];
2022-01-18 17:39:02 +00:00
const acceptorComp = entity.components.ItemAcceptor;
const inputs = acceptorComp.inputs;
const maxProgress = acceptorComp.progressLength;
2022-01-18 17:39:02 +00:00
inputs.forEach((values, index) => {
values.animProgress += progressGrowth;
2022-01-19 16:35:46 +00:00
if (values.animProgress < maxProgress) return;
2022-01-18 17:39:02 +00:00
inputs.delete(index);
acceptorComp.completedInputs.set(index, {
item: values.item,
2022-01-19 16:35:46 +00:00
extraProgress: values.animProgress - maxProgress,
}); // will be handled on the SAME frame due to processor system being afterwards
2022-01-18 17:39:02 +00:00
});
}
}
/**
* @param {DrawParameters} parameters
* @param {MapChunkView} chunk
*/
drawChunk(parameters, chunk) {
2020-09-19 08:34:46 +00:00
if (this.root.app.settings.getAllSettings().simplifiedBelts) {
// Disabled in potato mode
return;
}
const contents = chunk.containedEntitiesByLayer.regular;
for (let i = 0; i < contents.length; ++i) {
const entity = contents[i];
const acceptorComp = entity.components.ItemAcceptor;
if (!acceptorComp) {
continue;
}
const staticComp = entity.components.StaticMapEntity;
acceptorComp.inputs.forEach((values, index) => {
2022-01-18 17:39:02 +00:00
const { item, animProgress, direction } = values;
2022-01-18 17:39:02 +00:00
const slotData = acceptorComp.slots[index];
const realSlotPos = staticComp.localTileToWorld(slotData.pos);
if (!chunk.tileSpaceRectangle.containsPoint(realSlotPos.x, realSlotPos.y)) {
// Not within this chunk
2022-01-18 17:39:02 +00:00
return;
}
const fadeOutDirection = enumDirectionToVector[staticComp.localDirectionToWorld(direction)];
const finalTile = realSlotPos.subScalars(
2022-01-19 16:35:46 +00:00
fadeOutDirection.x * (animProgress - 0.5),
fadeOutDirection.y * (animProgress - 0.5)
);
item.drawItemCenteredClipped(
(finalTile.x + 0.5) * globalConfig.tileSize,
(finalTile.y + 0.5) * globalConfig.tileSize,
parameters,
globalConfig.defaultItemDiameter
);
2022-01-18 17:39:02 +00:00
});
}
}
}