mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +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 }],
|
||||
})
|
||||
);
|
||||
entity.addComponent(new ItemProducerComponent({}));
|
||||
entity.addComponent(new ItemProducerComponent());
|
||||
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() {
|
||||
return "ItemProducer";
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
/** @type {number} */
|
||||
this.lastOutputTime = 0;
|
||||
}
|
||||
}
|
||||
|
@ -11,17 +11,30 @@ export class ConstantProducerSystem extends GameSystemWithFilter {
|
||||
/** @param {GameRoot} root */
|
||||
constructor(root) {
|
||||
super(root, [ConstantSignalComponent, ItemProducerComponent]);
|
||||
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
update() {
|
||||
for (let i = 0; i < this.allEntities.length; ++i) {
|
||||
const entity = this.allEntities[i];
|
||||
const signalComp = entity.components.ConstantSignal;
|
||||
const ejectorComp = entity.components.ItemEjector;
|
||||
const signalComp = entity.components.ConstantSignal;
|
||||
|
||||
if (!ejectorComp) {
|
||||
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