Last active
November 5, 2021 01:56
-
-
Save Rio6/49e3916c6eae2d1955dc0aa10051395e to your computer and use it in GitHub Desktop.
A script that lets you press f when dragging a part to flip it. Only works on your own client.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* A script that lets you press f when dragging a part to flip it. | |
* Only works on your own client. | |
* | |
* by R26 | |
*/ | |
window.flipPartHooks = window.flipPartHooks || { | |
design_onkeyup: designMode.onkeyup, | |
design_rotatePart: designMode.rotatePart, | |
design_draw: designMode.draw, | |
part_draw: Part.prototype.draw, | |
}; | |
flipPart = part => { | |
if(part.dir === 0) part.dir = 4; | |
part.dir *= -1; | |
if(part.dir === 4) part.dir = 0; | |
}; | |
designMode.onkeyup = function(e) { | |
const part = this.draggingPart; | |
if(e.key === 'f' && part?.flip) { | |
flipPart(part); | |
} | |
flipPartHooks.design_onkeyup.call(this, e); | |
}; | |
designMode.rotatePart = function(part, way) { | |
const flip = part.dir < 0; | |
if(flip) flipPart(part); | |
flipPartHooks.design_rotatePart.call(this, part, way); | |
if(flip) flipPart(part); | |
return part | |
}; | |
designMode.draw = function() { | |
const part = this.draggingPart; | |
if(part == null) | |
return flipPartHooks.design_draw.call(this); | |
const flip = part.dir < 0; | |
part.forceFlip = flip; | |
if(flip) flipPart(part); | |
flipPartHooks.design_draw.call(this); | |
if(flip) { | |
if(this.draggingPart2?.flip) | |
this.draggingPart2.dir = -((this.draggingPart2.dir + 3) % 4 + 1); | |
flipPart(part); | |
} | |
} | |
Part.prototype.draw = function() { | |
if(this.forceFlip) flipPart(this); | |
if(this.dir < 0) this.pos[0] *= -1; | |
flipPartHooks.part_draw.call(this); | |
if(this.dir < 0) this.pos[0] *= -1; | |
if(this.forceFlip) flipPart(this); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment