mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-16 11:41:50 +00:00
consolidate belt drawing logic
This commit is contained in:
parent
6ea9f91641
commit
e23c3c17e2
@ -50,8 +50,6 @@ export class MapChunkView extends MapChunk {
|
|||||||
systems.mapResources.drawChunk(parameters, this);
|
systems.mapResources.drawChunk(parameters, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
systems.acceptorBelt.drawChunk(parameters, this);
|
|
||||||
systems.ejectorBelt.drawChunk(parameters, this);
|
|
||||||
systems.belt.drawChunk(parameters, this);
|
systems.belt.drawChunk(parameters, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -74,17 +74,11 @@ export class AcceptorBeltSystem extends GameSystemWithFilter {
|
|||||||
* Draws a given chunk
|
* Draws a given chunk
|
||||||
* @param {DrawParameters} parameters
|
* @param {DrawParameters} parameters
|
||||||
* @param {MapChunkView} chunk
|
* @param {MapChunkView} chunk
|
||||||
|
* @param {object} param0
|
||||||
|
* @param {number} param0.animationIndex
|
||||||
|
* @param {boolean} param0.simplifiedBelts
|
||||||
*/
|
*/
|
||||||
drawChunk(parameters, chunk) {
|
internalDrawChunk(parameters, chunk, { animationIndex, simplifiedBelts }) {
|
||||||
// SYNC with systems/belt.js:drawChunk!
|
|
||||||
const speedMultiplier = Math.min(this.root.hubGoals.getBeltBaseSpeed(), 10);
|
|
||||||
const animationIndex = Math.floor(
|
|
||||||
((this.root.time.realtimeNow() * speedMultiplier * BELT_ANIM_COUNT * 126) / 42) *
|
|
||||||
globalConfig.itemSpacingOnBelts
|
|
||||||
);
|
|
||||||
|
|
||||||
const simplifiedBelts = this.root.app.settings.getAllSettings().simplifiedBelts;
|
|
||||||
|
|
||||||
const contents = chunk.containedEntitiesByLayer.regular;
|
const contents = chunk.containedEntitiesByLayer.regular;
|
||||||
for (let i = 0; i < contents.length; ++i) {
|
for (let i = 0; i < contents.length; ++i) {
|
||||||
const entity = contents[i];
|
const entity = contents[i];
|
||||||
|
|||||||
@ -496,16 +496,42 @@ export class BeltSystem extends GameSystemWithFilter {
|
|||||||
* Draws a given chunk
|
* Draws a given chunk
|
||||||
* @param {DrawParameters} parameters
|
* @param {DrawParameters} parameters
|
||||||
* @param {MapChunkView} chunk
|
* @param {MapChunkView} chunk
|
||||||
|
* @param {object} param0
|
||||||
|
* @param {number} param0.animationIndex
|
||||||
|
* @param {boolean} param0.simplifiedBelts
|
||||||
|
* @param {BeltPath} param0.hoveredBeltPath
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
internalDrawChunk(parameters, chunk, { animationIndex, simplifiedBelts, hoveredBeltPath }) {
|
||||||
|
const contents = chunk.containedEntitiesByLayer.regular;
|
||||||
|
for (let i = 0; i < contents.length; ++i) {
|
||||||
|
const entity = contents[i];
|
||||||
|
if (entity.components.Belt) {
|
||||||
|
const { direction, assignedPath } = entity.components.Belt;
|
||||||
|
const sprite = this.beltAnimations[direction][
|
||||||
|
!simplifiedBelts || assignedPath === hoveredBeltPath ? animationIndex : 0
|
||||||
|
];
|
||||||
|
|
||||||
|
// Culling happens within the static map entity component
|
||||||
|
entity.components.StaticMapEntity.drawSpriteOnBoundsClipped(parameters, sprite, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws a given chunk, including acceptor/ejector belts
|
||||||
|
* @param {DrawParameters} parameters
|
||||||
|
* @param {MapChunkView} chunk
|
||||||
*/
|
*/
|
||||||
drawChunk(parameters, chunk) {
|
drawChunk(parameters, chunk) {
|
||||||
// SYNC with systems/acceptor_belt.js:drawChunk and systems/ejector_belt.js:drawChunk!
|
|
||||||
// Limit speed to avoid belts going backwards
|
// Limit speed to avoid belts going backwards
|
||||||
const speedMultiplier = Math.min(this.root.hubGoals.getBeltBaseSpeed(), 10);
|
const speedMultiplier = Math.min(this.root.hubGoals.getBeltBaseSpeed(), 10);
|
||||||
// 126 / 42 is the exact animation speed of the png animation
|
// 126 / 42 is the exact animation speed of the png animation
|
||||||
const animationIndex = Math.floor(
|
const animationIndex =
|
||||||
((this.root.time.realtimeNow() * speedMultiplier * BELT_ANIM_COUNT * 126) / 42) *
|
Math.floor(
|
||||||
globalConfig.itemSpacingOnBelts
|
((this.root.time.realtimeNow() * speedMultiplier * BELT_ANIM_COUNT * 126) / 42) *
|
||||||
);
|
globalConfig.itemSpacingOnBelts
|
||||||
|
) % BELT_ANIM_COUNT;
|
||||||
|
|
||||||
const simplifiedBelts = this.root.app.settings.getAllSettings().simplifiedBelts;
|
const simplifiedBelts = this.root.app.settings.getAllSettings().simplifiedBelts;
|
||||||
|
|
||||||
@ -522,21 +548,15 @@ export class BeltSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const contents = chunk.containedEntitiesByLayer.regular;
|
this.internalDrawChunk(parameters, chunk, { animationIndex, simplifiedBelts, hoveredBeltPath });
|
||||||
for (let i = 0; i < contents.length; ++i) {
|
this.root.systemMgr.systems.acceptorBelt.internalDrawChunk(parameters, chunk, {
|
||||||
const entity = contents[i];
|
animationIndex,
|
||||||
if (entity.components.Belt) {
|
simplifiedBelts,
|
||||||
const { direction, assignedPath } = entity.components.Belt;
|
});
|
||||||
const sprite = this.beltAnimations[direction][
|
this.root.systemMgr.systems.ejectorBelt.internalDrawChunk(parameters, chunk, {
|
||||||
!simplifiedBelts || assignedPath === hoveredBeltPath
|
animationIndex,
|
||||||
? animationIndex % BELT_ANIM_COUNT
|
simplifiedBelts,
|
||||||
: 0
|
});
|
||||||
];
|
|
||||||
|
|
||||||
// Culling happens within the static map entity component
|
|
||||||
entity.components.StaticMapEntity.drawSpriteOnBoundsClipped(parameters, sprite, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -24,17 +24,11 @@ export class EjectorBeltSystem extends GameSystemWithFilter {
|
|||||||
* Draws a given chunk
|
* Draws a given chunk
|
||||||
* @param {DrawParameters} parameters
|
* @param {DrawParameters} parameters
|
||||||
* @param {MapChunkView} chunk
|
* @param {MapChunkView} chunk
|
||||||
|
* @param {object} param0
|
||||||
|
* @param {number} param0.animationIndex
|
||||||
|
* @param {boolean} param0.simplifiedBelts
|
||||||
*/
|
*/
|
||||||
drawChunk(parameters, chunk) {
|
internalDrawChunk(parameters, chunk, { animationIndex, simplifiedBelts }) {
|
||||||
// SYNC with systems/belt.js:drawChunk!
|
|
||||||
const speedMultiplier = Math.min(this.root.hubGoals.getBeltBaseSpeed(), 10);
|
|
||||||
const animationIndex = Math.floor(
|
|
||||||
((this.root.time.realtimeNow() * speedMultiplier * BELT_ANIM_COUNT * 126) / 42) *
|
|
||||||
globalConfig.itemSpacingOnBelts
|
|
||||||
);
|
|
||||||
|
|
||||||
const simplifiedBelts = this.root.app.settings.getAllSettings().simplifiedBelts;
|
|
||||||
|
|
||||||
const contents = chunk.containedEntitiesByLayer.regular;
|
const contents = chunk.containedEntitiesByLayer.regular;
|
||||||
for (let i = 0; i < contents.length; ++i) {
|
for (let i = 0; i < contents.length; ++i) {
|
||||||
const entity = contents[i];
|
const entity = contents[i];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user