1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2024-10-27 20:34:29 +00:00

Fix belt paths not rendering

This commit is contained in:
tobspr 2020-09-21 18:07:47 +02:00
parent ff2274f671
commit 2ac570f6d8
2 changed files with 55 additions and 1 deletions

View File

@ -186,9 +186,12 @@ export class BeltPath extends BasicSerializableObject {
/** /**
* Finds the entity which accepts our items * Finds the entity which accepts our items
* @param {boolean=} debug_Silent Whether debug output should be silent
* @return {{ entity: Entity, slot: number, direction?: enumDirection }} * @return {{ entity: Entity, slot: number, direction?: enumDirection }}
*/ */
computeAcceptingEntityAndSlot() { computeAcceptingEntityAndSlot(debug_Silent = false) {
DEBUG && !debug_Silent && logger.log("Recomputing acceptor target");
const lastEntity = this.entityPath[this.entityPath.length - 1]; const lastEntity = this.entityPath[this.entityPath.length - 1];
const lastStatic = lastEntity.components.StaticMapEntity; const lastStatic = lastEntity.components.StaticMapEntity;
const lastBeltComp = lastEntity.components.Belt; const lastBeltComp = lastEntity.components.Belt;
@ -207,12 +210,23 @@ export class BeltPath extends BasicSerializableObject {
); );
if (targetEntity) { if (targetEntity) {
DEBUG && !debug_Silent && logger.log(" Found target entity", targetEntity.uid);
const targetStaticComp = targetEntity.components.StaticMapEntity; const targetStaticComp = targetEntity.components.StaticMapEntity;
const targetBeltComp = targetEntity.components.Belt; const targetBeltComp = targetEntity.components.Belt;
// Check for belts (special case) // Check for belts (special case)
if (targetBeltComp) { if (targetBeltComp) {
const beltAcceptingDirection = targetStaticComp.localDirectionToWorld(enumDirection.top); const beltAcceptingDirection = targetStaticComp.localDirectionToWorld(enumDirection.top);
DEBUG &&
!debug_Silent &&
logger.log(
" Entity is accepting items from",
ejectSlotWsDirection,
"vs",
beltAcceptingDirection,
"Rotation:",
targetStaticComp.rotation
);
if (ejectSlotWsDirection === beltAcceptingDirection) { if (ejectSlotWsDirection === beltAcceptingDirection) {
return { return {
entity: targetEntity, entity: targetEntity,
@ -377,6 +391,41 @@ export class BeltPath extends BasicSerializableObject {
if (!actualBounds.equalsEpsilon(this.worldBounds, 0.01)) { if (!actualBounds.equalsEpsilon(this.worldBounds, 0.01)) {
return fail("Bounds are stale"); return fail("Bounds are stale");
} }
// Check acceptor
const acceptor = this.computeAcceptingEntityAndSlot(true);
if (!!acceptor !== !!this.acceptorTarget) {
return fail("Acceptor target mismatch, acceptor", !!acceptor, "vs stored", !!this.acceptorTarget);
}
if (acceptor) {
if (this.acceptorTarget.entity !== acceptor.entity) {
return fail(
"Mismatching entity on acceptor target:",
acceptor.entity.uid,
"vs",
this.acceptorTarget.entity.uid
);
}
if (this.acceptorTarget.slot !== acceptor.slot) {
return fail(
"Mismatching entity on acceptor target:",
acceptor.slot,
"vs stored",
this.acceptorTarget.slot
);
}
if (this.acceptorTarget.direction !== acceptor.direction) {
return fail(
"Mismatching direction on acceptor target:",
acceptor.direction,
"vs stored",
this.acceptorTarget.direction
);
}
}
} }
/* dev:end */ /* dev:end */

View File

@ -165,6 +165,8 @@ export class BeltSystem extends GameSystemWithFilter {
const newDirection = arrayBeltVariantToRotation[rotationVariant]; const newDirection = arrayBeltVariantToRotation[rotationVariant];
if (targetStaticComp.rotation !== rotation || newDirection !== targetBeltComp.direction) { if (targetStaticComp.rotation !== rotation || newDirection !== targetBeltComp.direction) {
const originalPath = targetBeltComp.assignedPath;
// Ok, first remove it from its current path // Ok, first remove it from its current path
this.deleteEntityFromPath(targetBeltComp.assignedPath, targetEntity); this.deleteEntityFromPath(targetBeltComp.assignedPath, targetEntity);
@ -179,6 +181,9 @@ export class BeltSystem extends GameSystemWithFilter {
rotationVariant rotationVariant
); );
// Update the original path since it might have picked up the entit1y
originalPath.onPathChanged();
// Now add it again // Now add it again
this.addEntityToPaths(targetEntity); this.addEntityToPaths(targetEntity);