Fix: Add missing createKeyBladeCollision and getKeySurfaceHeightAtPosition to KeyOperations

This commit is contained in:
Z. Cliffe Schreuders
2025-10-27 16:17:30 +00:00
parent 8077391ba6
commit d9703930e1
2 changed files with 61 additions and 51 deletions

View File

@@ -378,5 +378,62 @@ export class KeyOperations {
flash.destroy();
});
}
createKeyBladeCollision() {
if (!this.parent.keyData || !this.parent.keyData.cuts || !this.parent.keyConfig) return;
// Create collision rectangles for each section of the key blade
this.parent.keyCollisionRects = [];
const pinSpacing = 400 / (this.parent.pinCount + 1);
const margin = pinSpacing * 0.75;
const bladeStartX = this.parent.keyConfig.circleRadius * 2 + this.parent.keyConfig.shoulderWidth;
console.log('Creating key collision rectangles, bladeStartX:', bladeStartX);
// Create collision rectangles for each pin position
for (let i = 0; i < this.parent.pinCount; i++) {
const cutDepth = this.parent.keyData.cuts[i] || 50;
const bladeHeight = this.parent.keyConfig.bladeHeight;
// The cut depth directly represents how deep the divot is
// Small pin = small cut, Large pin = large cut
const cutHeight = (bladeHeight / 2) * (cutDepth / 100);
const surfaceHeight = bladeHeight - cutHeight;
// Calculate pin position in the lock
const pinX = 100 + margin + i * pinSpacing;
// Create collision rectangle for this section - position relative to blade start
const rect = {
x: pinX - 100, // Position relative to blade start (not absolute)
y: -bladeHeight/2 + cutHeight, // Position relative to key center
width: 24, // Pin width
height: surfaceHeight,
cutDepth: cutDepth
};
console.log(`Key collision rect ${i}: x=${rect.x}, y=${rect.y}, width=${rect.width}, height=${rect.height}`);
this.parent.keyCollisionRects.push(rect);
}
}
getKeySurfaceHeightAtPosition(pinX, keyBladeStartX) {
if (!this.parent.keyCollisionRects || !this.parent.keyConfig) return this.parent.keyConfig ? this.parent.keyConfig.bladeHeight : 0;
// Find the collision rectangle for this pin position
const pinSpacing = 400 / (this.parent.pinCount + 1);
const margin = pinSpacing * 0.75;
for (let i = 0; i < this.parent.pinCount; i++) {
const cutPinX = 100 + margin + i * pinSpacing;
if (Math.abs(pinX - cutPinX) < 12) { // Within pin width
return this.parent.keyCollisionRects[i].height;
}
}
// If no cut found, return full blade height
return this.parent.keyConfig.bladeHeight;
}
}

View File

@@ -1620,60 +1620,13 @@ export class LockpickingMinigamePhaser extends MinigameScene {
}
createKeyBladeCollision() {
if (!this.keyData || !this.keyData.cuts || !this.keyConfig) return;
// Create collision rectangles for each section of the key blade
this.keyCollisionRects = [];
const pinSpacing = 400 / (this.pinCount + 1);
const margin = pinSpacing * 0.75;
const bladeStartX = this.keyConfig.circleRadius * 2 + this.keyConfig.shoulderWidth;
console.log('Creating key collision rectangles, bladeStartX:', bladeStartX);
// Create collision rectangles for each pin position
for (let i = 0; i < this.pinCount; i++) {
const cutDepth = this.keyData.cuts[i] || 50;
const bladeHeight = this.keyConfig.bladeHeight;
// The cut depth directly represents how deep the divot is
// Small pin = small cut, Large pin = large cut
const cutHeight = (bladeHeight / 2) * (cutDepth / 100);
const surfaceHeight = bladeHeight - cutHeight;
// Calculate pin position in the lock
const pinX = 100 + margin + i * pinSpacing;
// Create collision rectangle for this section - position relative to blade start
const rect = {
x: pinX - 100, // Position relative to blade start (not absolute)
y: -bladeHeight/2 + cutHeight, // Position relative to key center
width: 24, // Pin width
height: surfaceHeight,
cutDepth: cutDepth
};
console.log(`Key collision rect ${i}: x=${rect.x}, y=${rect.y}, width=${rect.width}, height=${rect.height}`);
this.keyCollisionRects.push(rect);
}
// Method moved to KeyOperations module - call via this.keyOps.createKeyBladeCollision()
this.keyOps.createKeyBladeCollision();
}
getKeySurfaceHeightAtPosition(pinX, keyBladeStartX) {
if (!this.keyCollisionRects || !this.keyConfig) return this.keyConfig ? this.keyConfig.bladeHeight : 0;
// Find the collision rectangle for this pin position
const pinSpacing = 400 / (this.pinCount + 1);
const margin = pinSpacing * 0.75;
for (let i = 0; i < this.pinCount; i++) {
const cutPinX = 100 + margin + i * pinSpacing;
if (Math.abs(pinX - cutPinX) < 12) { // Within pin width
return this.keyCollisionRects[i].height;
}
}
// If no cut found, return full blade height
return this.keyConfig.bladeHeight;
// Method moved to KeyOperations module - delegate to it
return this.keyOps.getKeySurfaceHeightAtPosition(pinX, keyBladeStartX);
}
hideLockpickingTools() {