Some checks failed
CI/CD Pipeline / Test & Lint (16.x) (push) Has been cancelled
CI/CD Pipeline / Test & Lint (18.x) (push) Has been cancelled
CI/CD Pipeline / Test & Lint (20.x) (push) Has been cancelled
CI/CD Pipeline / Security Audit (push) Has been cancelled
CI/CD Pipeline / Release (push) Has been cancelled
- Implemented StateHandler class with methods for entering, exiting, and updating states. - Created TypeStateHandler for handling typing state with appropriate animations and transitions. - Developed WaitStateHandler for managing idle state with quirk animations. - Added JSDoc documentation for all new classes and methods. - Included CSS styles for documentation formatting and syntax highlighting.
247 lines
6.6 KiB
HTML
247 lines
6.6 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<title>JSDoc: Source: states/TypeStateHandler.js</title>
|
|
|
|
<script src="scripts/prettify/prettify.js"></script>
|
|
<script src="scripts/prettify/lang-css.js"></script>
|
|
<!--[if lt IE 9]>
|
|
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
<![endif]-->
|
|
<link
|
|
type="text/css"
|
|
rel="stylesheet"
|
|
href="styles/prettify-tomorrow.css"
|
|
/>
|
|
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css" />
|
|
</head>
|
|
|
|
<body>
|
|
<div id="main">
|
|
<h1 class="page-title">Source: states/TypeStateHandler.js</h1>
|
|
|
|
<section>
|
|
<article>
|
|
<pre class="prettyprint source linenums"><code>/**
|
|
* @fileoverview Type state handler implementation
|
|
* @module states
|
|
*/
|
|
|
|
import { StateHandler } from './StateHandler.js'
|
|
import { States, Emotions } from '../constants.js'
|
|
|
|
/**
|
|
* Handler for the Type state
|
|
* @class
|
|
* @extends StateHandler
|
|
*/
|
|
export class TypeStateHandler extends StateHandler {
|
|
/**
|
|
* Create a type state handler
|
|
* @param {OwenAnimationContext} context - The animation context
|
|
*/
|
|
constructor (context) {
|
|
super(States.TYPING, context)
|
|
|
|
/**
|
|
* Current emotional state
|
|
* @type {string}
|
|
*/
|
|
this.emotion = Emotions.NEUTRAL
|
|
|
|
/**
|
|
* Whether currently typing
|
|
* @type {boolean}
|
|
*/
|
|
this.isTyping = false
|
|
}
|
|
|
|
/**
|
|
* Enter the type state
|
|
* @param {string|null} [_fromState=null] - The previous state (unused)
|
|
* @param {string} [emotion=Emotions.NEUTRAL] - The emotion to enter with
|
|
* @returns {Promise<void>}
|
|
*/
|
|
async enter (_fromState = null, emotion = Emotions.NEUTRAL) {
|
|
console.log(`Entering TYPING state with emotion: ${emotion}`)
|
|
this.emotion = emotion
|
|
this.isTyping = true
|
|
|
|
// Play appropriate typing animation
|
|
let typingClipName = 'type_idle_L'
|
|
if (emotion !== Emotions.NEUTRAL) {
|
|
typingClipName = `type_${emotion}_L`
|
|
}
|
|
|
|
const typingClip = this.context.getClip(typingClipName)
|
|
if (typingClip) {
|
|
await typingClip.play()
|
|
this.currentClip = typingClip
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Exit the type state
|
|
* @param {string|null} [toState=null] - The next state
|
|
* @param {string} [_emotion=Emotions.NEUTRAL] - The emotion to exit with (unused)
|
|
* @returns {Promise<void>}
|
|
*/
|
|
async exit (toState = null, _emotion = Emotions.NEUTRAL) {
|
|
console.log(`Exiting TYPING state to ${toState}`)
|
|
this.isTyping = false
|
|
|
|
if (this.currentClip) {
|
|
await this.stopCurrentClip()
|
|
}
|
|
|
|
// Play transition if available
|
|
let transitionName = `type_2${toState}_T`
|
|
if (this.emotion !== Emotions.NEUTRAL) {
|
|
transitionName = `type_${this.emotion}2${toState}_T`
|
|
}
|
|
|
|
const transition = this.context.getClip(transitionName)
|
|
if (transition) {
|
|
await transition.play()
|
|
await this.waitForClipEnd(transition)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Finish typing and prepare to transition
|
|
* @returns {Promise<void>}
|
|
*/
|
|
async finishTyping () {
|
|
if (!this.isTyping) return
|
|
|
|
// Play typing finish animation if available
|
|
const finishClip = this.context.getClip('type_finish_Q')
|
|
if (finishClip && this.currentClip) {
|
|
await this.stopCurrentClip(0.2)
|
|
await finishClip.play()
|
|
await this.waitForClipEnd(finishClip)
|
|
}
|
|
|
|
this.isTyping = false
|
|
}
|
|
|
|
/**
|
|
* Get available transitions from type state
|
|
* @returns {string[]} Array of available state transitions
|
|
*/
|
|
getAvailableTransitions () {
|
|
return [States.WAITING, States.REACTING]
|
|
}
|
|
|
|
/**
|
|
* Check if currently typing
|
|
* @returns {boolean} True if typing, false otherwise
|
|
*/
|
|
getIsTyping () {
|
|
return this.isTyping
|
|
}
|
|
|
|
/**
|
|
* Set typing state
|
|
* @param {boolean} typing - Whether currently typing
|
|
* @returns {void}
|
|
*/
|
|
setTyping (typing) {
|
|
this.isTyping = typing
|
|
}
|
|
}
|
|
</code></pre>
|
|
</article>
|
|
</section>
|
|
</div>
|
|
|
|
<nav>
|
|
<h2><a href="index.html">Home</a></h2>
|
|
<h3>Modules</h3>
|
|
<ul>
|
|
<li><a href="module-StateHandler.html">StateHandler</a></li>
|
|
<li><a href="module-animation.html">animation</a></li>
|
|
<li>
|
|
<a href="module-animation_AnimationConstants.html"
|
|
>animation/AnimationConstants</a
|
|
>
|
|
</li>
|
|
<li>
|
|
<a href="module-animation_AnimationNameMapper.html"
|
|
>animation/AnimationNameMapper</a
|
|
>
|
|
</li>
|
|
<li><a href="module-constants.html">constants</a></li>
|
|
<li><a href="module-core.html">core</a></li>
|
|
<li><a href="module-factories.html">factories</a></li>
|
|
<li><a href="module-loaders.html">loaders</a></li>
|
|
<li><a href="module-owen.html">owen</a></li>
|
|
<li><a href="module-states.html">states</a></li>
|
|
</ul>
|
|
<h3>Classes</h3>
|
|
<ul>
|
|
<li>
|
|
<a href="module-StateHandler.StateHandler.html">StateHandler</a>
|
|
</li>
|
|
<li><a href="module-animation.AnimationClip.html">AnimationClip</a></li>
|
|
<li>
|
|
<a href="module-animation.AnimationClipFactory.html"
|
|
>AnimationClipFactory</a
|
|
>
|
|
</li>
|
|
<li>
|
|
<a
|
|
href="module-animation_AnimationNameMapper.AnimationNameMapper.html"
|
|
>AnimationNameMapper</a
|
|
>
|
|
</li>
|
|
<li>
|
|
<a href="module-core.OwenAnimationContext.html"
|
|
>OwenAnimationContext</a
|
|
>
|
|
</li>
|
|
<li>
|
|
<a href="module-factories.OwenSystemFactory.html"
|
|
>OwenSystemFactory</a
|
|
>
|
|
</li>
|
|
<li>
|
|
<a href="module-loaders.AnimationLoader.html">AnimationLoader</a>
|
|
</li>
|
|
<li>
|
|
<a href="module-loaders.GLTFAnimationLoader.html"
|
|
>GLTFAnimationLoader</a
|
|
>
|
|
</li>
|
|
<li>
|
|
<a href="module-states.ReactStateHandler.html">ReactStateHandler</a>
|
|
</li>
|
|
<li>
|
|
<a href="module-states.SleepStateHandler.html">SleepStateHandler</a>
|
|
</li>
|
|
<li><a href="module-states.StateFactory.html">StateFactory</a></li>
|
|
<li>
|
|
<a href="module-states.TypeStateHandler.html">TypeStateHandler</a>
|
|
</li>
|
|
<li>
|
|
<a href="module-states.WaitStateHandler.html">WaitStateHandler</a>
|
|
</li>
|
|
</ul>
|
|
</nav>
|
|
|
|
<br class="clear" />
|
|
|
|
<footer>
|
|
Documentation generated by
|
|
<a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.4</a> on Sat May 24
|
|
2025 12:29:38 GMT+0200 (Midden-Europese zomertijd)
|
|
</footer>
|
|
|
|
<script>
|
|
prettyPrint();
|
|
</script>
|
|
<script src="scripts/linenumber.js"></script>
|
|
</body>
|
|
</html>
|