mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-13 02:01:51 +00:00
smash dat bug owo
This commit is contained in:
parent
c8b072c7d9
commit
09186cb647
@ -3,6 +3,7 @@ import { enumDirection, Vector } from "../../core/vector";
|
||||
import { ItemAcceptorComponent, enumItemAcceptorItemFilter } from "../components/item_acceptor";
|
||||
import { ItemEjectorComponent } from "../components/item_ejector";
|
||||
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
|
||||
import { SorterComponent } from "../components/sorter";
|
||||
import { Entity } from "../entity";
|
||||
import { MetaBuilding } from "../meta_building";
|
||||
import { GameRoot } from "../root";
|
||||
@ -51,7 +52,9 @@ export class MetaSorterBuilding extends MetaBuilding {
|
||||
processorType: enumItemProcessorTypes.sorter,
|
||||
})
|
||||
);
|
||||
|
||||
entity.addComponent(
|
||||
new SorterComponent({})
|
||||
);
|
||||
entity.addComponent(
|
||||
new ItemEjectorComponent({
|
||||
slots: [
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { gComponentRegistry } from "../core/global_registries";
|
||||
import { StaticMapEntityComponent } from "./components/static_map_entity";
|
||||
import { BeltComponent } from "./components/belt";
|
||||
import { SorterComponent } from "./components/sorter";
|
||||
import { ItemEjectorComponent } from "./components/item_ejector";
|
||||
import { ItemAcceptorComponent } from "./components/item_acceptor";
|
||||
import { MinerComponent } from "./components/miner";
|
||||
@ -14,6 +15,7 @@ import { StorageComponent } from "./components/storage";
|
||||
export function initComponentRegistry() {
|
||||
gComponentRegistry.register(StaticMapEntityComponent);
|
||||
gComponentRegistry.register(BeltComponent);
|
||||
gComponentRegistry.register(SorterComponent);
|
||||
gComponentRegistry.register(ItemEjectorComponent);
|
||||
gComponentRegistry.register(ItemAcceptorComponent);
|
||||
gComponentRegistry.register(MinerComponent);
|
||||
@ -31,7 +33,7 @@ export function initComponentRegistry() {
|
||||
assert(
|
||||
// @ts-ignore
|
||||
require.context("./components", false, /.*\.js/i).keys().length ===
|
||||
gComponentRegistry.getNumEntries(),
|
||||
gComponentRegistry.getNumEntries(),
|
||||
"Not all components are registered"
|
||||
);
|
||||
|
||||
|
||||
29
src/js/game/components/sorter.js
Normal file
29
src/js/game/components/sorter.js
Normal file
@ -0,0 +1,29 @@
|
||||
import { Component } from "../component";
|
||||
import { types } from "../../savegame/serialization";
|
||||
import { gItemRegistry } from "../../core/global_registries";
|
||||
import { BaseItem } from "../base_item";
|
||||
import { Vector, enumDirection } from "../../core/vector";
|
||||
import { Math_PI, Math_sin, Math_cos } from "../../core/builtins";
|
||||
import { globalConfig } from "../../core/config";
|
||||
|
||||
export class SorterComponent extends Component {
|
||||
static getId() {
|
||||
return "Sorter";
|
||||
}
|
||||
|
||||
static getSchema() {
|
||||
return {
|
||||
filter: types.string,
|
||||
isfil: types.bool,
|
||||
};
|
||||
}
|
||||
constructor({
|
||||
filter = "CuCuCuXu",
|
||||
isfil = false,
|
||||
}) {
|
||||
super();
|
||||
|
||||
this.filter = filter;
|
||||
this.isfil = isfil;
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
/* typehints:start */
|
||||
import { StaticMapEntityComponent } from "./components/static_map_entity";
|
||||
import { BeltComponent } from "./components/belt";
|
||||
import { SorterComponent } from "./components/sorter";
|
||||
import { ItemEjectorComponent } from "./components/item_ejector";
|
||||
import { ItemAcceptorComponent } from "./components/item_acceptor";
|
||||
import { MinerComponent } from "./components/miner";
|
||||
@ -29,6 +30,9 @@ export class EntityComponentStorage {
|
||||
/** @type {BeltComponent} */
|
||||
this.Belt;
|
||||
|
||||
/** @type {SorterComponent} */
|
||||
this.Sorter;
|
||||
|
||||
/** @type {ItemEjectorComponent} */
|
||||
this.ItemEjector;
|
||||
|
||||
|
||||
@ -123,22 +123,24 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
trackProduction = false;
|
||||
const availableSlots = entity.components.ItemEjector.slots.length - 1;
|
||||
assert(inputItem instanceof ShapeItem, "Input for sorting is not a shape");
|
||||
console.log(inputItem.serialize);
|
||||
if (inputItem.serialize() == "CuCuCuCu") {
|
||||
if (inputItem.serialize() == entity.components.Sorter.filter && entity.components.Sorter.isfil) {
|
||||
let nextSlot = processorComp.nextOutputSlot++ % availableSlots;
|
||||
for (let i = 0; i < items.length; ++i) {
|
||||
outItems.push({
|
||||
item: items[i].item,
|
||||
requiredSlot: 1,
|
||||
});
|
||||
}
|
||||
outItems.push({
|
||||
item: inputItem,
|
||||
requiredSlot: 1,
|
||||
});
|
||||
} else if (!entity.components.Sorter.isfil) {
|
||||
entity.components.Sorter.isfil = true;
|
||||
entity.components.Sorter.filter = inputItem.serialize();
|
||||
outItems.push({
|
||||
item: inputItem,
|
||||
requiredSlot: 1,
|
||||
});
|
||||
} else {
|
||||
for (let i = 0; i < items.length; ++i) {
|
||||
outItems.push({
|
||||
item: items[i].item,
|
||||
requiredSlot: 0,
|
||||
});
|
||||
}
|
||||
outItems.push({
|
||||
item: inputItem,
|
||||
requiredSlot: 0,
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user