default value
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
|||||||
useScene,
|
useScene,
|
||||||
} from '@pascal-app/core'
|
} from '@pascal-app/core'
|
||||||
import { ChevronDown, ChevronRight } from 'lucide-react'
|
import { ChevronDown, ChevronRight } from 'lucide-react'
|
||||||
import { useState } from 'react'
|
import { useMemo, useState } from 'react'
|
||||||
import { useShallow } from 'zustand/react/shallow'
|
import { useShallow } from 'zustand/react/shallow'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
|
|
||||||
@@ -145,10 +145,10 @@ function CollectionRow({ collectionId }: { collectionId: CollectionId }) {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
const controlValuesByItem = useInteractive(
|
const allItems = useInteractive((s) => s.items)
|
||||||
useShallow((s) =>
|
const controlValuesByItem = useMemo(
|
||||||
Object.fromEntries(interactiveItems.map((n) => [n.id, s.items[n.id]?.controlValues ?? []])),
|
() => Object.fromEntries(interactiveItems.map((n) => [n.id, allItems[n.id]?.controlValues ?? []])),
|
||||||
),
|
[allItems, interactiveItems],
|
||||||
)
|
)
|
||||||
|
|
||||||
const setControlValue = useInteractive((s) => s.setControlValue)
|
const setControlValue = useInteractive((s) => s.setControlValue)
|
||||||
|
|||||||
@@ -1235,7 +1235,8 @@ export const CATALOG_ITEMS: AssetInput[] = [
|
|||||||
kind: 'toggle',
|
kind: 'toggle',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
kind: 'slider', label: 'Intensity', min: 0, max: 100, unit: '%', displayMode: 'dial'
|
kind: 'slider', label: 'Intensity', min: 0, max: 100, unit: '%', displayMode: 'dial',
|
||||||
|
default: 100
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
effects: [
|
effects: [
|
||||||
@@ -1266,7 +1267,8 @@ export const CATALOG_ITEMS: AssetInput[] = [
|
|||||||
kind: 'toggle',
|
kind: 'toggle',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
kind: 'slider', label: 'Intensity', min: 0, max: 100, unit: '%', displayMode: 'dial'
|
kind: 'slider', label: 'Intensity', min: 0, max: 100, unit: '%', displayMode: 'dial' ,
|
||||||
|
default: 100
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
effects: [
|
effects: [
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import type { CollectionId } from '../collections'
|
|||||||
const toggleControlSchema = z.object({
|
const toggleControlSchema = z.object({
|
||||||
kind: z.literal('toggle'),
|
kind: z.literal('toggle'),
|
||||||
label: z.string().optional(),
|
label: z.string().optional(),
|
||||||
|
default: z.boolean().optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
const sliderControlSchema = z.object({
|
const sliderControlSchema = z.object({
|
||||||
@@ -18,6 +19,7 @@ const sliderControlSchema = z.object({
|
|||||||
step: z.number().default(1),
|
step: z.number().default(1),
|
||||||
unit: z.string().optional(),
|
unit: z.string().optional(),
|
||||||
displayMode: z.enum(['slider', 'stepper', 'dial']).default('slider'),
|
displayMode: z.enum(['slider', 'stepper', 'dial']).default('slider'),
|
||||||
|
default: z.number().optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
const temperatureControlSchema = z.object({
|
const temperatureControlSchema = z.object({
|
||||||
@@ -26,6 +28,7 @@ const temperatureControlSchema = z.object({
|
|||||||
min: z.number().default(16),
|
min: z.number().default(16),
|
||||||
max: z.number().default(30),
|
max: z.number().default(30),
|
||||||
unit: z.enum(['C', 'F']).default('C'),
|
unit: z.enum(['C', 'F']).default('C'),
|
||||||
|
default: z.number().optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
const controlSchema = z.discriminatedUnion('kind', [
|
const controlSchema = z.discriminatedUnion('kind', [
|
||||||
|
|||||||
@@ -30,11 +30,11 @@ const defaultControlValue = (interactive: Interactive, index: number): ControlVa
|
|||||||
if (!control) return false
|
if (!control) return false
|
||||||
switch (control.kind) {
|
switch (control.kind) {
|
||||||
case 'toggle':
|
case 'toggle':
|
||||||
return false
|
return control.default ?? false
|
||||||
case 'slider':
|
case 'slider':
|
||||||
return control.min
|
return control.default ?? control.min
|
||||||
case 'temperature':
|
case 'temperature':
|
||||||
return control.min
|
return control.default ?? control.min
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user