mirror of
https://github.com/teoxoy/factorio-blueprint-editor.git
synced 2025-01-16 02:33:23 +02:00
improved export of blueprint picture
This commit is contained in:
parent
da02d53c45
commit
83ee66a3bb
11
package-lock.json
generated
11
package-lock.json
generated
@ -34,6 +34,12 @@
|
||||
"commander": "*"
|
||||
}
|
||||
},
|
||||
"@types/file-saver": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/file-saver/-/file-saver-1.3.0.tgz",
|
||||
"integrity": "sha512-fC12hKtEzVkrV/ZRcrmqvpHG/TMYDZtgpAmgMUA4F7KneDaQeFMwmPz8AfygKKJMqsdTi8bL+E+fciaaMLxUhg==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/keyboardjs": {
|
||||
"version": "2.2.31",
|
||||
"resolved": "https://registry.npmjs.org/@types/keyboardjs/-/keyboardjs-2.2.31.tgz",
|
||||
@ -2782,6 +2788,11 @@
|
||||
"integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=",
|
||||
"dev": true
|
||||
},
|
||||
"file-saver": {
|
||||
"version": "1.3.8",
|
||||
"resolved": "https://registry.npmjs.org/file-saver/-/file-saver-1.3.8.tgz",
|
||||
"integrity": "sha512-spKHSBQIxxS81N/O21WmuXA2F6wppUCsutpzenOeZzOCCJ5gEfcbqJP983IrpLXzYmXnMUa6J03SubcNPdKrlg=="
|
||||
},
|
||||
"filename-regex": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/filename-regex/-/filename-regex-2.0.1.tgz",
|
||||
|
@ -22,6 +22,7 @@
|
||||
"@pixi/filter-adjustment": "^2.5.0",
|
||||
"ajv": "^6.5.2",
|
||||
"factorio-data": "git+https://github.com/Teoxoy/factorio-data.git",
|
||||
"file-saver": "^1.3.8",
|
||||
"gown": "^0.1.6",
|
||||
"immutable": "^4.0.0-rc.10",
|
||||
"keyboardjs": "^2.4.1",
|
||||
@ -30,6 +31,7 @@
|
||||
"pixi.js": "^4.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/file-saver": "^1.3.0",
|
||||
"@types/keyboardjs": "^2.2.31",
|
||||
"@types/pako": "^1.0.0",
|
||||
"@types/pixi.js": "^4.8.0",
|
||||
|
28
src/app.ts
28
src/app.ts
@ -26,6 +26,7 @@ import { ToolbarContainer } from './containers/toolbar'
|
||||
import { Blueprint } from './factorio-data/blueprint'
|
||||
import { EditEntityContainer } from './containers/editEntity'
|
||||
import { InfoContainer } from './containers/info'
|
||||
import FileSaver from 'file-saver'
|
||||
|
||||
let doorbellButton: HTMLElement
|
||||
window.doorbellOptions = {
|
||||
@ -212,6 +213,7 @@ function loadBp(bpString: string, clearData = true) {
|
||||
|
||||
document.addEventListener('copy', (e: ClipboardEvent) => {
|
||||
e.preventDefault()
|
||||
if (G.bp.isEmpty()) return
|
||||
|
||||
BPString.encode(G.bp)
|
||||
.then(data => {
|
||||
@ -246,19 +248,21 @@ keyboardJS.bind(keybinds.clear, () => {
|
||||
})
|
||||
|
||||
keyboardJS.bind(keybinds.picture, () => {
|
||||
G.BPC.centerViewport()
|
||||
if (G.renderOnly) G.BPC.cacheAsBitmap = false
|
||||
const t = G.app.renderer.generateTexture(G.BPC)
|
||||
if (G.renderOnly) G.BPC.cacheAsBitmap = true
|
||||
t.frame = G.BPC.entitySprites.getLocalBounds()
|
||||
t._updateUvs()
|
||||
const s = new PIXI.Sprite(t)
|
||||
const image = G.app.renderer.plugins.extract.image(s)
|
||||
const w = window.open()
|
||||
w.focus()
|
||||
w.document.write(image.outerHTML)
|
||||
if (G.bp.isEmpty()) return
|
||||
|
||||
console.log('Saved BP Image')
|
||||
G.BPC.enableRenderableOnChildren()
|
||||
if (G.renderOnly) G.BPC.cacheAsBitmap = false
|
||||
const texture = G.app.renderer.generateTexture(G.BPC)
|
||||
if (G.renderOnly) G.BPC.cacheAsBitmap = true
|
||||
G.BPC.updateViewportCulling()
|
||||
|
||||
texture.frame = G.BPC.getEntitySpritesBounds()
|
||||
texture._updateUvs()
|
||||
|
||||
G.app.renderer.plugins.extract.canvas(new PIXI.Sprite(texture)).toBlob((blob: Blob) => {
|
||||
FileSaver.saveAs(blob, G.bp.name)
|
||||
console.log('Saved BP Image')
|
||||
})
|
||||
})
|
||||
|
||||
keyboardJS.bind('shift', () => G.keyboard.shift = true, () => G.keyboard.shift = false)
|
||||
|
@ -258,6 +258,26 @@ export class BlueprintContainer extends PIXI.Container {
|
||||
this.updateViewportCulling()
|
||||
}
|
||||
|
||||
getEntitySpritesBounds() {
|
||||
const bounds = new PIXI.Bounds()
|
||||
for (const sprite of this.entitySprites.children as PIXI.Sprite[]) {
|
||||
const sB = new PIXI.Bounds()
|
||||
const W = sprite.width * sprite.anchor.x
|
||||
const H = sprite.height * sprite.anchor.y
|
||||
sB.minX = sprite.x - W
|
||||
sB.minY = sprite.y - H
|
||||
sB.maxX = sprite.x + W
|
||||
sB.maxY = sprite.y + H
|
||||
bounds.addBounds(sB)
|
||||
}
|
||||
return bounds.getRectangle()
|
||||
}
|
||||
|
||||
enableRenderableOnChildren() {
|
||||
this.entitySprites.children.forEach(c => c.renderable = true)
|
||||
this.overlayContainer.overlay.children.forEach(c => c.renderable = true)
|
||||
}
|
||||
|
||||
updateViewportCulling() {
|
||||
cullChildren(this.entitySprites.children)
|
||||
cullChildren(this.overlayContainer.overlay.children)
|
||||
|
@ -335,6 +335,10 @@ export class Blueprint {
|
||||
return this
|
||||
}
|
||||
|
||||
isEmpty() {
|
||||
return this.rawEntities.isEmpty() && this.tiles.length === 0
|
||||
}
|
||||
|
||||
// Get corner/center positions
|
||||
getPosition(f: string, xcomp: any, ycomp: any) {
|
||||
if (!this.rawEntities.size) return { x: 0, y: 0 }
|
||||
|
Loading…
Reference in New Issue
Block a user