-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.ts
68 lines (59 loc) · 1.89 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import * as Sentry from "@sentry/browser"
import { Automaton } from "./core/Automaton"
import { Controls } from "./ui/controls"
import { getAlgorithmFromRoute } from "./utils/getAlgorithmFromRoute"
// Initialize Sentry before any other code
Sentry.init({
dsn: import.meta.env.VITE_SENTRY_DSN,
environment: import.meta.env.VITE_ENVIRONMENT,
release: APP_VERSION,
integrations: [
Sentry.browserTracingIntegration(),
Sentry.replayIntegration(),
],
// Tracing
tracesSampleRate: 1.0, // Capture 100% of the transactions
// Session Replay
replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
})
let controls: Controls
let automaton: Automaton
const reset = async (): Promise<void> => {
// Cleanup existing automaton
Automaton.cleanup(automaton)
automaton = undefined
// Get canvas and dimensions
const canvasEl = document.getElementById("canvas") as HTMLCanvasElement
const width = window.innerWidth
const height = window.innerHeight
// Create new automaton
automaton = await Automaton.create(
canvasEl,
width,
height,
controls.getSettings(),
)
// Update automaton reference in Controls
controls.setAutomaton(automaton)
}
window.onload = async () => {
const canvasEl = document.getElementById("canvas") as HTMLCanvasElement
const initialAlgo = getAlgorithmFromRoute()
// Create automaton with all needed settings
automaton = await Automaton.create(
canvasEl,
window.innerWidth,
window.innerHeight,
{
algo: initialAlgo,
cca2dColorsCount: 8,
cca2dThreshold: 2, // Add default threshold
resolution: 5,
},
)
controls = new Controls(automaton, reset)
}
window.onresize = (): void => {
void reset()
}