mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-02-12 19:09:21 +00:00
fixed the output speed of producers being too fast sometimes
This commit is contained in:
parent
a1c6a99df0
commit
27d340009f
@ -36,7 +36,7 @@ export class MetaConstantProducerBuilding extends MetaBuilding {
|
|||||||
slots: [{ pos: new Vector(0, 0), direction: enumDirection.top }],
|
slots: [{ pos: new Vector(0, 0), direction: enumDirection.top }],
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
entity.addComponent(new ItemProducerComponent({}));
|
entity.addComponent(new ItemProducerComponent());
|
||||||
entity.addComponent(new ConstantSignalComponent({}));
|
entity.addComponent(new ConstantSignalComponent({}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,6 +39,6 @@ export class MetaItemProducerBuilding extends MetaBuilding {
|
|||||||
],
|
],
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
entity.addComponent(new ItemProducerComponent({}));
|
entity.addComponent(new ItemProducerComponent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,4 +4,11 @@ export class ItemProducerComponent extends Component {
|
|||||||
static getId() {
|
static getId() {
|
||||||
return "ItemProducer";
|
return "ItemProducer";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
/** @type {number} */
|
||||||
|
this.lastOutputTime = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,17 +11,30 @@ export class ConstantProducerSystem extends GameSystemWithFilter {
|
|||||||
/** @param {GameRoot} root */
|
/** @param {GameRoot} root */
|
||||||
constructor(root) {
|
constructor(root) {
|
||||||
super(root, [ConstantSignalComponent, ItemProducerComponent]);
|
super(root, [ConstantSignalComponent, ItemProducerComponent]);
|
||||||
|
|
||||||
|
this.root = root;
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
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];
|
||||||
const signalComp = entity.components.ConstantSignal;
|
|
||||||
const ejectorComp = entity.components.ItemEjector;
|
const ejectorComp = entity.components.ItemEjector;
|
||||||
|
const signalComp = entity.components.ConstantSignal;
|
||||||
|
|
||||||
if (!ejectorComp) {
|
if (!ejectorComp) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ejectorComp.tryEject(0, signalComp.signal);
|
|
||||||
|
const now = this.root.time.now();
|
||||||
|
const secondsPerItem = 1 / (globalConfig.puzzleModeSpeed * globalConfig.beltSpeedItemsPerSecond);
|
||||||
|
|
||||||
|
const producerComp = entity.components.ItemProducer;
|
||||||
|
|
||||||
|
if (now - producerComp.lastOutputTime > secondsPerItem) {
|
||||||
|
if (ejectorComp.tryEject(0, signalComp.signal)) {
|
||||||
|
producerComp.lastOutputTime = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user