mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
comments and prettier added
This commit is contained in:
parent
14eaa2d9aa
commit
5405d34c21
@ -41,6 +41,10 @@ export class BeltReaderComponent extends Component {
|
|||||||
*/
|
*/
|
||||||
this.lastThroughputComputation = 0;
|
this.lastThroughputComputation = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the entry time of the latest removed item
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
this.lastRemovedItemTime = 0;
|
this.lastRemovedItemTime = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ export class BeltReaderSystem extends GameSystemWithFilter {
|
|||||||
update() {
|
update() {
|
||||||
const now = this.root.time.now();
|
const now = this.root.time.now();
|
||||||
const minimumTime = now - globalConfig.readerAnalyzeIntervalSeconds;
|
const minimumTime = now - globalConfig.readerAnalyzeIntervalSeconds;
|
||||||
const minimumTimeForThroughput = now - 1;
|
|
||||||
for (let i = 0; i < this.allEntities.length; ++i) {
|
for (let i = 0; i < this.allEntities.length; ++i) {
|
||||||
const entity = this.allEntities[i];
|
const entity = this.allEntities[i];
|
||||||
|
|
||||||
@ -19,16 +18,19 @@ export class BeltReaderSystem extends GameSystemWithFilter {
|
|||||||
const lastItemTimes = readerComp.lastItemTimes;
|
const lastItemTimes = readerComp.lastItemTimes;
|
||||||
const pinsComp = entity.components.WiredPins;
|
const pinsComp = entity.components.WiredPins;
|
||||||
|
|
||||||
// Remove outdated items
|
// Remove outdated items and set lastRemovedItemTime
|
||||||
while (lastItemTimes[0] < minimumTime) {
|
while (lastItemTimes[0] < minimumTime) {
|
||||||
readerComp.lastRemovedItemTime = lastItemTimes.shift();
|
readerComp.lastRemovedItemTime = lastItemTimes.shift();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (now - readerComp.lastThroughputComputation > 0.5) {
|
if (now - readerComp.lastThroughputComputation > 0.5) {
|
||||||
// Compute throughput
|
// Compute throughput
|
||||||
readerComp.lastThroughputComputation = now;
|
readerComp.lastThroughputComputation = now;
|
||||||
|
|
||||||
|
//if only one item is in the list, use the time from the last removed item
|
||||||
|
//to allow for much lower numbers to be correctly calculated
|
||||||
const oneItem = lastItemTimes.length == 1;
|
const oneItem = lastItemTimes.length == 1;
|
||||||
|
|
||||||
let throughput = 0;
|
let throughput = 0;
|
||||||
if (lastItemTimes.length > 0) {
|
if (lastItemTimes.length > 0) {
|
||||||
let averageSpacing = oneItem ? lastItemTimes[0] - readerComp.lastRemovedItemTime : 0;
|
let averageSpacing = oneItem ? lastItemTimes[0] - readerComp.lastRemovedItemTime : 0;
|
||||||
@ -44,6 +46,7 @@ export class BeltReaderSystem extends GameSystemWithFilter {
|
|||||||
readerComp.lastThroughput = Math.min(globalConfig.beltSpeedItemsPerSecond, throughput);
|
readerComp.lastThroughput = Math.min(globalConfig.beltSpeedItemsPerSecond, throughput);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the pins value - shape output consistent with the boolean output
|
||||||
if (readerComp.lastThroughput > 0) {
|
if (readerComp.lastThroughput > 0) {
|
||||||
pinsComp.slots[0].value = BOOL_TRUE_SINGLETON;
|
pinsComp.slots[0].value = BOOL_TRUE_SINGLETON;
|
||||||
pinsComp.slots[1].value = readerComp.lastItem;
|
pinsComp.slots[1].value = readerComp.lastItem;
|
||||||
|
Loading…
Reference in New Issue
Block a user