2020-08-30 13:31:53 +00:00
|
|
|
import { globalConfig } from "../../core/config";
|
|
|
|
|
import { DrawParameters } from "../../core/draw_parameters";
|
|
|
|
|
import { enumDirectionToVector } from "../../core/vector";
|
2022-01-18 17:39:02 +00:00
|
|
|
import {
|
|
|
|
|
enumItemAcceptorTypes,
|
|
|
|
|
ItemAcceptorComponent,
|
|
|
|
|
InputCompletedArgs,
|
|
|
|
|
} from "../components/item_acceptor";
|
2020-08-30 13:31:53 +00:00
|
|
|
import { GameSystemWithFilter } from "../game_system_with_filter";
|
2022-01-18 17:39:02 +00:00
|
|
|
import { ShapeItem } from "../items/shape_item";
|
2020-08-30 13:31:53 +00:00
|
|
|
import { MapChunkView } from "../map_chunk_view";
|
|
|
|
|
|
|
|
|
|
export class ItemAcceptorSystem extends GameSystemWithFilter {
|
|
|
|
|
constructor(root) {
|
|
|
|
|
super(root, [ItemAcceptorComponent]);
|
2020-09-18 17:51:15 +00:00
|
|
|
|
2022-01-18 17:39:02 +00:00
|
|
|
/**
|
|
|
|
|
* @type {Object<enumItemAcceptorTypes, function(InputCompletedArgs) : string>}
|
|
|
|
|
*/
|
|
|
|
|
this.handlers = {
|
|
|
|
|
[enumItemAcceptorTypes.itemProcessor]: this.input_ITEMPROCESSOR,
|
|
|
|
|
[enumItemAcceptorTypes.hub]: this.input_HUB,
|
|
|
|
|
[enumItemAcceptorTypes.trash]: this.input_TRASH,
|
|
|
|
|
};
|
2020-09-19 08:34:46 +00:00
|
|
|
|
2022-01-18 17:39:02 +00:00
|
|
|
// Bind all handlers
|
|
|
|
|
for (const key in this.handlers) {
|
|
|
|
|
this.handlers[key] = this.handlers[key].bind(this);
|
2020-09-18 17:51:15 +00:00
|
|
|
}
|
2022-01-18 17:39:02 +00:00
|
|
|
}
|
2020-09-18 17:51:15 +00:00
|
|
|
|
2022-01-18 17:39:02 +00:00
|
|
|
update() {
|
|
|
|
|
// * 2 because its only a half tile - (same code as ejector)
|
|
|
|
|
const progressGrowth =
|
2020-08-30 13:31:53 +00:00
|
|
|
2 *
|
2022-01-18 17:39:02 +00:00
|
|
|
this.root.dynamicTickrate.deltaSeconds *
|
2020-08-30 13:31:53 +00:00
|
|
|
this.root.hubGoals.getBeltBaseSpeed() *
|
2022-01-18 17:39:02 +00:00
|
|
|
globalConfig.itemSpacingOnBelts;
|
2020-08-30 13:31:53 +00:00
|
|
|
|
|
|
|
|
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.currentInputs;
|
|
|
|
|
|
|
|
|
|
inputs.forEach((values, index) => {
|
|
|
|
|
if (values.animProgress >= 1) return; // items which are inputted already
|
|
|
|
|
|
|
|
|
|
values.animProgress += progressGrowth;
|
|
|
|
|
|
|
|
|
|
if (values.animProgress < 1) return;
|
|
|
|
|
|
|
|
|
|
/** @type {function(InputCompletedArgs) : string} */
|
|
|
|
|
const handler = this.handlers[acceptorComp.type];
|
|
|
|
|
assert(handler, "No handler for acceptor type defined: " + acceptorComp.type);
|
|
|
|
|
|
|
|
|
|
// Call implementation
|
|
|
|
|
handler({
|
|
|
|
|
root: this.root,
|
|
|
|
|
entity,
|
|
|
|
|
item: values.item,
|
|
|
|
|
slotIndex: index,
|
|
|
|
|
extraProgress: values.animProgress - 1,
|
|
|
|
|
});
|
|
|
|
|
});
|
2020-08-30 13:31:53 +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;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-30 13:31:53 +00:00
|
|
|
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;
|
2022-01-18 17:39:02 +00:00
|
|
|
acceptorComp.currentInputs.forEach((values, index) => {
|
|
|
|
|
const { item, animProgress, direction } = values;
|
|
|
|
|
if (animProgress >= 1) return; // items which are inputted already
|
2020-08-30 13:31:53 +00:00
|
|
|
|
2022-01-18 17:39:02 +00:00
|
|
|
const slotData = acceptorComp.slots[index];
|
2020-08-30 13:31:53 +00:00
|
|
|
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;
|
2020-08-30 13:31:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const fadeOutDirection = enumDirectionToVector[staticComp.localDirectionToWorld(direction)];
|
|
|
|
|
const finalTile = realSlotPos.subScalars(
|
|
|
|
|
fadeOutDirection.x * (animProgress / 2 - 0.5),
|
|
|
|
|
fadeOutDirection.y * (animProgress / 2 - 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
|
|
|
});
|
2020-08-30 13:31:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
2022-01-18 17:39:02 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {InputCompletedArgs} args
|
|
|
|
|
*/
|
|
|
|
|
input_ITEMPROCESSOR(args) {
|
|
|
|
|
const entity = args.entity;
|
|
|
|
|
|
|
|
|
|
const itemProcessorComp = entity.components.ItemProcessor;
|
|
|
|
|
assert(itemProcessorComp, "No item processor to input item to");
|
|
|
|
|
|
|
|
|
|
itemProcessorComp.inputs.set(args.slotIndex, {
|
|
|
|
|
item: args.item,
|
|
|
|
|
extraProgress: args.extraProgress,
|
|
|
|
|
}); // in the future the item processor will not need a list of items
|
|
|
|
|
}
|
|
|
|
|
//@SENSETODO this isn't set up like it should be yet
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {InputCompletedArgs} args
|
|
|
|
|
*/
|
|
|
|
|
input_HUB(args) {
|
|
|
|
|
const item = /** @type {ShapeItem} */ (args.item);
|
|
|
|
|
assert(item instanceof ShapeItem, "Input for hub is not a shape");
|
|
|
|
|
|
|
|
|
|
this.root.hubGoals.handleDefinitionDelivered(item.definition);
|
|
|
|
|
|
|
|
|
|
const acceptorComp = args.entity.components.ItemAcceptor;
|
|
|
|
|
acceptorComp.currentInputs.delete(args.slotIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {InputCompletedArgs} args
|
|
|
|
|
*/
|
|
|
|
|
input_TRASH(args) {
|
|
|
|
|
// just remove the item
|
|
|
|
|
const acceptorComp = args.entity.components.ItemAcceptor;
|
|
|
|
|
acceptorComp.currentInputs.delete(args.slotIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//storage
|
|
|
|
|
|
|
|
|
|
//underground belt
|
2020-08-30 13:31:53 +00:00
|
|
|
}
|