1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Multiple improvements

This commit is contained in:
tobspr
2020-05-17 10:07:20 +02:00
parent ce8640195a
commit 13c6fc7598
26 changed files with 360 additions and 208 deletions

View File

@@ -59,9 +59,8 @@ export class BeltComponent extends Component {
/**
* Returns if the belt can currently accept an item from the given direction
* @param {enumDirection} direction
*/
canAcceptNewItem(direction) {
canAcceptNewItem() {
const firstItem = this.sortedItems[0];
if (!firstItem) {
return true;
@@ -73,9 +72,8 @@ export class BeltComponent extends Component {
/**
* Pushes a new item to the belt
* @param {BaseItem} item
* @param {enumDirection} direction
*/
takeNewItem(item, direction) {
takeNewItem(item) {
this.sortedItems.unshift([0, item]);
}

View File

@@ -1,5 +1,5 @@
import { Component } from "../component";
import { Vector, enumDirection, enumDirectionToAngle, enumInvertedDirections } from "../../core/vector";
import { Vector, enumDirection, enumInvertedDirections } from "../../core/vector";
import { BaseItem } from "../base_item";
import { ShapeItem } from "../items/shape_item";
import { ColorItem } from "../items/color_item";
@@ -34,6 +34,23 @@ export class ItemAcceptorComponent extends Component {
filter: types.nullable(types.enum(enumItemAcceptorItemFilter)),
})
),
animated: types.bool,
beltUnderlays: types.array(
types.structured({
pos: types.vector,
direction: types.enum(enumDirection),
})
),
// We don't actually need to store the animations
// itemConsumptionAnimations: types.array(
// types.structured({
// item: types.obj(gItemRegistry),
// slotIndex: types.uint,
// animProgress: types.float,
// direction: types.enum(enumDirection),
// })
// ),
};
}
@@ -41,10 +58,23 @@ export class ItemAcceptorComponent extends Component {
*
* @param {object} param0
* @param {Array<{pos: Vector, directions: enumDirection[], filter?: enumItemAcceptorItemFilter}>} param0.slots The slots from which we accept items
* @param {boolean=} param0.animated Whether to animate item consumption
* @param {Array<{pos: Vector, direction: enumDirection}>=} param0.beltUnderlays Where to render belt underlays
*/
constructor({ slots = [] }) {
constructor({ slots = [], beltUnderlays = [], animated = true }) {
super();
this.animated = animated;
/**
* Fixes belt animations
* @type {Array<{ item: BaseItem, slotIndex: number, animProgress: number, direction: enumDirection}>}
*/
this.itemConsumptionAnimations = [];
/* Which belt underlays to render */
this.beltUnderlays = beltUnderlays;
this.setSlots(slots);
}
@@ -86,6 +116,23 @@ export class ItemAcceptorComponent extends Component {
}
}
/**
* Called when an item has been accepted so that
* @param {number} slotIndex
* @param {enumDirection} direction
* @param {BaseItem} item
*/
onItemAccepted(slotIndex, direction, item) {
if (this.animated) {
this.itemConsumptionAnimations.push({
item,
slotIndex,
direction,
animProgress: 0.0,
});
}
}
/**
* Tries to find a slot which accepts the current item
* @param {Vector} targetLocalTile
@@ -106,12 +153,6 @@ export class ItemAcceptorComponent extends Component {
for (let slotIndex = 0; slotIndex < this.slots.length; ++slotIndex) {
const slot = this.slots[slotIndex];
// const acceptorLocalPosition = targetStaticComp.applyRotationToVector(
// slot.pos
// );
// const acceptorGlobalPosition = acceptorLocalPosition.add(targetStaticComp.origin);
// Make sure the acceptor slot is on the right position
if (!slot.pos.equals(targetLocalTile)) {
continue;
@@ -130,7 +171,6 @@ export class ItemAcceptorComponent extends Component {
}
}
// && this.canAcceptItem(slotIndex, ejectingItem)
return null;
}
}

View File

@@ -30,12 +30,7 @@ export class ItemProcessorComponent extends Component {
nextOutputSlot: types.uint,
type: types.enum(enumItemProcessorTypes),
inputsPerCharge: types.uint,
beltUnderlays: types.array(
types.structured({
pos: types.vector,
direction: types.enum(enumDirection),
})
),
inputSlots: types.array(
types.structured({
item: types.obj(gItemRegistry),
@@ -50,14 +45,6 @@ export class ItemProcessorComponent extends Component {
})
),
secondsUntilEject: types.float,
itemConsumptionAnimations: types.array(
types.structured({
item: types.obj(gItemRegistry),
slotIndex: types.uint,
animProgress: types.float,
direction: types.enum(enumDirection),
})
),
};
}
@@ -66,14 +53,9 @@ export class ItemProcessorComponent extends Component {
* @param {object} param0
* @param {enumItemProcessorTypes=} param0.processorType Which type of processor this is
* @param {number=} param0.inputsPerCharge How many items this machine needs until it can start working
* @param {Array<{pos: Vector, direction: enumDirection}>=} param0.beltUnderlays Where to render belt underlays
*
*/
constructor({
processorType = enumItemProcessorTypes.splitter,
inputsPerCharge = 1,
beltUnderlays = [],
}) {
constructor({ processorType = enumItemProcessorTypes.splitter, inputsPerCharge = 1 }) {
super();
// Which slot to emit next, this is only a preference and if it can't emit
@@ -87,9 +69,6 @@ export class ItemProcessorComponent extends Component {
// How many inputs we need for one charge
this.inputsPerCharge = inputsPerCharge;
// Which belt underlays to render
this.beltUnderlays = beltUnderlays;
/**
* Our current inputs
* @type {Array<{ item: BaseItem, sourceSlot: number }>}
@@ -108,19 +87,14 @@ export class ItemProcessorComponent extends Component {
* How long it takes until we are done with the current items
*/
this.secondsUntilEject = 0;
/**
* Fixes belt animations
* @type {Array<{ item: BaseItem, slotIndex: number, animProgress: number, direction: enumDirection}>}
*/
this.itemConsumptionAnimations = [];
}
/**
* Tries to take the item
* @param {BaseItem} item
* @param {number} sourceSlot
*/
tryTakeItem(item, sourceSlot, sourceDirection) {
tryTakeItem(item, sourceSlot) {
// Check that we only take one item per slot
for (let i = 0; i < this.inputSlots.length; ++i) {
const slot = this.inputSlots[i];
@@ -130,12 +104,6 @@ export class ItemProcessorComponent extends Component {
}
this.inputSlots.push({ item, sourceSlot });
this.itemConsumptionAnimations.push({
item,
slotIndex: sourceSlot,
direction: sourceDirection,
animProgress: 0.0,
});
return true;
}
}

View File

@@ -34,6 +34,9 @@ export class UndergroundBeltComponent extends Component {
this.mode = mode;
this.tier = tier;
/** @type {Array<{ item: BaseItem, progress: number }>} */
this.consumptionAnimations = [];
/**
* Used on both receiver and sender.
* Reciever: Used to store the next item to transfer, and to block input while doing this