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:
@ -103,7 +103,7 @@ customStates.set("custom", CustomStateHandler);
|
||||
const owenSystem = await OwenSystemFactory.createCustomOwenSystem(gltfModel, scene, customStates);
|
||||
|
||||
// Manual state transitions
|
||||
await owenSystem.transitionTo(States.REACT, Emotions.HAPPY);
|
||||
await owenSystem.transitionTo(States.REACTING, Emotions.HAPPY);
|
||||
```
|
||||
|
||||
## 🎮 Animation Naming Convention
|
||||
|
||||
@ -177,16 +177,16 @@ class OwenDemo {
|
||||
|
||||
switch (event.key) {
|
||||
case '1':
|
||||
this.owenSystem.transitionTo(States.WAIT)
|
||||
this.owenSystem.transitionTo(States.WAITING)
|
||||
break
|
||||
case '2':
|
||||
this.owenSystem.transitionTo(States.REACT)
|
||||
this.owenSystem.transitionTo(States.REACTING)
|
||||
break
|
||||
case '3':
|
||||
this.owenSystem.transitionTo(States.TYPE)
|
||||
this.owenSystem.transitionTo(States.TYPING)
|
||||
break
|
||||
case '4':
|
||||
this.owenSystem.transitionTo(States.SLEEP)
|
||||
this.owenSystem.transitionTo(States.SLEEPING)
|
||||
break
|
||||
case ' ':
|
||||
this.sendTestMessage()
|
||||
|
||||
@ -92,7 +92,7 @@ class SimpleOwenExample {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
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) {
|
||||
console.log(`🔄 Transitioning to ${state.toUpperCase()} state...`)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -32,13 +32,13 @@ export const ClipTypes = {
|
||||
*/
|
||||
export const States = {
|
||||
/** Waiting/idle state */
|
||||
WAIT: 'wait',
|
||||
WAITING: 'wait',
|
||||
/** Reacting to input state */
|
||||
REACT: 'react',
|
||||
REACTING: 'react',
|
||||
/** Typing response state */
|
||||
TYPE: 'type',
|
||||
TYPING: 'type',
|
||||
/** Sleep/inactive state */
|
||||
SLEEP: 'sleep'
|
||||
SLEEPING: 'sleep'
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -59,7 +59,7 @@ export class OwenAnimationContext {
|
||||
* Current active state
|
||||
* @type {string}
|
||||
*/
|
||||
this.currentState = States.WAIT
|
||||
this.currentState = States.WAITING
|
||||
|
||||
/**
|
||||
* Current active state handler
|
||||
@ -105,7 +105,7 @@ export class OwenAnimationContext {
|
||||
this.initializeStates()
|
||||
|
||||
// Start in wait state
|
||||
await this.transitionTo(States.WAIT)
|
||||
await this.transitionTo(States.WAITING)
|
||||
|
||||
this.initialized = true
|
||||
console.log('Owen Animation System initialized')
|
||||
@ -167,8 +167,8 @@ export class OwenAnimationContext {
|
||||
this.onUserActivity()
|
||||
|
||||
// If sleeping, wake up first
|
||||
if (this.currentState === States.SLEEP) {
|
||||
await this.transitionTo(States.REACT)
|
||||
if (this.currentState === States.SLEEPING) {
|
||||
await this.transitionTo(States.REACTING)
|
||||
}
|
||||
|
||||
// Let current state handle the message
|
||||
@ -177,10 +177,10 @@ export class OwenAnimationContext {
|
||||
}
|
||||
|
||||
// Transition to appropriate next state based on current state
|
||||
if (this.currentState === States.WAIT) {
|
||||
await this.transitionTo(States.REACT)
|
||||
} else if (this.currentState === States.REACT) {
|
||||
await this.transitionTo(States.TYPE)
|
||||
if (this.currentState === States.WAITING) {
|
||||
await this.transitionTo(States.REACTING);
|
||||
} else if (this.currentState === States.REACTING) {
|
||||
await this.transitionTo(States.TYPING)
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,8 +192,8 @@ export class OwenAnimationContext {
|
||||
this.resetActivityTimer()
|
||||
|
||||
// Wake up if sleeping
|
||||
if (this.currentState === States.SLEEP) {
|
||||
this.transitionTo(States.WAIT)
|
||||
if (this.currentState === States.SLEEPING) {
|
||||
this.transitionTo(States.WAITING)
|
||||
}
|
||||
}
|
||||
|
||||
@ -213,7 +213,7 @@ export class OwenAnimationContext {
|
||||
*/
|
||||
async handleInactivity () {
|
||||
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
|
||||
this.inactivityTimer += deltaTime
|
||||
if (this.inactivityTimer > this.inactivityTimeout && this.currentState !== States.SLEEP) {
|
||||
if (this.inactivityTimer > this.inactivityTimeout && this.currentState !== States.SLEEPING) {
|
||||
this.handleInactivity()
|
||||
}
|
||||
}
|
||||
|
||||
8
src/index.d.ts
vendored
8
src/index.d.ts
vendored
@ -16,10 +16,10 @@ export const ClipTypes: {
|
||||
};
|
||||
|
||||
export const States: {
|
||||
readonly WAIT: 'wait';
|
||||
readonly REACT: 'react';
|
||||
readonly TYPE: 'type';
|
||||
readonly SLEEP: 'sleep';
|
||||
readonly WAITING: 'wait';
|
||||
readonly REACTING: 'react';
|
||||
readonly TYPING: 'type';
|
||||
readonly SLEEPING: 'sleep';
|
||||
};
|
||||
|
||||
export const Emotions: {
|
||||
|
||||
@ -17,7 +17,7 @@ export class ReactStateHandler extends StateHandler {
|
||||
* @param {OwenAnimationContext} context - The animation context
|
||||
*/
|
||||
constructor (context) {
|
||||
super(States.REACT, context)
|
||||
super(States.REACTING, context)
|
||||
|
||||
/**
|
||||
* Current emotional state
|
||||
@ -33,7 +33,7 @@ export class ReactStateHandler extends StateHandler {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
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
|
||||
|
||||
// Play appropriate reaction
|
||||
@ -51,7 +51,7 @@ export class ReactStateHandler extends StateHandler {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
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) {
|
||||
await this.stopCurrentClip()
|
||||
@ -154,6 +154,6 @@ export class ReactStateHandler extends StateHandler {
|
||||
* @returns {string[]} Array of available state transitions
|
||||
*/
|
||||
getAvailableTransitions () {
|
||||
return [States.TYPE, States.WAIT]
|
||||
return [ States.TYPING, States.WAITING ]
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ export class SleepStateHandler extends StateHandler {
|
||||
* @param {OwenAnimationContext} context - The animation context
|
||||
*/
|
||||
constructor (context) {
|
||||
super(States.SLEEP, context)
|
||||
super(States.SLEEPING, context)
|
||||
|
||||
/**
|
||||
* Sleep animation clip
|
||||
@ -39,7 +39,7 @@ export class SleepStateHandler extends StateHandler {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
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
|
||||
const sleepTransition = this.context.getClip('wait_2sleep_T')
|
||||
@ -65,7 +65,7 @@ export class SleepStateHandler extends StateHandler {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async exit (toState = null, _emotion = Emotions.NEUTRAL) {
|
||||
console.log(`Exiting SLEEP state to ${toState}`)
|
||||
console.log(`Exiting SLEEPING state to ${toState}`)
|
||||
this.isDeepSleep = false
|
||||
|
||||
if (this.currentClip) {
|
||||
@ -107,8 +107,8 @@ export class SleepStateHandler extends StateHandler {
|
||||
// Any message should wake up the character
|
||||
if (this.isDeepSleep) {
|
||||
console.log('Waking up due to user message')
|
||||
// This will trigger a state transition to REACT
|
||||
await this.context.transitionTo(States.REACT)
|
||||
// This will trigger a state transition to REACTING
|
||||
await this.context.transitionTo(States.REACTING)
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,7 +117,7 @@ export class SleepStateHandler extends StateHandler {
|
||||
* @returns {string[]} Array of available state transitions
|
||||
*/
|
||||
getAvailableTransitions () {
|
||||
return [States.WAIT, States.REACT]
|
||||
return [ States.WAITING, States.REACTING ]
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,7 +134,7 @@ export class SleepStateHandler extends StateHandler {
|
||||
*/
|
||||
async wakeUp () {
|
||||
if (this.isDeepSleep) {
|
||||
await this.context.transitionTo(States.WAIT)
|
||||
await this.context.transitionTo(States.WAITING)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,10 +26,10 @@ export class StateFactory {
|
||||
this.stateHandlers = new Map()
|
||||
|
||||
// Register default state handlers
|
||||
this.registerStateHandler(States.WAIT, WaitStateHandler)
|
||||
this.registerStateHandler(States.REACT, ReactStateHandler)
|
||||
this.registerStateHandler(States.TYPE, TypeStateHandler)
|
||||
this.registerStateHandler(States.SLEEP, SleepStateHandler)
|
||||
this.registerStateHandler(States.WAITING, WaitStateHandler);
|
||||
this.registerStateHandler(States.REACTING, ReactStateHandler);
|
||||
this.registerStateHandler(States.TYPING, TypeStateHandler);
|
||||
this.registerStateHandler(States.SLEEPING, SleepStateHandler)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -17,7 +17,7 @@ export class TypeStateHandler extends StateHandler {
|
||||
* @param {OwenAnimationContext} context - The animation context
|
||||
*/
|
||||
constructor (context) {
|
||||
super(States.TYPE, context)
|
||||
super(States.TYPING, context)
|
||||
|
||||
/**
|
||||
* Current emotional state
|
||||
@ -39,7 +39,7 @@ export class TypeStateHandler extends StateHandler {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
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.isTyping = true
|
||||
|
||||
@ -63,7 +63,7 @@ export class TypeStateHandler extends StateHandler {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async exit (toState = null, _emotion = Emotions.NEUTRAL) {
|
||||
console.log(`Exiting TYPE state to ${toState}`)
|
||||
console.log(`Exiting TYPING state to ${toState}`)
|
||||
this.isTyping = false
|
||||
|
||||
if (this.currentClip) {
|
||||
@ -106,7 +106,7 @@ export class TypeStateHandler extends StateHandler {
|
||||
* @returns {string[]} Array of available state transitions
|
||||
*/
|
||||
getAvailableTransitions () {
|
||||
return [States.WAIT, States.REACT]
|
||||
return [ States.WAITING, States.REACTING ]
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -17,7 +17,7 @@ export class WaitStateHandler extends StateHandler {
|
||||
* @param {OwenAnimationContext} context - The animation context
|
||||
*/
|
||||
constructor (context) {
|
||||
super(States.WAIT, context)
|
||||
super(States.WAITING, context)
|
||||
|
||||
/**
|
||||
* The main idle animation clip
|
||||
@ -51,7 +51,7 @@ export class WaitStateHandler extends StateHandler {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async enter (fromState = null, _emotion = Emotions.NEUTRAL) {
|
||||
console.log(`Entering WAIT state from ${fromState}`)
|
||||
console.log(`Entering WAITING state from ${fromState}`)
|
||||
|
||||
// Play idle loop
|
||||
this.idleClip = this.context.getClip('wait_idle_L')
|
||||
@ -72,7 +72,7 @@ export class WaitStateHandler extends StateHandler {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async exit (toState = null, _emotion = Emotions.NEUTRAL) {
|
||||
console.log(`Exiting WAIT state to ${toState}`)
|
||||
console.log(`Exiting WAITING state to ${toState}`)
|
||||
|
||||
if (this.currentClip) {
|
||||
await this.stopCurrentClip()
|
||||
@ -133,6 +133,6 @@ export class WaitStateHandler extends StateHandler {
|
||||
* @returns {string[]} Array of available state transitions
|
||||
*/
|
||||
getAvailableTransitions () {
|
||||
return [States.REACT, States.SLEEP]
|
||||
return [ States.REACTING, States.SLEEPING ]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user