Add item filter

This commit is contained in:
tobspr 2020-08-13 20:30:43 +02:00
parent 984bea1921
commit f44563fc05
26 changed files with 1149 additions and 885 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 70 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.2 MiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 217 KiB

After

Width:  |  Height:  |  Size: 223 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 532 KiB

After

Width:  |  Height:  |  Size: 538 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 997 KiB

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -1,5 +1,5 @@
$buildings: belt, cutter, miner, mixer, painter, rotater, splitter, stacker, trash, underground_belt, wire,
constant_signal, logic_gate, lever;
constant_signal, logic_gate, lever, filter;
@each $building in $buildings {
[data-icon="building_icons/#{$building}.png"] {

View File

@ -70,6 +70,7 @@ export const globalConfig = {
mixer: 1 / 5,
stacker: 1 / 6,
advancedProcessor: 1 / 3,
filter: 1,
},
// Zooming

View File

@ -1182,7 +1182,7 @@ export class BeltPath extends BasicSerializableObject {
const beltLength = beltComp.getEffectiveLengthTiles();
// Check if the current items are on the belt
while (trackPos + beltLength >= currentItemPos - 1e-51) {
while (trackPos + beltLength >= currentItemPos - 1e-5) {
// Its on the belt, render it now
const staticComp = entity.components.StaticMapEntity;
assert(

View File

@ -0,0 +1,82 @@
import { enumDirection, Vector } from "../../core/vector";
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
import { Entity } from "../entity";
import { MetaBuilding } from "../meta_building";
import { GameRoot } from "../root";
import { LeverComponent } from "../components/lever";
import { ItemAcceptorComponent } from "../components/item_acceptor";
import { ItemEjectorComponent } from "../components/item_ejector";
import { ItemProcessorComponent, enumItemProcessorTypes } from "../components/item_processor";
export class MetaFilterBuilding extends MetaBuilding {
constructor() {
super("filter");
}
getSilhouetteColor() {
return "#c45c2e";
}
/**
* @param {GameRoot} root
*/
getIsUnlocked(root) {
// @todo
return true;
}
getDimensions() {
return new Vector(2, 1);
}
/**
* Creates the entity at the given location
* @param {Entity} entity
*/
setupEntityComponents(entity) {
entity.addComponent(
new WiredPinsComponent({
slots: [
{
pos: new Vector(0, 0),
direction: enumDirection.left,
type: enumPinSlotType.logicalAcceptor,
},
],
})
);
entity.addComponent(
new ItemAcceptorComponent({
slots: [
{
pos: new Vector(0, 0),
directions: [enumDirection.bottom],
},
],
})
);
entity.addComponent(
new ItemEjectorComponent({
slots: [
{
pos: new Vector(0, 0),
direction: enumDirection.top,
},
{
pos: new Vector(1, 0),
direction: enumDirection.right,
},
],
})
);
entity.addComponent(
new ItemProcessorComponent({
processorType: enumItemProcessorTypes.filter,
inputsPerCharge: 1,
})
);
}
}

View File

@ -19,6 +19,7 @@ export const enumItemProcessorTypes = {
painterDouble: "painterDouble",
painterQuad: "painterQuad",
hub: "hub",
filter: "filter",
};
export class ItemProcessorComponent extends Component {

View File

@ -404,6 +404,8 @@ export class HubGoals extends BasicSerializableObject {
return 1e30;
case enumItemProcessorTypes.splitter:
return globalConfig.beltSpeedItemsPerSecond * this.upgradeImprovements.belt * 2;
case enumItemProcessorTypes.filter:
return globalConfig.beltSpeedItemsPerSecond * this.upgradeImprovements.belt;
case enumItemProcessorTypes.mixer:
case enumItemProcessorTypes.painter:

View File

@ -11,6 +11,7 @@ import { MetaUndergroundBeltBuilding } from "../../buildings/underground_belt";
import { enumLayer } from "../../root";
import { HUDBaseToolbar } from "./base_toolbar";
import { MetaLeverBuilding } from "../../buildings/lever";
import { MetaFilterBuilding } from "../../buildings/filter";
const supportedBuildings = [
MetaBeltBaseBuilding,
@ -24,6 +25,7 @@ const supportedBuildings = [
MetaPainterBuilding,
MetaTrashBuilding,
MetaLeverBuilding,
MetaFilterBuilding,
];
export class HUDBuildingsToolbar extends HUDBaseToolbar {

View File

@ -59,6 +59,7 @@ export const KEYMAPPINGS = {
constant_signal: { keyCode: key("2") },
logic_gate: { keyCode: key("3") },
lever: { keyCode: key("4") },
filter: { keyCode: key("5") },
},
placement: {

View File

@ -18,6 +18,7 @@ import { defaultBuildingVariant } from "./meta_building";
import { MetaConstantSignalBuilding } from "./buildings/constant_signal";
import { MetaLogicGateBuilding, enumLogicGateVariants } from "./buildings/logic_gate";
import { MetaLeverBuilding } from "./buildings/lever";
import { MetaFilterBuilding } from "./buildings/filter";
const logger = createLogger("building_registry");
@ -37,6 +38,7 @@ export function initMetaBuildingRegistry() {
gMetaBuildingRegistry.register(MetaConstantSignalBuilding);
gMetaBuildingRegistry.register(MetaLogicGateBuilding);
gMetaBuildingRegistry.register(MetaLeverBuilding);
gMetaBuildingRegistry.register(MetaFilterBuilding);
// Belt
registerBuildingVariant(1, MetaBeltBaseBuilding, defaultBuildingVariant, 0);
@ -104,6 +106,9 @@ export function initMetaBuildingRegistry() {
// Lever
registerBuildingVariant(33, MetaLeverBuilding);
// Filter
registerBuildingVariant(37, MetaFilterBuilding);
// Propagate instances
for (const key in gBuildingVariants) {
gBuildingVariants[key].metaInstance = gMetaBuildingRegistry.findByClass(

View File

@ -283,6 +283,16 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
const itemProcessorComp = receiver.components.ItemProcessor;
if (itemProcessorComp) {
// @todo HACK
// Check if there are pins, and if so if they are connected
const pinsComp = receiver.components.WiredPins;
if (pinsComp && pinsComp.slots.length === 1) {
const network = pinsComp.slots[0].linkedNetwork;
if (!network || !network.currentValue) {
return false;
}
}
// Its an item processor ..
if (itemProcessorComp.tryTakeItem(item, slotIndex)) {
return true;

View File

@ -1,9 +1,10 @@
import { globalConfig } from "../../core/config";
import { BaseItem, enumItemType } from "../base_item";
import { BaseItem } from "../base_item";
import { enumColorMixingResults } from "../colors";
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
import { Entity } from "../entity";
import { GameSystemWithFilter } from "../game_system_with_filter";
import { BOOL_TRUE_SINGLETON } from "../items/boolean_item";
import { ColorItem } from "../items/color_item";
import { ShapeItem } from "../items/shape_item";
@ -329,6 +330,38 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
break;
}
// FILTER
case enumItemProcessorTypes.filter: {
// TODO
trackProduction = false;
const item = itemsBySlot[0].item;
const network = entity.components.WiredPins.slots[0].linkedNetwork;
if (!network || !network.currentValue) {
outItems.push({
item,
requiredSlot: 1,
});
break;
}
const value = network.currentValue;
if (value.equals(BOOL_TRUE_SINGLETON) || value.equals(item)) {
outItems.push({
item,
requiredSlot: 0,
});
} else {
outItems.push({
item,
requiredSlot: 1,
});
}
break;
}
// HUB
case enumItemProcessorTypes.hub: {

View File

@ -574,6 +574,12 @@ buildings:
name: OR
description: Emits a truthy signal if one of the inputs is truthy.
filter:
default:
name: &filter Filter
# TEMP
description: Only leaves through items who match exactly the provided shape / color. If you put in a boolean 1, it leaves everything through, if you put in a 0 it will leave nothing through.
storyRewards:
# Those are the rewards gained from completing the store
reward_cutter_and_trash:
@ -845,6 +851,7 @@ keybindings:
constant_signal: *constant_signal
logic_gate: *logic_gate
lever: *lever
filter: *filter
# ---
pipette: Pipette