Refactor code for consistency and readability
- Updated import statements to use consistent formatting across files. - Adjusted method definitions and class constructors for uniform spacing and style. - Simplified promise handling and error messages in state handlers. - Enhanced state transition logic in various state handlers. - Improved quirk animation handling in WaitStateHandler. - Streamlined animation loading and caching mechanisms in AnimationLoader. - Updated Vite configuration for aliasing.
This commit is contained in:
@ -3,8 +3,8 @@
|
||||
* @module states
|
||||
*/
|
||||
|
||||
import { StateHandler } from './StateHandler.js';
|
||||
import { States, Emotions } from '../constants.js';
|
||||
import { StateHandler } from './StateHandler.js'
|
||||
import { States, Emotions } from '../constants.js'
|
||||
|
||||
/**
|
||||
* Handler for the Type state
|
||||
@ -16,20 +16,20 @@ export class TypeStateHandler extends StateHandler {
|
||||
* Create a type state handler
|
||||
* @param {OwenAnimationContext} context - The animation context
|
||||
*/
|
||||
constructor(context) {
|
||||
super(States.TYPE, context);
|
||||
constructor (context) {
|
||||
super(States.TYPE, context)
|
||||
|
||||
/**
|
||||
* Current emotional state
|
||||
* @type {string}
|
||||
*/
|
||||
this.emotion = Emotions.NEUTRAL;
|
||||
this.emotion = Emotions.NEUTRAL
|
||||
|
||||
/**
|
||||
* Whether currently typing
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.isTyping = false;
|
||||
this.isTyping = false
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,21 +38,21 @@ export class TypeStateHandler extends StateHandler {
|
||||
* @param {string} [emotion=Emotions.NEUTRAL] - The emotion to enter with
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async enter(_fromState = null, emotion = Emotions.NEUTRAL) {
|
||||
console.log(`Entering TYPE state with emotion: ${emotion}`);
|
||||
this.emotion = emotion;
|
||||
this.isTyping = true;
|
||||
async enter (_fromState = null, emotion = Emotions.NEUTRAL) {
|
||||
console.log(`Entering TYPE state with emotion: ${emotion}`)
|
||||
this.emotion = emotion
|
||||
this.isTyping = true
|
||||
|
||||
// Play appropriate typing animation
|
||||
let typingClipName = 'type_idle_L';
|
||||
let typingClipName = 'type_idle_L'
|
||||
if (emotion !== Emotions.NEUTRAL) {
|
||||
typingClipName = `type_${emotion}_L`;
|
||||
typingClipName = `type_${emotion}_L`
|
||||
}
|
||||
|
||||
const typingClip = this.context.getClip(typingClipName);
|
||||
const typingClip = this.context.getClip(typingClipName)
|
||||
if (typingClip) {
|
||||
await typingClip.play();
|
||||
this.currentClip = typingClip;
|
||||
await typingClip.play()
|
||||
this.currentClip = typingClip
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,24 +62,24 @@ export class TypeStateHandler extends StateHandler {
|
||||
* @param {string} [_emotion=Emotions.NEUTRAL] - The emotion to exit with (unused)
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async exit(toState = null, _emotion = Emotions.NEUTRAL) {
|
||||
console.log(`Exiting TYPE state to ${toState}`);
|
||||
this.isTyping = false;
|
||||
async exit (toState = null, _emotion = Emotions.NEUTRAL) {
|
||||
console.log(`Exiting TYPE state to ${toState}`)
|
||||
this.isTyping = false
|
||||
|
||||
if (this.currentClip) {
|
||||
await this.stopCurrentClip();
|
||||
await this.stopCurrentClip()
|
||||
}
|
||||
|
||||
// Play transition if available
|
||||
let transitionName = `type_2${toState}_T`;
|
||||
let transitionName = `type_2${toState}_T`
|
||||
if (this.emotion !== Emotions.NEUTRAL) {
|
||||
transitionName = `type_${this.emotion}2${toState}_T`;
|
||||
transitionName = `type_${this.emotion}2${toState}_T`
|
||||
}
|
||||
|
||||
const transition = this.context.getClip(transitionName);
|
||||
const transition = this.context.getClip(transitionName)
|
||||
if (transition) {
|
||||
await transition.play();
|
||||
await this.waitForClipEnd(transition);
|
||||
await transition.play()
|
||||
await this.waitForClipEnd(transition)
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,34 +87,34 @@ export class TypeStateHandler extends StateHandler {
|
||||
* Finish typing and prepare to transition
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async finishTyping() {
|
||||
if (!this.isTyping) return;
|
||||
async finishTyping () {
|
||||
if (!this.isTyping) return
|
||||
|
||||
// Play typing finish animation if available
|
||||
const finishClip = this.context.getClip('type_finish_Q');
|
||||
const finishClip = this.context.getClip('type_finish_Q')
|
||||
if (finishClip && this.currentClip) {
|
||||
await this.stopCurrentClip(0.2);
|
||||
await finishClip.play();
|
||||
await this.waitForClipEnd(finishClip);
|
||||
await this.stopCurrentClip(0.2)
|
||||
await finishClip.play()
|
||||
await this.waitForClipEnd(finishClip)
|
||||
}
|
||||
|
||||
this.isTyping = false;
|
||||
this.isTyping = false
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available transitions from type state
|
||||
* @returns {string[]} Array of available state transitions
|
||||
*/
|
||||
getAvailableTransitions() {
|
||||
return [ States.WAIT, States.REACT ];
|
||||
getAvailableTransitions () {
|
||||
return [States.WAIT, States.REACT]
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if currently typing
|
||||
* @returns {boolean} True if typing, false otherwise
|
||||
*/
|
||||
getIsTyping() {
|
||||
return this.isTyping;
|
||||
getIsTyping () {
|
||||
return this.isTyping
|
||||
}
|
||||
|
||||
/**
|
||||
@ -122,7 +122,7 @@ export class TypeStateHandler extends StateHandler {
|
||||
* @param {boolean} typing - Whether currently typing
|
||||
* @returns {void}
|
||||
*/
|
||||
setTyping(typing) {
|
||||
this.isTyping = typing;
|
||||
setTyping (typing) {
|
||||
this.isTyping = typing
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user