mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-03-02 03:39:21 +00:00
Get rid of item ejector / acceptor layers and new wires buildings for now
This commit is contained in:
@@ -11,7 +11,6 @@ export const curvedBeltLength = /* Math.PI / 4 */ 0.78;
|
||||
export const FAKE_BELT_ACCEPTOR_SLOT = {
|
||||
pos: new Vector(0, 0),
|
||||
directions: [enumDirection.bottom],
|
||||
layer: enumLayer.regular,
|
||||
};
|
||||
|
||||
/** @type {Object<enumDirection, import("./item_ejector").ItemEjectorSlot>} */
|
||||
@@ -20,7 +19,6 @@ export const FAKE_BELT_EJECTOR_SLOT_BY_DIRECTION = {
|
||||
pos: new Vector(0, 0),
|
||||
direction: enumDirection.top,
|
||||
item: null,
|
||||
layer: enumLayer.regular,
|
||||
progress: 0,
|
||||
},
|
||||
|
||||
@@ -28,7 +26,6 @@ export const FAKE_BELT_EJECTOR_SLOT_BY_DIRECTION = {
|
||||
pos: new Vector(0, 0),
|
||||
direction: enumDirection.right,
|
||||
item: null,
|
||||
layer: enumLayer.regular,
|
||||
progress: 0,
|
||||
},
|
||||
|
||||
@@ -36,7 +33,6 @@ export const FAKE_BELT_EJECTOR_SLOT_BY_DIRECTION = {
|
||||
pos: new Vector(0, 0),
|
||||
direction: enumDirection.left,
|
||||
item: null,
|
||||
layer: enumLayer.regular,
|
||||
progress: 0,
|
||||
},
|
||||
};
|
||||
@@ -79,14 +75,9 @@ export class BeltComponent extends Component {
|
||||
|
||||
/**
|
||||
* Returns the effective length of this belt in tile space
|
||||
* @param {enumLayer} layer
|
||||
* @returns {number}
|
||||
*/
|
||||
getEffectiveLengthTiles(layer) {
|
||||
assert(layer, "no layer given");
|
||||
if (layer === enumLayer.wires) {
|
||||
return 1.0;
|
||||
}
|
||||
getEffectiveLengthTiles() {
|
||||
return this.direction === enumDirection.top ? 1.0 : curvedBeltLength;
|
||||
}
|
||||
|
||||
@@ -115,62 +106,28 @@ export class BeltComponent extends Component {
|
||||
* Converts from belt space (0 = start of belt ... 1 = end of belt) to the local
|
||||
* belt coordinates (-0.5|-0.5 to 0.5|0.5)
|
||||
* @param {number} progress
|
||||
* @param {enumLayer} layer
|
||||
* @returns {Vector}
|
||||
*/
|
||||
transformBeltToLocalSpace(progress, layer) {
|
||||
transformBeltToLocalSpace(progress) {
|
||||
assert(progress >= 0.0, "Invalid progress ( < 0): " + progress);
|
||||
switch (this.direction) {
|
||||
case enumDirection.top:
|
||||
assert(progress <= 1.02, "Invalid progress: " + progress);
|
||||
return new Vector(0, 0.5 - progress);
|
||||
|
||||
switch (layer) {
|
||||
case enumLayer.regular: {
|
||||
switch (this.direction) {
|
||||
case enumDirection.top:
|
||||
assert(progress <= 1.02, "Invalid progress: " + progress);
|
||||
return new Vector(0, 0.5 - progress);
|
||||
|
||||
case enumDirection.right: {
|
||||
assert(progress <= curvedBeltLength + 0.02, "Invalid progress 2: " + progress);
|
||||
const arcProgress = (progress / curvedBeltLength) * 0.5 * Math.PI;
|
||||
return new Vector(
|
||||
0.5 - 0.5 * Math.cos(arcProgress),
|
||||
0.5 - 0.5 * Math.sin(arcProgress)
|
||||
);
|
||||
}
|
||||
case enumDirection.left: {
|
||||
assert(progress <= curvedBeltLength + 0.02, "Invalid progress 3: " + progress);
|
||||
const arcProgress = (progress / curvedBeltLength) * 0.5 * Math.PI;
|
||||
return new Vector(
|
||||
-0.5 + 0.5 * Math.cos(arcProgress),
|
||||
0.5 - 0.5 * Math.sin(arcProgress)
|
||||
);
|
||||
}
|
||||
default:
|
||||
assertAlways(false, "Invalid belt direction: " + this.direction);
|
||||
return new Vector(0, 0);
|
||||
}
|
||||
case enumDirection.right: {
|
||||
assert(progress <= curvedBeltLength + 0.02, "Invalid progress 2: " + progress);
|
||||
const arcProgress = (progress / curvedBeltLength) * 0.5 * Math.PI;
|
||||
return new Vector(0.5 - 0.5 * Math.cos(arcProgress), 0.5 - 0.5 * Math.sin(arcProgress));
|
||||
}
|
||||
case enumLayer.wires: {
|
||||
const pow = 0.5;
|
||||
switch (this.direction) {
|
||||
case enumDirection.top:
|
||||
assert(progress <= 1.02, "Invalid progress: " + progress);
|
||||
return new Vector(0, 0.5 - progress);
|
||||
|
||||
case enumDirection.right: {
|
||||
assert(progress <= 1.02, "Invalid progress 2: " + progress);
|
||||
return progress > 0.5 ? new Vector(progress - 0.5, 0) : new Vector(0, 0.5 - progress);
|
||||
}
|
||||
case enumDirection.left: {
|
||||
assert(progress <= 1.02, "Invalid progress 3: " + progress);
|
||||
return progress > 0.5
|
||||
? new Vector(-progress + 0.5, 0)
|
||||
: new Vector(0, 0.5 - progress);
|
||||
}
|
||||
default:
|
||||
assertAlways(false, "Invalid belt direction: " + this.direction);
|
||||
return new Vector(0, 0);
|
||||
}
|
||||
case enumDirection.left: {
|
||||
assert(progress <= curvedBeltLength + 0.02, "Invalid progress 3: " + progress);
|
||||
const arcProgress = (progress / curvedBeltLength) * 0.5 * Math.PI;
|
||||
return new Vector(-0.5 + 0.5 * Math.cos(arcProgress), 0.5 - 0.5 * Math.sin(arcProgress));
|
||||
}
|
||||
default:
|
||||
assertAlways(false, "Invalid belt direction: " + this.direction);
|
||||
return new Vector(0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
import { Component } from "../component";
|
||||
import { types } from "../../savegame/serialization";
|
||||
import { Vector } from "../../core/vector";
|
||||
import { BaseItem, enumItemTypeToLayer, enumItemType } from "../base_item";
|
||||
|
||||
export class EnergyConsumerComponent extends Component {
|
||||
static getId() {
|
||||
return "EnergyConsumer";
|
||||
}
|
||||
|
||||
static getSchema() {
|
||||
return {
|
||||
bufferSize: types.float,
|
||||
perCharge: types.float,
|
||||
batteryPosition: types.vector,
|
||||
energyType: types.enum(enumItemType),
|
||||
wasteType: types.enum(enumItemType),
|
||||
acceptorSlotIndex: types.uint,
|
||||
ejectorSlotIndex: types.uint,
|
||||
|
||||
stored: types.float,
|
||||
piledOutput: types.float,
|
||||
};
|
||||
}
|
||||
|
||||
duplicateWithoutContents() {
|
||||
return new EnergyConsumerComponent({
|
||||
bufferSize: this.bufferSize,
|
||||
perCharge: this.perCharge,
|
||||
batteryPosition: this.batteryPosition.copy(),
|
||||
acceptorSlotIndex: this.acceptorSlotIndex,
|
||||
ejectorSlotIndex: this.ejectorSlotIndex,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {object} param0
|
||||
* @param {number} param0.bufferSize How much energy this consumer can store
|
||||
* @param {number} param0.perCharge How much energy this consumer needs per charge
|
||||
* @param {Vector} param0.batteryPosition world space render offset of the battery icon
|
||||
* @param {number} param0.acceptorSlotIndex Which slot to accept energy on
|
||||
* @param {number} param0.ejectorSlotIndex Which slot to eject energy off
|
||||
*
|
||||
*/
|
||||
constructor({
|
||||
bufferSize = 3,
|
||||
perCharge = 1,
|
||||
batteryPosition = new Vector(),
|
||||
acceptorSlotIndex = 0,
|
||||
ejectorSlotIndex = 0,
|
||||
}) {
|
||||
super();
|
||||
this.bufferSize = bufferSize;
|
||||
this.perCharge = perCharge;
|
||||
this.batteryPosition = batteryPosition;
|
||||
this.energyType = enumItemType.positiveEnergy;
|
||||
this.wasteType = enumItemType.negativeEnergy;
|
||||
this.acceptorSlotIndex = acceptorSlotIndex;
|
||||
this.ejectorSlotIndex = ejectorSlotIndex;
|
||||
|
||||
/**
|
||||
* How much energy we have stored right now
|
||||
*/
|
||||
this.stored = 0;
|
||||
|
||||
/**
|
||||
* How much waste we have piled up so far
|
||||
*/
|
||||
this.piledOutput = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to accept a given item
|
||||
* @param {BaseItem} item
|
||||
* @param {number} slotIndex
|
||||
*/
|
||||
tryAcceptItem(item, slotIndex) {
|
||||
if (slotIndex !== this.acceptorSlotIndex) {
|
||||
// Wrong slot
|
||||
return false;
|
||||
}
|
||||
|
||||
if (item.getItemType() !== this.energyType) {
|
||||
// Not the right type
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.stored >= this.bufferSize) {
|
||||
// We are full
|
||||
return false;
|
||||
}
|
||||
|
||||
// All good, consume
|
||||
this.stored = Math.min(this.stored + 1, this.bufferSize);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to start the next charge
|
||||
*/
|
||||
tryStartNextCharge() {
|
||||
if (this.hasTooMuchWastePiled()) {
|
||||
// Too much waste remaining
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.stored < this.perCharge) {
|
||||
// Not enough energy stored
|
||||
return false;
|
||||
}
|
||||
|
||||
this.stored -= this.perCharge;
|
||||
this.piledOutput += this.perCharge;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if there is too much waste piled
|
||||
*/
|
||||
hasTooMuchWastePiled() {
|
||||
return this.piledOutput >= 1.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces the waste by the given amount
|
||||
* @param {number} amount
|
||||
*/
|
||||
reduceWaste(amount) {
|
||||
this.piledOutput = Math.max(0, this.piledOutput - amount);
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
import { types } from "../../savegame/serialization";
|
||||
import { BaseItem, enumItemType } from "../base_item";
|
||||
import { Component } from "../component";
|
||||
import { ShapeItem } from "../items/shape_item";
|
||||
|
||||
const maxQueueSize = 4;
|
||||
|
||||
export class EnergyGeneratorComponent extends Component {
|
||||
static getId() {
|
||||
return "EnergyGenerator";
|
||||
}
|
||||
|
||||
static getSchema() {
|
||||
return {
|
||||
requiredKey: types.nullable(types.string),
|
||||
itemsInQueue: types.uint,
|
||||
wasteAcceptorSlotIndex: types.uint,
|
||||
};
|
||||
}
|
||||
|
||||
duplicateWithoutContents() {
|
||||
return new EnergyGeneratorComponent({
|
||||
requiredKey: null,
|
||||
wasteAcceptorSlotIndex: this.wasteAcceptorSlotIndex,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {object} param0
|
||||
* @param {string=} param0.requiredKey Which shape this generator needs, can be null if not computed yet
|
||||
* @param {number} param0.wasteAcceptorSlotIndex Which slot accepts the waste
|
||||
*/
|
||||
constructor({ requiredKey, wasteAcceptorSlotIndex = 0 }) {
|
||||
super();
|
||||
this.requiredKey = requiredKey;
|
||||
|
||||
/**
|
||||
* Stores how many items are ready to be converted to energy
|
||||
* @type {number}
|
||||
*/
|
||||
this.itemsInQueue = 0;
|
||||
|
||||
/**
|
||||
* Stores which slot accepts the waste
|
||||
* @type {number}
|
||||
*/
|
||||
this.wasteAcceptorSlotIndex = wasteAcceptorSlotIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {BaseItem} item
|
||||
* @param {number} slot
|
||||
*/
|
||||
tryTakeItem(item, slot) {
|
||||
if (slot === this.wasteAcceptorSlotIndex) {
|
||||
// this is the acceptor slot on the wires layer
|
||||
// just destroy it
|
||||
return true;
|
||||
} else {
|
||||
if (item.getItemType() !== enumItemType.shape) {
|
||||
// This shouldn't happen since we have a filter - still, it doesn't hurt
|
||||
// to check either
|
||||
assertAlways(
|
||||
false,
|
||||
"Energy generator took wrong item: " +
|
||||
item.getItemType() +
|
||||
" on slot " +
|
||||
slot +
|
||||
" (waste slot = " +
|
||||
this.wasteAcceptorSlotIndex +
|
||||
")"
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (/** @type {ShapeItem} */ (item).definition.getHash() !== this.requiredKey) {
|
||||
// Not our shape
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.itemsInQueue >= maxQueueSize) {
|
||||
// Queue is full
|
||||
return false;
|
||||
}
|
||||
|
||||
// Take item and put it into the queue
|
||||
++this.itemsInQueue;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import { enumLayer } from "../root";
|
||||
/** @typedef {{
|
||||
* pos: Vector,
|
||||
* directions: enumDirection[],
|
||||
* layer: enumLayer,
|
||||
* filter?: enumItemType
|
||||
* }} ItemAcceptorSlot */
|
||||
|
||||
@@ -22,7 +21,6 @@ import { enumLayer } from "../root";
|
||||
/** @typedef {{
|
||||
* pos: Vector,
|
||||
* directions: enumDirection[],
|
||||
* layer?: enumLayer,
|
||||
* filter?: enumItemType
|
||||
* }} ItemAcceptorSlotConfig */
|
||||
|
||||
@@ -38,9 +36,6 @@ export class ItemAcceptorComponent extends Component {
|
||||
pos: types.vector,
|
||||
directions: types.array(types.enum(enumDirection)),
|
||||
filter: types.nullable(types.enum(enumItemType)),
|
||||
|
||||
// TODO: MIGRATE
|
||||
layer: types.enum(enumLayer),
|
||||
})
|
||||
),
|
||||
};
|
||||
@@ -54,7 +49,6 @@ export class ItemAcceptorComponent extends Component {
|
||||
pos: slot.pos.copy(),
|
||||
directions: slot.directions.slice(),
|
||||
filter: slot.filter,
|
||||
layer: slot.layer,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -92,7 +86,6 @@ export class ItemAcceptorComponent extends Component {
|
||||
this.slots.push({
|
||||
pos: slot.pos,
|
||||
directions: slot.directions,
|
||||
layer: slot.layer || enumLayer.regular,
|
||||
|
||||
// Which type of item to accept (shape | color | all) @see enumItemType
|
||||
filter: slot.filter,
|
||||
@@ -147,10 +140,9 @@ export class ItemAcceptorComponent extends Component {
|
||||
* Tries to find a slot which accepts the current item
|
||||
* @param {Vector} targetLocalTile
|
||||
* @param {enumDirection} fromLocalDirection
|
||||
* @param {enumLayer} layer
|
||||
* @returns {ItemAcceptorLocatedSlot|null}
|
||||
*/
|
||||
findMatchingSlot(targetLocalTile, fromLocalDirection, layer) {
|
||||
findMatchingSlot(targetLocalTile, fromLocalDirection) {
|
||||
// We need to invert our direction since the acceptor specifies *from* which direction
|
||||
// it accepts items, but the ejector specifies *into* which direction it ejects items.
|
||||
// E.g.: Ejector ejects into "right" direction but acceptor accepts from "left" direction.
|
||||
@@ -165,11 +157,6 @@ export class ItemAcceptorComponent extends Component {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Make sure the layer matches
|
||||
if (slot.layer !== layer) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if the acceptor slot accepts items from our direction
|
||||
for (let i = 0; i < slot.directions.length; ++i) {
|
||||
// const localDirection = targetStaticComp.localDirectionToWorld(slot.directions[l]);
|
||||
|
||||
@@ -12,7 +12,6 @@ import { BeltPath } from "../belt_path";
|
||||
* pos: Vector,
|
||||
* direction: enumDirection,
|
||||
* item: BaseItem,
|
||||
* layer: enumLayer,
|
||||
* progress: number?,
|
||||
* cachedDestSlot?: import("./item_acceptor").ItemAcceptorLocatedSlot,
|
||||
* cachedBeltPath?: BeltPath,
|
||||
@@ -34,9 +33,6 @@ export class ItemEjectorComponent extends Component {
|
||||
direction: types.enum(enumDirection),
|
||||
item: types.nullable(types.obj(gItemRegistry)),
|
||||
progress: types.float,
|
||||
|
||||
// TODO: Migrate
|
||||
layer: types.enum(enumLayer),
|
||||
})
|
||||
),
|
||||
};
|
||||
@@ -49,7 +45,6 @@ export class ItemEjectorComponent extends Component {
|
||||
slotsCopy.push({
|
||||
pos: slot.pos.copy(),
|
||||
direction: slot.direction,
|
||||
layer: slot.layer,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -61,7 +56,7 @@ export class ItemEjectorComponent extends Component {
|
||||
/**
|
||||
*
|
||||
* @param {object} param0
|
||||
* @param {Array<{pos: Vector, direction: enumDirection, layer?: enumLayer}>=} param0.slots The slots to eject on
|
||||
* @param {Array<{pos: Vector, direction: enumDirection }>=} param0.slots The slots to eject on
|
||||
*/
|
||||
constructor({ slots = [] }) {
|
||||
super();
|
||||
@@ -75,7 +70,7 @@ export class ItemEjectorComponent extends Component {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Array<{pos: Vector, direction: enumDirection, layer?: enumLayer}>} slots The slots to eject on
|
||||
* @param {Array<{pos: Vector, direction: enumDirection }>} slots The slots to eject on
|
||||
*/
|
||||
setSlots(slots) {
|
||||
/** @type {Array<ItemEjectorSlot>} */
|
||||
@@ -87,7 +82,6 @@ export class ItemEjectorComponent extends Component {
|
||||
direction: slot.direction,
|
||||
item: null,
|
||||
progress: 0,
|
||||
layer: slot.layer || enumLayer.regular,
|
||||
cachedDestSlot: null,
|
||||
cachedTargetEntity: null,
|
||||
});
|
||||
@@ -108,11 +102,10 @@ export class ItemEjectorComponent extends Component {
|
||||
/**
|
||||
* Returns whether any slot ejects to the given local tile
|
||||
* @param {Vector} tile
|
||||
* @param {enumLayer} layer
|
||||
*/
|
||||
anySlotEjectsToLocalTile(tile, layer) {
|
||||
anySlotEjectsToLocalTile(tile) {
|
||||
for (let i = 0; i < this.slots.length; ++i) {
|
||||
if (this.getSlotTargetLocalTile(i).equals(tile) && this.slots[i].layer === layer) {
|
||||
if (this.getSlotTargetLocalTile(i).equals(tile)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -131,12 +124,11 @@ export class ItemEjectorComponent extends Component {
|
||||
|
||||
/**
|
||||
* Returns the first free slot on this ejector or null if there is none
|
||||
* @param {enumLayer} layer
|
||||
* @returns {number?}
|
||||
*/
|
||||
getFirstFreeSlot(layer) {
|
||||
getFirstFreeSlot() {
|
||||
for (let i = 0; i < this.slots.length; ++i) {
|
||||
if (this.canEjectOnSlot(i) && this.slots[i].layer === layer) {
|
||||
if (this.canEjectOnSlot(i)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ export const enumItemProcessorTypes = {
|
||||
painter: "painter",
|
||||
painterDouble: "painterDouble",
|
||||
painterQuad: "painterQuad",
|
||||
advancedProcessor: "advancedProcessor",
|
||||
hub: "hub",
|
||||
};
|
||||
|
||||
|
||||
@@ -103,8 +103,7 @@ export class UndergroundBeltComponent extends Component {
|
||||
}
|
||||
|
||||
// Notice: We assume that for all items the travel distance is the same
|
||||
const maxItemsInTunnel =
|
||||
(2 + travelDistance) / globalConfig.beltItemSpacingByLayer[enumLayer.regular];
|
||||
const maxItemsInTunnel = (2 + travelDistance) / globalConfig.itemSpacingOnBelts;
|
||||
if (this.pendingItems.length >= maxItemsInTunnel) {
|
||||
// Simulate a real belt which gets full at some point
|
||||
return false;
|
||||
@@ -114,8 +113,7 @@ export class UndergroundBeltComponent extends Component {
|
||||
// This corresponds to the item ejector - it needs 0.5 additional tiles to eject the item.
|
||||
// So instead of adding 1 we add 0.5 only.
|
||||
// Additionally it takes 1 tile for the acceptor which we just add on top.
|
||||
const travelDuration =
|
||||
(travelDistance + 1.5) / beltSpeed / globalConfig.beltItemSpacingByLayer[enumLayer.regular];
|
||||
const travelDuration = (travelDistance + 1.5) / beltSpeed / globalConfig.itemSpacingOnBelts;
|
||||
|
||||
this.pendingItems.push([item, travelDuration]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user