Fix scrolling on github pages not working
This commit is contained in:
parent
d6200cffef
commit
4afe680833
|
@ -9,8 +9,8 @@ import { SelectedPins } from '../types/SelectedPins'
|
||||||
import { currentStore } from '../../saving/stores/currentStore'
|
import { currentStore } from '../../saving/stores/currentStore'
|
||||||
import { saveStore } from '../../saving/stores/saveStore'
|
import { saveStore } from '../../saving/stores/saveStore'
|
||||||
import {
|
import {
|
||||||
fromSimulationState,
|
fromSimulationState,
|
||||||
fromCameraState
|
fromCameraState
|
||||||
} from '../../saving/helpers/fromState'
|
} from '../../saving/helpers/fromState'
|
||||||
import merge from 'deepmerge'
|
import merge from 'deepmerge'
|
||||||
import { handleScroll } from '../helpers/scaleCanvas'
|
import { handleScroll } from '../helpers/scaleCanvas'
|
||||||
|
@ -29,134 +29,132 @@ import { handleMouseMove } from '../helpers/handleMouseMove'
|
||||||
import { Gate } from '../../simulation/classes/Gate'
|
import { Gate } from '../../simulation/classes/Gate'
|
||||||
|
|
||||||
export class SimulationRenderer {
|
export class SimulationRenderer {
|
||||||
public mouseDownOutput = new Subject<MouseEventInfo>()
|
public mouseDownOutput = new Subject<MouseEventInfo>()
|
||||||
public mouseUpOutput = new Subject<MouseEventInfo>()
|
public mouseUpOutput = new Subject<MouseEventInfo>()
|
||||||
public mouseMoveOutput = new Subject<MouseEventInfo>()
|
public mouseMoveOutput = new Subject<MouseEventInfo>()
|
||||||
public wheelOutput = new Subject<unknown>()
|
public wheelOutput = new Subject<unknown>()
|
||||||
|
|
||||||
public selectedGates: Record<selectionType, Set<number>> = {
|
public selectedGates: Record<selectionType, Set<number>> = {
|
||||||
temporary: new Set<number>(),
|
temporary: new Set<number>(),
|
||||||
permanent: new Set<number>()
|
permanent: new Set<number>()
|
||||||
}
|
}
|
||||||
|
|
||||||
public options: SimulationRendererOptions
|
public options: SimulationRendererOptions
|
||||||
public camera = new Camera()
|
public camera = new Camera()
|
||||||
|
|
||||||
public selectedArea = new Transform()
|
public selectedArea = new Transform()
|
||||||
public clipboard: GateInitter[] = []
|
public clipboard: GateInitter[] = []
|
||||||
public wireClipboard: WireState[] = []
|
public wireClipboard: WireState[] = []
|
||||||
|
|
||||||
// first bit = dragging
|
// first bit = dragging
|
||||||
// second bit = panning
|
// second bit = panning
|
||||||
// third bit = selecting
|
// third bit = selecting
|
||||||
public mouseState = 0b000
|
public mouseState = 0b000
|
||||||
|
|
||||||
public lastMousePosition: vector2 = [0, 0]
|
public lastMousePosition: vector2 = [0, 0]
|
||||||
|
|
||||||
// this is used for spawning gates
|
// this is used for spawning gates
|
||||||
public spawnCount = 0
|
public spawnCount = 0
|
||||||
|
|
||||||
public selectedPins: SelectedPins = {
|
public selectedPins: SelectedPins = {
|
||||||
start: null,
|
start: null,
|
||||||
end: null
|
end: null
|
||||||
}
|
}
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
options: Partial<SimulationRendererOptions> = {},
|
options: Partial<SimulationRendererOptions> = {},
|
||||||
public simulation = new Simulation('project', 'default')
|
public simulation = new Simulation('project', 'default')
|
||||||
) {
|
) {
|
||||||
this.options = merge(defaultSimulationRendererOptions, options)
|
this.options = merge(defaultSimulationRendererOptions, options)
|
||||||
|
|
||||||
this.init()
|
this.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
this.mouseDownOutput.subscribe(handleMouseDown(this))
|
this.mouseDownOutput.subscribe(handleMouseDown(this))
|
||||||
this.mouseUpOutput.subscribe(handleMouseUp(this))
|
this.mouseUpOutput.subscribe(handleMouseUp(this))
|
||||||
this.mouseMoveOutput.subscribe(handleMouseMove(this))
|
this.mouseMoveOutput.subscribe(handleMouseMove(this))
|
||||||
|
|
||||||
this.reloadSave()
|
this.reloadSave()
|
||||||
}
|
}
|
||||||
|
|
||||||
public updateWheelListener(ref: RefObject<HTMLCanvasElement>) {
|
public updateWheelListener(ref: RefObject<HTMLCanvasElement>) {
|
||||||
if (ref.current) {
|
if (ref.current) {
|
||||||
ref.current.addEventListener('wheel', (event) => {
|
ref.current.addEventListener('wheel', (event) => {
|
||||||
if (!modalIsOpen() && location.pathname === '/') {
|
if (!modalIsOpen() && location.pathname === process.env.BASEURL) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
|
||||||
handleScroll(event, this.camera)
|
handleScroll(event, this.camera)
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a simulation state
|
* Loads a simulation state
|
||||||
*
|
*
|
||||||
* @param save LThe state to load
|
* @param save LThe state to load
|
||||||
*/
|
*/
|
||||||
public loadSave(save: RendererState) {
|
public loadSave(save: RendererState) {
|
||||||
this.simulation = fromSimulationState(save.simulation)
|
this.simulation = fromSimulationState(save.simulation)
|
||||||
this.camera = fromCameraState(save.camera)
|
this.camera = fromCameraState(save.camera)
|
||||||
}
|
}
|
||||||
|
|
||||||
public reloadSave() {
|
public reloadSave() {
|
||||||
dumpSimulation(this)
|
dumpSimulation(this)
|
||||||
|
|
||||||
const current = currentStore.get()
|
const current = currentStore.get()
|
||||||
const save = saveStore.get(current)
|
const save = saveStore.get(current)
|
||||||
|
|
||||||
if (!save) return
|
if (!save) return
|
||||||
if (!(save.simulation || save.camera)) return
|
if (!(save.simulation || save.camera)) return
|
||||||
|
|
||||||
this.loadSave(save)
|
this.loadSave(save)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all selected gates in the simulation
|
* Gets all selected gates in the simulation
|
||||||
*
|
*
|
||||||
* @throws SimulationError if an id isnt valid
|
* @throws SimulationError if an id isnt valid
|
||||||
* @throws SimulationError if the id doesnt have a data prop
|
* @throws SimulationError if the id doesnt have a data prop
|
||||||
*/
|
*/
|
||||||
public getSelected(): Gate[] {
|
public getSelected(): Gate[] {
|
||||||
return setToArray(this.allSelectedIds()).map((id) => {
|
return setToArray(this.allSelectedIds()).map((id) => {
|
||||||
const gate = this.simulation.gates.get(id)
|
const gate = this.simulation.gates.get(id)
|
||||||
|
|
||||||
if (!gate) {
|
if (!gate) {
|
||||||
throw new SimulationError(`Cannot find gate with id ${id}`)
|
throw new SimulationError(`Cannot find gate with id ${id}`)
|
||||||
} else if (!gate.data) {
|
} else if (!gate.data) {
|
||||||
throw new SimulationError(
|
throw new SimulationError(`Cannot find data of gate with id ${id}`)
|
||||||
`Cannot find data of gate with id ${id}`
|
}
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return gate.data
|
return gate.data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* helper to merge the temporary and permanent selection
|
* helper to merge the temporary and permanent selection
|
||||||
*/
|
*/
|
||||||
public allSelectedIds() {
|
public allSelectedIds() {
|
||||||
return new Set([
|
return new Set([
|
||||||
...setToArray(this.selectedGates.permanent),
|
...setToArray(this.selectedGates.permanent),
|
||||||
...setToArray(this.selectedGates.temporary)
|
...setToArray(this.selectedGates.temporary)
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to clear all selected sets
|
* Helper to clear all selected sets
|
||||||
*/
|
*/
|
||||||
public clearSelection() {
|
public clearSelection() {
|
||||||
this.selectedGates.permanent.clear()
|
this.selectedGates.permanent.clear()
|
||||||
this.selectedGates.temporary.clear()
|
this.selectedGates.temporary.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the selected pins of the renderer
|
* Clears the selected pins of the renderer
|
||||||
*/
|
*/
|
||||||
public clearPinSelection() {
|
public clearPinSelection() {
|
||||||
this.selectedPins.end = null
|
this.selectedPins.end = null
|
||||||
this.selectedPins.start = null
|
this.selectedPins.start = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue