Newer
Older
</div>
</template>
<script>
import { mapState } from 'vuex'
import * as PIXI from 'pixi.js'
//var id
var fromnode
var tonode
var xposstart
var yposstart
var xposend
var yposend
var endState = false
configPositions: (state) => state.configPositions,
myNodes: (state) => state.myNodes,
otherNodes: (state) => state.otherNodes,
toolmode: (state) => state.ui.mode,
watch: {
configConnections: {
deep: true,
handler() {
toolmode: {
handler() {
this.toolState()
},
},
makeConnection(id, xpos, ypos) {
if (endState == false) {
fromnode = id
xposstart = xpos
yposstart = ypos
endState = true
//count = 1
// this.$store.dispatch('connectionState', true)
} else if (endState == true) {
tonode = id
xposend = xpos
yposend = ypos
// count = 0
// this.$store.dispatch('connectionState', false)
// console.log(fromnode, tonode, xposstart, yposstart, xposend, yposend)
this.$store.dispatch('makeConnect', {
fromnode,
tonode,
xposstart,
yposstart,
xposend,
yposend,
})
}
this.canvas = this.$refs.pixi
const stage = this.PIXIApp.stage
buttonMap[i] = new PIXI.Graphics()
// console.log(buttonMap[i])
for (j = 0; j < Object.keys(this.configPositions).length; j++) {
if (this.configPositions[j].node_id == this.myNodes[i].node_id) {
buttonMap[i].name = this.myNodes[i].node_id
// console.log(button_one.name)
buttonMap[i].lineStyle(0)
buttonMap[i].beginFill(0xcab6ff, 1)
this.configPositions[j].x_pos + this.configPositions[j].width,
this.configPositions[j].y_pos +
this.configPositions[j].height / 2,
15
)
stage.addChild(buttonMap[i])
// Opt-in to interactivity
buttonMap[i].interactive = true
// Shows hand cursor
buttonMap[i].buttonMode = true
buttonMap[i]
.on('pointerdown', onDragStart)
.on('pointerdown', start)
.on('pointerup', onDragEnd)
.on('pointerup', finish)
for (i = 0; i < Object.keys(this.otherNodes).length; i++) {
buttonMapOther[i] = new PIXI.Graphics()
// console.log(buttonMap[i])
for (j = 0; j < Object.keys(this.configPositions).length; j++) {
if (this.configPositions[j].node_id == this.otherNodes[i].node_id) {
buttonMapOther[i].name = this.otherNodes[i].node_id
// console.log(button_one.name)
buttonMapOther[i].lineStyle(0)
buttonMapOther[i].beginFill(0xcab6ff, 1)
// x, y, radius
buttonMapOther[i].drawCircle(
this.configPositions[j].x_pos + this.configPositions[j].width,
this.configPositions[j].y_pos +
this.configPositions[j].height / 2,
15
)
buttonMapOther[i].endFill()
// names it the last one only?
}
stage.addChild(buttonMapOther[i])
// Opt-in to interactivity
buttonMapOther[i].interactive = true
// Shows hand cursor
buttonMapOther[i].buttonMode = true
}
buttonMapOther[i]
.on('pointerdown', onDragStart)
.on('pointerdown', start)
.on('pointerup', finish)
.on('pointerup', onDragEnd)
.on('pointerupoutside', onDragEndOutside)
var initialMoveTo
let lines = []
this.id = this.name
ref.makeConnection(this.id, event.data.global.x, event.data.global.y)
}
function finish(event) {
this.id = this.name
ref.makeConnection(this.id, event.data.global.x, event.data.global.y)
function onDragStart(event) {
this.dragging = true
let mouseX = event.data.global.x
let mouseY = event.data.global.y
initialMoveTo = [mouseX, mouseY]
line.lineStyle(8, 0xcab6ff)
line.moveTo(mouseX, mouseY)
lines = [line].concat(lines)
stage.addChild(line)
}
function onDragEnd() {
//console.log('end')
this.dragging = false
stage.removeChild(line)
}
function onDragEndOutside() {
// console.log('Outside')
endState = false
this.dragging = false
stage.removeChild(line)
}
function onDragMove(event) {
if (this.dragging) {
let mouseX = event.data.global.x
let mouseY = event.data.global.y
lines[0].clear()
lines[0].lineStyle(8, 0xcab6ff)
lines[0].moveTo(initialMoveTo[0], initialMoveTo[1])
lines[0].lineTo(mouseX, mouseY)
}
}
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
connectionsDraw() {
var i
this.canvas = this.$refs.pixi
const stage = this.PIXIApp.stage
let graphics = new PIXI.Graphics()
//let line = new PIXI.Graphics()
graphics.lineStyle(8, 0xcab6ff)
// move the lines to start and end pos based on if to_node == node_id
// or from_id == node_id
// this will put them in the same place as buttons
for (i = 0; i < Object.keys(this.configConnections).length; i++) {
//start
graphics.moveTo(
this.configConnections[i].x_pos_start,
this.configConnections[i].y_pos_start
)
//end
graphics.lineTo(
this.configConnections[i].x_pos_end,
this.configConnections[i].y_pos_end
)
}
for (var l = stage.children.length - 1; l >= 0; l--) {
stage.removeChild(stage.children[l])
}
stage.addChild(graphics)
if (this.toolmode == 'connect') {
this.buttonsDraw()
}
const canvas = this.$refs.pixi
this.PIXIApp = new PIXI.Application({
width: window.innerWidth,
height: window.innerHeight,
antialias: true,
transparent: true,
view: canvas,
})