refactor: rename states for clarity and consistency

- Updated state names in constants and related files from WAIT, REACT, TYPE, SLEEP to WAITING, REACTING, TYPING, SLEEPING.
- Adjusted all references to the renamed states across the codebase, including state handlers and transition logic.
- Ensured that logging messages reflect the new state names for better readability.
This commit is contained in:
2025-05-24 04:16:02 +02:00
parent 472de05e4b
commit d513e80c07
12 changed files with 694 additions and 314 deletions

View File

@ -103,7 +103,7 @@ customStates.set("custom", CustomStateHandler);
const owenSystem = await OwenSystemFactory.createCustomOwenSystem(gltfModel, scene, customStates); const owenSystem = await OwenSystemFactory.createCustomOwenSystem(gltfModel, scene, customStates);
// Manual state transitions // Manual state transitions
await owenSystem.transitionTo(States.REACT, Emotions.HAPPY); await owenSystem.transitionTo(States.REACTING, Emotions.HAPPY);
``` ```
## 🎮 Animation Naming Convention ## 🎮 Animation Naming Convention

View File

@ -177,16 +177,16 @@ class OwenDemo {
switch (event.key) { switch (event.key) {
case '1': case '1':
this.owenSystem.transitionTo(States.WAIT) this.owenSystem.transitionTo(States.WAITING)
break break
case '2': case '2':
this.owenSystem.transitionTo(States.REACT) this.owenSystem.transitionTo(States.REACTING)
break break
case '3': case '3':
this.owenSystem.transitionTo(States.TYPE) this.owenSystem.transitionTo(States.TYPING)
break break
case '4': case '4':
this.owenSystem.transitionTo(States.SLEEP) this.owenSystem.transitionTo(States.SLEEPING)
break break
case ' ': case ' ':
this.sendTestMessage() this.sendTestMessage()

View File

@ -92,7 +92,7 @@ class SimpleOwenExample {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async demonstrateStateTransitions () { async demonstrateStateTransitions () {
const states = [States.REACT, States.TYPE, States.WAIT, States.SLEEP] const states = [ States.REACTING, States.TYPING, States.WAITING, States.SLEEPING ]
for (const state of states) { for (const state of states) {
console.log(`🔄 Transitioning to ${state.toUpperCase()} state...`) console.log(`🔄 Transitioning to ${state.toUpperCase()} state...`)

File diff suppressed because it is too large Load Diff

View File

@ -32,13 +32,13 @@ export const ClipTypes = {
*/ */
export const States = { export const States = {
/** Waiting/idle state */ /** Waiting/idle state */
WAIT: 'wait', WAITING: 'wait',
/** Reacting to input state */ /** Reacting to input state */
REACT: 'react', REACTING: 'react',
/** Typing response state */ /** Typing response state */
TYPE: 'type', TYPING: 'type',
/** Sleep/inactive state */ /** Sleep/inactive state */
SLEEP: 'sleep' SLEEPING: 'sleep'
} }
/** /**

View File

@ -59,7 +59,7 @@ export class OwenAnimationContext {
* Current active state * Current active state
* @type {string} * @type {string}
*/ */
this.currentState = States.WAIT this.currentState = States.WAITING
/** /**
* Current active state handler * Current active state handler
@ -105,7 +105,7 @@ export class OwenAnimationContext {
this.initializeStates() this.initializeStates()
// Start in wait state // Start in wait state
await this.transitionTo(States.WAIT) await this.transitionTo(States.WAITING)
this.initialized = true this.initialized = true
console.log('Owen Animation System initialized') console.log('Owen Animation System initialized')
@ -167,8 +167,8 @@ export class OwenAnimationContext {
this.onUserActivity() this.onUserActivity()
// If sleeping, wake up first // If sleeping, wake up first
if (this.currentState === States.SLEEP) { if (this.currentState === States.SLEEPING) {
await this.transitionTo(States.REACT) await this.transitionTo(States.REACTING)
} }
// Let current state handle the message // Let current state handle the message
@ -177,10 +177,10 @@ export class OwenAnimationContext {
} }
// Transition to appropriate next state based on current state // Transition to appropriate next state based on current state
if (this.currentState === States.WAIT) { if (this.currentState === States.WAITING) {
await this.transitionTo(States.REACT) await this.transitionTo(States.REACTING);
} else if (this.currentState === States.REACT) { } else if (this.currentState === States.REACTING) {
await this.transitionTo(States.TYPE) await this.transitionTo(States.TYPING)
} }
} }
@ -192,8 +192,8 @@ export class OwenAnimationContext {
this.resetActivityTimer() this.resetActivityTimer()
// Wake up if sleeping // Wake up if sleeping
if (this.currentState === States.SLEEP) { if (this.currentState === States.SLEEPING) {
this.transitionTo(States.WAIT) this.transitionTo(States.WAITING)
} }
} }
@ -213,7 +213,7 @@ export class OwenAnimationContext {
*/ */
async handleInactivity () { async handleInactivity () {
console.log('Inactivity detected, transitioning to sleep') console.log('Inactivity detected, transitioning to sleep')
await this.transitionTo(States.SLEEP) await this.transitionTo(States.SLEEPING)
} }
/** /**
@ -234,7 +234,7 @@ export class OwenAnimationContext {
// Update inactivity timer // Update inactivity timer
this.inactivityTimer += deltaTime this.inactivityTimer += deltaTime
if (this.inactivityTimer > this.inactivityTimeout && this.currentState !== States.SLEEP) { if (this.inactivityTimer > this.inactivityTimeout && this.currentState !== States.SLEEPING) {
this.handleInactivity() this.handleInactivity()
} }
} }

8
src/index.d.ts vendored
View File

@ -16,10 +16,10 @@ export const ClipTypes: {
}; };
export const States: { export const States: {
readonly WAIT: 'wait'; readonly WAITING: 'wait';
readonly REACT: 'react'; readonly REACTING: 'react';
readonly TYPE: 'type'; readonly TYPING: 'type';
readonly SLEEP: 'sleep'; readonly SLEEPING: 'sleep';
}; };
export const Emotions: { export const Emotions: {

View File

@ -17,7 +17,7 @@ export class ReactStateHandler extends StateHandler {
* @param {OwenAnimationContext} context - The animation context * @param {OwenAnimationContext} context - The animation context
*/ */
constructor (context) { constructor (context) {
super(States.REACT, context) super(States.REACTING, context)
/** /**
* Current emotional state * Current emotional state
@ -33,7 +33,7 @@ export class ReactStateHandler extends StateHandler {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async enter (_fromState = null, emotion = Emotions.NEUTRAL) { async enter (_fromState = null, emotion = Emotions.NEUTRAL) {
console.log(`Entering REACT state with emotion: ${emotion}`) console.log(`Entering REACTING state with emotion: ${emotion}`)
this.emotion = emotion this.emotion = emotion
// Play appropriate reaction // Play appropriate reaction
@ -51,7 +51,7 @@ export class ReactStateHandler extends StateHandler {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async exit (toState = null, emotion = Emotions.NEUTRAL) { async exit (toState = null, emotion = Emotions.NEUTRAL) {
console.log(`Exiting REACT state to ${toState} with emotion: ${emotion}`) console.log(`Exiting REACTING state to ${toState} with emotion: ${emotion}`)
if (this.currentClip) { if (this.currentClip) {
await this.stopCurrentClip() await this.stopCurrentClip()
@ -154,6 +154,6 @@ export class ReactStateHandler extends StateHandler {
* @returns {string[]} Array of available state transitions * @returns {string[]} Array of available state transitions
*/ */
getAvailableTransitions () { getAvailableTransitions () {
return [States.TYPE, States.WAIT] return [ States.TYPING, States.WAITING ]
} }
} }

View File

@ -17,7 +17,7 @@ export class SleepStateHandler extends StateHandler {
* @param {OwenAnimationContext} context - The animation context * @param {OwenAnimationContext} context - The animation context
*/ */
constructor (context) { constructor (context) {
super(States.SLEEP, context) super(States.SLEEPING, context)
/** /**
* Sleep animation clip * Sleep animation clip
@ -39,7 +39,7 @@ export class SleepStateHandler extends StateHandler {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async enter (fromState = null, _emotion = Emotions.NEUTRAL) { async enter (fromState = null, _emotion = Emotions.NEUTRAL) {
console.log(`Entering SLEEP state from ${fromState}`) console.log(`Entering SLEEPING state from ${fromState}`)
// Play sleep transition if available // Play sleep transition if available
const sleepTransition = this.context.getClip('wait_2sleep_T') const sleepTransition = this.context.getClip('wait_2sleep_T')
@ -65,7 +65,7 @@ export class SleepStateHandler extends StateHandler {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async exit (toState = null, _emotion = Emotions.NEUTRAL) { async exit (toState = null, _emotion = Emotions.NEUTRAL) {
console.log(`Exiting SLEEP state to ${toState}`) console.log(`Exiting SLEEPING state to ${toState}`)
this.isDeepSleep = false this.isDeepSleep = false
if (this.currentClip) { if (this.currentClip) {
@ -107,8 +107,8 @@ export class SleepStateHandler extends StateHandler {
// Any message should wake up the character // Any message should wake up the character
if (this.isDeepSleep) { if (this.isDeepSleep) {
console.log('Waking up due to user message') console.log('Waking up due to user message')
// This will trigger a state transition to REACT // This will trigger a state transition to REACTING
await this.context.transitionTo(States.REACT) await this.context.transitionTo(States.REACTING)
} }
} }
@ -117,7 +117,7 @@ export class SleepStateHandler extends StateHandler {
* @returns {string[]} Array of available state transitions * @returns {string[]} Array of available state transitions
*/ */
getAvailableTransitions () { getAvailableTransitions () {
return [States.WAIT, States.REACT] return [ States.WAITING, States.REACTING ]
} }
/** /**
@ -134,7 +134,7 @@ export class SleepStateHandler extends StateHandler {
*/ */
async wakeUp () { async wakeUp () {
if (this.isDeepSleep) { if (this.isDeepSleep) {
await this.context.transitionTo(States.WAIT) await this.context.transitionTo(States.WAITING)
} }
} }
} }

View File

@ -26,10 +26,10 @@ export class StateFactory {
this.stateHandlers = new Map() this.stateHandlers = new Map()
// Register default state handlers // Register default state handlers
this.registerStateHandler(States.WAIT, WaitStateHandler) this.registerStateHandler(States.WAITING, WaitStateHandler);
this.registerStateHandler(States.REACT, ReactStateHandler) this.registerStateHandler(States.REACTING, ReactStateHandler);
this.registerStateHandler(States.TYPE, TypeStateHandler) this.registerStateHandler(States.TYPING, TypeStateHandler);
this.registerStateHandler(States.SLEEP, SleepStateHandler) this.registerStateHandler(States.SLEEPING, SleepStateHandler)
} }
/** /**

View File

@ -17,7 +17,7 @@ export class TypeStateHandler extends StateHandler {
* @param {OwenAnimationContext} context - The animation context * @param {OwenAnimationContext} context - The animation context
*/ */
constructor (context) { constructor (context) {
super(States.TYPE, context) super(States.TYPING, context)
/** /**
* Current emotional state * Current emotional state
@ -39,7 +39,7 @@ export class TypeStateHandler extends StateHandler {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async enter (_fromState = null, emotion = Emotions.NEUTRAL) { async enter (_fromState = null, emotion = Emotions.NEUTRAL) {
console.log(`Entering TYPE state with emotion: ${emotion}`) console.log(`Entering TYPING state with emotion: ${emotion}`)
this.emotion = emotion this.emotion = emotion
this.isTyping = true this.isTyping = true
@ -63,7 +63,7 @@ export class TypeStateHandler extends StateHandler {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async exit (toState = null, _emotion = Emotions.NEUTRAL) { async exit (toState = null, _emotion = Emotions.NEUTRAL) {
console.log(`Exiting TYPE state to ${toState}`) console.log(`Exiting TYPING state to ${toState}`)
this.isTyping = false this.isTyping = false
if (this.currentClip) { if (this.currentClip) {
@ -106,7 +106,7 @@ export class TypeStateHandler extends StateHandler {
* @returns {string[]} Array of available state transitions * @returns {string[]} Array of available state transitions
*/ */
getAvailableTransitions () { getAvailableTransitions () {
return [States.WAIT, States.REACT] return [ States.WAITING, States.REACTING ]
} }
/** /**

View File

@ -17,7 +17,7 @@ export class WaitStateHandler extends StateHandler {
* @param {OwenAnimationContext} context - The animation context * @param {OwenAnimationContext} context - The animation context
*/ */
constructor (context) { constructor (context) {
super(States.WAIT, context) super(States.WAITING, context)
/** /**
* The main idle animation clip * The main idle animation clip
@ -51,7 +51,7 @@ export class WaitStateHandler extends StateHandler {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async enter (fromState = null, _emotion = Emotions.NEUTRAL) { async enter (fromState = null, _emotion = Emotions.NEUTRAL) {
console.log(`Entering WAIT state from ${fromState}`) console.log(`Entering WAITING state from ${fromState}`)
// Play idle loop // Play idle loop
this.idleClip = this.context.getClip('wait_idle_L') this.idleClip = this.context.getClip('wait_idle_L')
@ -72,7 +72,7 @@ export class WaitStateHandler extends StateHandler {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async exit (toState = null, _emotion = Emotions.NEUTRAL) { async exit (toState = null, _emotion = Emotions.NEUTRAL) {
console.log(`Exiting WAIT state to ${toState}`) console.log(`Exiting WAITING state to ${toState}`)
if (this.currentClip) { if (this.currentClip) {
await this.stopCurrentClip() await this.stopCurrentClip()
@ -133,6 +133,6 @@ export class WaitStateHandler extends StateHandler {
* @returns {string[]} Array of available state transitions * @returns {string[]} Array of available state transitions
*/ */
getAvailableTransitions () { getAvailableTransitions () {
return [States.REACT, States.SLEEP] return [ States.REACTING, States.SLEEPING ]
} }
} }