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,39 +3,38 @@
|
||||
* @author Owen Animation System
|
||||
*/
|
||||
|
||||
import { OwenSystemFactory, States } from '../src/index.js';
|
||||
import { OwenSystemFactory, States } from '../src/index.js'
|
||||
|
||||
/**
|
||||
* Simple example of using Owen Animation System
|
||||
* This example shows how to use the system without a browser environment
|
||||
*/
|
||||
class SimpleOwenExample {
|
||||
constructor() {
|
||||
this.owenSystem = null;
|
||||
constructor () {
|
||||
this.owenSystem = null
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the Owen system with a mock model
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async init() {
|
||||
async init () {
|
||||
try {
|
||||
// Create a mock GLTF model for demonstration
|
||||
const mockModel = this.createMockModel();
|
||||
const mockModel = this.createMockModel()
|
||||
|
||||
// Create the Owen system
|
||||
this.owenSystem = await OwenSystemFactory.createBasicOwenSystem(mockModel);
|
||||
this.owenSystem = await OwenSystemFactory.createBasicOwenSystem(mockModel)
|
||||
|
||||
console.log('✅ Owen Animation System initialized successfully!');
|
||||
console.log('📊 System Info:');
|
||||
console.log(` Available States: ${this.owenSystem.getAvailableStates().join(', ')}`);
|
||||
console.log(` Current State: ${this.owenSystem.getCurrentState()}`);
|
||||
console.log('✅ Owen Animation System initialized successfully!')
|
||||
console.log('📊 System Info:')
|
||||
console.log(` Available States: ${this.owenSystem.getAvailableStates().join(', ')}`)
|
||||
console.log(` Current State: ${this.owenSystem.getCurrentState()}`)
|
||||
|
||||
// Run some example interactions
|
||||
await this.runExamples();
|
||||
|
||||
await this.runExamples()
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to initialize Owen system:', error.message);
|
||||
console.error('❌ Failed to initialize Owen system:', error.message)
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +42,7 @@ class SimpleOwenExample {
|
||||
* Create a mock 3D model for demonstration purposes
|
||||
* @returns {Object} Mock model object
|
||||
*/
|
||||
createMockModel() {
|
||||
createMockModel () {
|
||||
return {
|
||||
animations: [
|
||||
{ name: 'wait_idle_L' },
|
||||
@ -63,46 +62,46 @@ class SimpleOwenExample {
|
||||
],
|
||||
scene: {},
|
||||
userData: {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run example interactions with the Owen system
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async runExamples() {
|
||||
console.log('\n🎬 Running example interactions...\n');
|
||||
async runExamples () {
|
||||
console.log('\n🎬 Running example interactions...\n')
|
||||
|
||||
// Example 1: Basic state transitions
|
||||
console.log('📝 Example 1: Manual state transitions');
|
||||
await this.demonstrateStateTransitions();
|
||||
console.log('📝 Example 1: Manual state transitions')
|
||||
await this.demonstrateStateTransitions()
|
||||
|
||||
// Example 2: Message handling
|
||||
console.log('\n📝 Example 2: Message handling with emotions');
|
||||
await this.demonstrateMessageHandling();
|
||||
console.log('\n📝 Example 2: Message handling with emotions')
|
||||
await this.demonstrateMessageHandling()
|
||||
|
||||
// Example 3: System update loop
|
||||
console.log('\n📝 Example 3: System update simulation');
|
||||
this.demonstrateUpdateLoop();
|
||||
console.log('\n📝 Example 3: System update simulation')
|
||||
this.demonstrateUpdateLoop()
|
||||
|
||||
console.log('\n✨ All examples completed!');
|
||||
console.log('\n✨ All examples completed!')
|
||||
}
|
||||
|
||||
/**
|
||||
* Demonstrate manual state transitions
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async demonstrateStateTransitions() {
|
||||
const states = [ States.REACT, States.TYPE, States.WAIT, States.SLEEP ];
|
||||
async demonstrateStateTransitions () {
|
||||
const states = [States.REACT, States.TYPE, States.WAIT, States.SLEEP]
|
||||
|
||||
for (const state of states) {
|
||||
console.log(`🔄 Transitioning to ${state.toUpperCase()} state...`);
|
||||
await this.owenSystem.transitionTo(state);
|
||||
console.log(` ✓ Current state: ${this.owenSystem.getCurrentState()}`);
|
||||
console.log(` ✓ Available transitions: ${this.owenSystem.getAvailableTransitions().join(', ')}`);
|
||||
console.log(`🔄 Transitioning to ${state.toUpperCase()} state...`)
|
||||
await this.owenSystem.transitionTo(state)
|
||||
console.log(` ✓ Current state: ${this.owenSystem.getCurrentState()}`)
|
||||
console.log(` ✓ Available transitions: ${this.owenSystem.getAvailableTransitions().join(', ')}`)
|
||||
|
||||
// Simulate some time passing
|
||||
await this.sleep(500);
|
||||
await this.sleep(500)
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,23 +109,23 @@ class SimpleOwenExample {
|
||||
* Demonstrate message handling with emotional responses
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async demonstrateMessageHandling() {
|
||||
async demonstrateMessageHandling () {
|
||||
const messages = [
|
||||
{ text: 'Hello Owen!', expected: 'neutral response' },
|
||||
{ text: 'This is urgent!', expected: 'angry/urgent response' },
|
||||
{ text: 'Great work!', expected: 'happy response' },
|
||||
{ text: 'There\'s an error in the system', expected: 'shocked response' },
|
||||
{ text: 'I\'m feeling sad today', expected: 'sad response' }
|
||||
];
|
||||
]
|
||||
|
||||
for (const message of messages) {
|
||||
console.log(`💬 Sending message: "${message.text}"`);
|
||||
console.log(` Expected: ${message.expected}`);
|
||||
console.log(`💬 Sending message: "${message.text}"`)
|
||||
console.log(` Expected: ${message.expected}`)
|
||||
|
||||
await this.owenSystem.handleUserMessage(message.text);
|
||||
console.log(` ✓ Current state after message: ${this.owenSystem.getCurrentState()}`);
|
||||
await this.owenSystem.handleUserMessage(message.text)
|
||||
console.log(` ✓ Current state after message: ${this.owenSystem.getCurrentState()}`)
|
||||
|
||||
await this.sleep(300);
|
||||
await this.sleep(300)
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,26 +133,26 @@ class SimpleOwenExample {
|
||||
* Demonstrate the system update loop
|
||||
* @returns {void}
|
||||
*/
|
||||
demonstrateUpdateLoop() {
|
||||
console.log('⏱️ Simulating update loop for 3 seconds...');
|
||||
demonstrateUpdateLoop () {
|
||||
console.log('⏱️ Simulating update loop for 3 seconds...')
|
||||
|
||||
let iterations = 0;
|
||||
const startTime = Date.now();
|
||||
let iterations = 0
|
||||
const startTime = Date.now()
|
||||
|
||||
const updateLoop = () => {
|
||||
const deltaTime = 16.67; // ~60 FPS
|
||||
this.owenSystem.update(deltaTime);
|
||||
iterations++;
|
||||
const deltaTime = 16.67 // ~60 FPS
|
||||
this.owenSystem.update(deltaTime)
|
||||
iterations++
|
||||
|
||||
if (Date.now() - startTime < 3000) {
|
||||
setTimeout(updateLoop, 16);
|
||||
setTimeout(updateLoop, 16)
|
||||
} else {
|
||||
console.log(` ✓ Completed ${iterations} update iterations`);
|
||||
console.log(` ✓ Final state: ${this.owenSystem.getCurrentState()}`);
|
||||
console.log(` ✓ Completed ${iterations} update iterations`)
|
||||
console.log(` ✓ Final state: ${this.owenSystem.getCurrentState()}`)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
updateLoop();
|
||||
updateLoop()
|
||||
}
|
||||
|
||||
/**
|
||||
@ -161,24 +160,24 @@ class SimpleOwenExample {
|
||||
* @param {number} ms - Milliseconds to sleep
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
sleep (ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms))
|
||||
}
|
||||
}
|
||||
|
||||
// Run the example if this file is executed directly
|
||||
if (import.meta.url === `file://${process.argv[ 1 ]}`) {
|
||||
console.log('🚀 Starting Owen Animation System Example\n');
|
||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
console.log('🚀 Starting Owen Animation System Example\n')
|
||||
|
||||
const example = new SimpleOwenExample();
|
||||
const example = new SimpleOwenExample()
|
||||
example.init()
|
||||
.then(() => {
|
||||
console.log('\n🎉 Example completed successfully!');
|
||||
console.log('💡 Try modifying this example or check out the browser demo in examples/index.html');
|
||||
console.log('\n🎉 Example completed successfully!')
|
||||
console.log('💡 Try modifying this example or check out the browser demo in examples/index.html')
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('\n💥 Example failed:', error);
|
||||
});
|
||||
console.error('\n💥 Example failed:', error)
|
||||
})
|
||||
}
|
||||
|
||||
export default SimpleOwenExample;
|
||||
export default SimpleOwenExample
|
||||
|
||||
Reference in New Issue
Block a user