Fix light bulb errors (also add a dev mode to build script)

This commit is contained in:
prescientmoon 2024-11-28 14:58:57 +01:00
parent fbd05e4dd0
commit d6ba5609e8
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4
8 changed files with 170 additions and 161 deletions

View file

@ -5,15 +5,17 @@ import * as fs from 'fs'
const serve = process.env.ESBUILD_SERVE === '1' const serve = process.env.ESBUILD_SERVE === '1'
const baseurl = process.env.ESBUILD_BASEURL || '' const baseurl = process.env.ESBUILD_BASEURL || ''
const nodeEnv = process.env.NODE_ENV
const isProd = nodeEnv !== 'development'
console.log(`Building with baseurl ${baseurl}`) console.log(`Building with baseurl ${baseurl}`)
const ctx = await esbuild.context({ const ctx = await esbuild.context({
entryPoints: ['src/index.ts'], entryPoints: ['src/index.ts'],
minify: true, minify: isProd,
bundle: true, bundle: true,
metafile: true, metafile: true,
splitting: true, splitting: isProd,
outdir: 'dist', outdir: 'dist',
format: 'esm', format: 'esm',
target: ['es2020'], target: ['es2020'],
@ -23,7 +25,8 @@ const ctx = await esbuild.context({
'.svg': 'file' '.svg': 'file'
}, },
define: { define: {
'process.env.BASEURL': JSON.stringify(baseurl) 'process.env.BASEURL': JSON.stringify(baseurl),
'process.env.NODE_ENV': JSON.stringify(nodeEnv)
}, },
plugins: [ plugins: [
htmlPlugin({ htmlPlugin({

View file

@ -3,7 +3,7 @@
"version": "1.0.0", "version": "1.0.0",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "ESBUILD_SERVE=1 node ./build.js", "dev": "NODE_ENV=development ESBUILD_SERVE=1 node ./build.js",
"build": "node ./build.js", "build": "node ./build.js",
"check": "tsc" "check": "tsc"
}, },

View file

@ -33,7 +33,11 @@ async function main() {
} }
} }
new EventSource('/esbuild').addEventListener('change', () => location.reload()) if (process.env.BASEURL === 'development') {
new EventSource('/esbuild').addEventListener('change', () =>
location.reload()
)
}
// Call entry // Call entry
main().catch((error) => { main().catch((error) => {

View file

@ -24,7 +24,7 @@ export class ExecutionQueue<T> {
private current: Promise<T> | null private current: Promise<T> | null
/** /**
* Wheather the tasks should continue beeing executed * Whether the tasks should continue being executed
*/ */
public active = true public active = true
@ -58,7 +58,7 @@ export class ExecutionQueue<T> {
if (task) { if (task) {
this.current = task.execute() this.current = task.execute()
this.current.then(result => { this.current.then((result) => {
task.output.next(result) task.output.next(result)
if (this.active) { if (this.active) {

View file

@ -24,7 +24,7 @@ const lightTemplate: PartialTemplate = {
activation: ` activation: `
const { main, active } = context.colors const { main, active } = context.colors
context.color(context.getBinary(2) ? active : main) context.color(context.getBinary(0) ? active : main)
` `
}, },
integration: { integration: {

View file

@ -295,8 +295,9 @@ export class Gate {
props: Property[] = this.template.properties.data, props: Property[] = this.template.properties.data,
target: GateProps = this.props, target: GateProps = this.props,
path: string[] = [] path: string[] = []
) { ): boolean {
// We don't want to update until every prop has been created // We don't want to update until every prop has been created
let shouldUpdate = false
let lockUpdates = true let lockUpdates = true
if (this.template.properties.enabled) { if (this.template.properties.enabled) {
@ -304,7 +305,7 @@ export class Gate {
if (isGroup(prop)) { if (isGroup(prop)) {
const { groupName } = prop const { groupName } = prop
target[groupName] = {} as GateProps target[groupName] = {} as GateProps
this.assignProps( shouldUpdate ||= this.assignProps(
typeof source[groupName] === 'object' typeof source[groupName] === 'object'
? (source[groupName] as PropsSave) ? (source[groupName] as PropsSave)
: {}, : {},
@ -312,11 +313,9 @@ export class Gate {
target[groupName] as GateProps, target[groupName] as GateProps,
[...path, groupName] [...path, groupName]
) )
} else {
continue
}
const { name, base, needsUpdate } = prop const { name, base, needsUpdate } = prop
shouldUpdate ||= needsUpdate || false
const subject = new BehaviorSubject( const subject = new BehaviorSubject(
source.hasOwnProperty(name) ? source[name] : base source.hasOwnProperty(name) ? source[name] : base
@ -339,9 +338,13 @@ export class Gate {
) )
} }
} }
}
lockUpdates = false lockUpdates = false
this.update()
if (path.length === 0 && shouldUpdate) this.update()
return shouldUpdate
} }
/** /**

View file

@ -1,6 +1,5 @@
import { GateTemplate, Property, RawProp } from './types/GateTemplate' import { GateTemplate, RawProp } from './types/GateTemplate'
import { categories } from '../saving/data/categories' import { categories } from '../saving/data/categories'
import { getRendererSafely } from '../logic-gates/helpers/getRendererSafely'
export const DefaultGateTemplate: GateTemplate = { export const DefaultGateTemplate: GateTemplate = {
metadata: { metadata: {