still make it work for logged out users
This commit is contained in:
parent
38c01c4e8f
commit
b2b5090b28
1 changed files with 16 additions and 10 deletions
|
@ -3,6 +3,7 @@ import { last, sortBy, values } from 'lodash'
|
||||||
|
|
||||||
import $jit from '../patched/JIT'
|
import $jit from '../patched/JIT'
|
||||||
|
|
||||||
|
import Active from './Active'
|
||||||
import Create from './Create'
|
import Create from './Create'
|
||||||
import DataModel from './DataModel'
|
import DataModel from './DataModel'
|
||||||
import Mouse from './Mouse'
|
import Mouse from './Mouse'
|
||||||
|
@ -13,20 +14,22 @@ const Engine = {
|
||||||
focusBody: null,
|
focusBody: null,
|
||||||
newNodeConstraint: null,
|
newNodeConstraint: null,
|
||||||
newNodeBody: Bodies.circle(Mouse.newNodeCoords.x, Mouse.newNodeCoords.y, 1),
|
newNodeBody: Bodies.circle(Mouse.newNodeCoords.x, Mouse.newNodeCoords.y, 1),
|
||||||
init: () => {
|
init: (serverData) => {
|
||||||
Engine.engine = Matter.Engine.create()
|
Engine.engine = Matter.Engine.create()
|
||||||
Events.on(Engine.engine, 'afterUpdate', Engine.callUpdate)
|
Events.on(Engine.engine, 'afterUpdate', Engine.callUpdate)
|
||||||
//Engine.engine.world.gravity.scale = 0
|
if (!serverData.ActiveMapper) Engine.engine.world.gravity.scale = 0
|
||||||
Engine.engine.world.gravity.y = 0
|
else {
|
||||||
Engine.engine.world.gravity.x = -1
|
Engine.engine.world.gravity.y = 0
|
||||||
Body.setStatic(Engine.newNodeBody, true)
|
Engine.engine.world.gravity.x = -1
|
||||||
|
Body.setStatic(Engine.newNodeBody, true)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
run: init => {
|
run: init => {
|
||||||
if (init) {
|
if (init) {
|
||||||
World.addBody(Engine.engine.world, Engine.newNodeBody)
|
if (Active.Mapper) World.addBody(Engine.engine.world, Engine.newNodeBody)
|
||||||
Visualize.mGraph.graph.eachNode(Engine.addNode)
|
Visualize.mGraph.graph.eachNode(Engine.addNode)
|
||||||
DataModel.Synapses.each(s => Engine.addEdge(s.get('edge')))
|
DataModel.Synapses.each(s => Engine.addEdge(s.get('edge')))
|
||||||
if (Object.keys(Visualize.mGraph.graph.nodes).length) {
|
if (Active.Mapper && Object.keys(Visualize.mGraph.graph.nodes).length) {
|
||||||
Engine.setFocusNode(Engine.findFocusNode(Visualize.mGraph.graph.nodes))
|
Engine.setFocusNode(Engine.findFocusNode(Visualize.mGraph.graph.nodes))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,6 +68,7 @@ const Engine = {
|
||||||
return last(sortBy(values(nodes), n => new Date(n.getData('topic').get('created_at'))))
|
return last(sortBy(values(nodes), n => new Date(n.getData('topic').get('created_at'))))
|
||||||
},
|
},
|
||||||
setFocusNode: node => {
|
setFocusNode: node => {
|
||||||
|
if (!Active.Mapper) return
|
||||||
Create.newSynapse.focusNode = node
|
Create.newSynapse.focusNode = node
|
||||||
const body = Composite.get(Engine.engine.world, node.getData('body_id'), 'body')
|
const body = Composite.get(Engine.engine.world, node.getData('body_id'), 'body')
|
||||||
Engine.focusBody = body
|
Engine.focusBody = body
|
||||||
|
@ -104,9 +108,11 @@ const Engine = {
|
||||||
const newPos = new $jit.Complex(b.position.x, b.position.y)
|
const newPos = new $jit.Complex(b.position.x, b.position.y)
|
||||||
node && node.setPos(newPos, 'current')
|
node && node.setPos(newPos, 'current')
|
||||||
})
|
})
|
||||||
if (Engine.focusBody) Mouse.focusNodeCoords = Engine.focusBody.position
|
if (Active.Mapper) {
|
||||||
Create.newSynapse.updateForm()
|
if (Engine.focusBody) Mouse.focusNodeCoords = Engine.focusBody.position
|
||||||
Create.newTopic.position()
|
Create.newSynapse.updateForm()
|
||||||
|
Create.newTopic.position()
|
||||||
|
}
|
||||||
Visualize.mGraph.plot()
|
Visualize.mGraph.plot()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue