Commit Graph

222 Commits

Author SHA1 Message Date
fritzsenpai 16d561eae2 Implement Phase 3: MusicManager Integration with Custom Audio
Complete integration of custom audio files with existing music player:

## Core Integration Features:

1. **Extended Track System:**
   - Built-in tracks marked with isBuiltIn: true
   - Custom tracks marked with isCustom: true
   - MusicManager now loads custom background music from storage
   - Automatic filtering of enabled custom tracks

2. **Dynamic Track Loading:**
   - loadCustomTracks(): Loads enabled background music into MusicManager
   - refreshCustomTracks(): Updates track list when audio files change
   - Auto-refresh when audio gallery is loaded/updated
   - Maintains backwards compatibility with built-in tracks

3. **Enhanced Track Selector:**
   - updateTrackSelector(): Rebuilds dropdown with all available tracks
   - Custom tracks labeled as '(Custom)' in selector
   - Handles track list changes without breaking current playback
   - Auto-resets to first track if current track becomes unavailable

4. **Seamless Integration:**
   - Custom background music appears alongside built-in tracks
   - All existing music controls work with custom tracks (play/pause, loop, shuffle, volume)
   - Track selector automatically updates when importing/deleting audio
   - No changes needed to existing playback logic

## User Experience:

 Import background music  Automatically appears in music player dropdown
 Enable/disable audio  Updates music player track list immediately
 Delete audio  Safely removes from player and resets if needed
 All music controls work seamlessly with custom tracks
 Visual distinction between built-in and custom tracks

## Technical Implementation:

- MusicManager.tracks array now includes custom audio files
- Automatic synchronization between audio management and music player
- Smart track indexing that survives add/remove operations
- Integrated with existing storage system and settings persistence

**Custom background music now fully integrated with the header music player!**
2025-09-25 21:45:42 -05:00
fritzsenpai c2e5b572ec Fix audio property mismatch: Use 'name' instead of 'filename'
Critical property mismatch fix:

Root Cause:
- Audio objects stored in customAudio have 'name' property (from desktop-file-manager.js)
- But UI templates and functions were looking for 'filename' property
- This caused audio files to never be found for deletion or enable/disable

Fixed Components:

1. HTML Template (loadAudioCategory):
   - data-filename now uses audio.name instead of audio.filename
   - Display filename now uses audio.name
   - onchange handler now passes audio.name

2. Deletion Logic (deleteSelectedAudio):
   - Search logic now looks for audio.name === filename
   - Removed incorrect audio.filename references

3. Storage Operations:
   - removeAudioFromStorage now filters by audio.name
   - toggleAudioEnabled now finds files by audio.name

4. Consistency:
   - All audio operations now use consistent 'name' property
   - Matches the actual storage structure from import process

This fixes:
 Audio file deletion (files can now be found in storage)
 Enable/disable toggles (files can be located properly)
 Storage operations (consistent property references)
 UI display consistency (proper filename display)

Audio deletion should now work correctly.
2025-09-25 21:41:11 -05:00
fritzsenpai 663bc9c489 Fix audio deletion async handling and add debugging
Fixes for audio deletion functionality:

1. Async Handling Fix:
   - Made deleteSelectedAudio() async function
   - Replaced forEach with Promise.all() for proper async handling
   - deletedCount was not updating correctly due to async timing issues
   - Now waits for all deletion promises to complete before showing results

2. Enhanced Error Handling:
   - Added try/catch around Promise.all()
   - Better error messages for failed deletions
   - Separate handling for no deletions vs errors

3. Debug Logging:
   - Added console logs to track audio file lookup process
   - Logs storage contents and search parameters
   - Helps identify why files aren't being found for deletion
   - Shows actual audioFile object found in storage

4. Improved User Feedback:
   - Shows specific count of successful deletions
   - Warning when no files are deleted
   - Error notification for deletion failures

This should resolve the deletion timing issues and provide better insight into any remaining problems.
2025-09-25 21:36:25 -05:00
fritzsenpai b4709e4f66 Fix audio file deletion: Correct path resolution for file deletion
Critical bug fix for audio deletion:

Issue:
- deleteSelectedAudio() was passing category and filename to deleteAudio()
- deleteAudio() expects full file path as first parameter
- This caused deletion attempts on directory paths like 'C:\Users\drew\webGame\background'
- Result: ENOENT errors trying to delete directories instead of files

Fix:
- Look up full audio file path from storage before calling deleteAudio()
- Handle both string and object audio storage formats
- Pass correct audioPath parameter to deleteAudio(audioPath, category)
- Enhanced removeAudioFromStorage() to handle both storage formats properly

Changes:
- deleteSelectedAudio(): Find full path from storage before deletion
- removeAudioFromStorage(): Support both string paths and object formats
- Proper error handling when audio file not found in storage
- Maintains backward compatibility with different storage formats

Now audio deletion works correctly:
 Finds correct file paths from storage
 Deletes actual audio files from disk
 Removes storage references properly
 No more ENOENT directory deletion errors
2025-09-25 21:34:07 -05:00
fritzsenpai 4e8e08c51e Fix audio import functionality: Add missing IPC API exposure
Critical fix for audio management:
- Added missing audio IPC functions to preload.js
- selectAudio: File dialog for selecting audio files
- readAudioDirectory: Directory scanning with title formatting
- copyAudio: File copying for audio import

Issue:
- Audio IPC handlers existed in main.js but weren't exposed to renderer
- selectAndImportAudio() calls were failing with 'undefined function' errors
- Upload functionality was broken due to missing API bridge

Fix:
- Exposed all three audio IPC functions in electronAPI context bridge
- Audio import buttons now have access to required backend functionality
- Maintains consistency with existing image API pattern

Now audio management fully functional:
 File selection dialogs work
 Directory scanning operational
 File copying and import functional
 Ready for user testing
2025-09-25 21:31:40 -05:00
fritzsenpai 9c8876b89f Implement Phase 2: Complete Audio Management UI
Major audio management interface implementation:

HTML Structure (index.html):
- Added complete audio-management-screen after image management
- Audio import buttons for background/ambient/effects categories
- Audio gallery with tabbed interface (background, ambient, effects)
- Audio preview section with HTML5 audio player
- Gallery controls: select all, deselect all, delete, preview
- Manage Audio button added to main start screen
- Professional layout matching image management design

CSS Styling (styles.css):
- Complete audio management styling system
- Audio gallery grid layout with 280px cards
- Audio item cards with icons, titles, controls
- Tabbed interface styling with active states
- Audio preview section with integrated player
- Category-specific icons ( background,  ambient,  effects)
- Hover effects, selection states, and responsive design
- Consistent with image management visual patterns

JavaScript Functionality (game.js):
- showAudioManagement() - main screen initialization
- setupAudioManagementEventListeners() - comprehensive event handling
- loadAudioGallery() - populate all three category galleries
- Audio tab switching (background/ambient/effects)
- Audio selection/deselection with click handlers
- Audio preview system with HTML5 player integration
- Delete functionality for selected audio files
- Enable/disable audio file toggles
- Audio storage info modal with desktop/web mode details
- Complete event listener management with duplicate prevention
- Audio discovery initialization in constructor

Features:
- Three-category audio organization (background, ambient, effects)
- Click-to-select audio items with visual feedback
- Preview selected audio files with integrated player
- Bulk operations: select all, deselect all, delete selected
- Enable/disable individual audio files
- Desktop file management integration
- Automatic audio directory scanning
- Storage information with category breakdowns
- Professional gallery layout with metadata display

Ready for Phase 3: Integration with MusicManager for playlist functionality
2025-09-25 21:27:21 -05:00
fritzsenpai c67d4dca27 Implement Phase 1: Desktop Audio Management Infrastructure
- Add comprehensive audio file management to desktop-file-manager.js
  - Audio directory structure (background/ambient/effects categories)
  - selectAndImportAudio() with category selection and file dialog integration
  - scanDirectoryForAudio() with category-specific scanning
  - updateAudioStorage() with duplicate prevention and storage management
  - deleteAudio() with file cleanup and storage updates
  - Utility functions: getAudioTitle() and getAudioPath()

- Add audio-specific IPC handlers to main.js
  - select-audio: Multi-selection file dialog for audio files
  - read-audio-directory: Directory scanning with title formatting
  - copy-audio: File copying with directory creation
  - Support for MP3, WAV, OGG, M4A, AAC, FLAC formats

- Foundation ready for Phase 2: Audio Management UI implementation
2025-09-25 21:19:58 -05:00
fritzsenpai 5caa82e659 Remove debug logging
Clean up console.log statements added during troubleshooting:
- Removed logging from showImageManagement()
- Removed logging from setupImageManagementEventListeners()
- Removed logging from loadImageGallery()
- Removed logging from updateImageGalleryControls()

Production ready - no more debug console spam.
2025-09-25 21:15:08 -05:00
fritzsenpai 205fbc1186 Fix critical startup freeze when no images loaded
Root cause fix:
- startGame() was calling showScreen('image-management-screen') directly
- This bypassed setupImageManagementEventListeners() and loadImageGallery()
- Changed to call showImageManagement() instead which properly initializes the screen
- showImageManagement() sets up all event listeners and loads gallery correctly

Issue sequence:
1. App starts with no images
2. User immediately clicks 'Start Game'
3. startGame() detects no images available
4. Called showScreen() directly  No event listeners  Freeze
5. Now calls showImageManagement()  Full setup  Works perfectly

Fix tested scenario:
- Start app  Navigate to manage images  Back home  Start game  (was working)
- Start app  Immediately click Start game  (now fixed - was freezing)

The freeze only happened on immediate startup because the screen wasn't properly initialized.
2025-09-25 21:10:12 -05:00
fritzsenpai 3d949fe08c Fix image management screen freeze with performance optimization
Major performance improvements:
- Replaced expensive DOM cloning/replacing in setupImageManagementEventListeners()
- Used direct onclick assignments instead of clone/replace operations
- Added imageManagementListenersAttached flag to prevent duplicate listener attachment
- Simplified updateImageGalleryControls() to use direct onclick assignment
- Added comprehensive logging to track function execution flow
- Reset listener flag when showing image management screen for fresh attachment

Performance fixes:
- Eliminated heavy DOM manipulation that was causing UI freeze
- Reduced memory overhead from constant node cloning
- Prevented listener duplication without expensive DOM operations
- Faster event listener setup with direct property assignment

The freeze was caused by the expensive cloneNode() and replaceChild() operations
being performed on every screen load, creating performance bottlenecks.
2025-09-25 21:06:27 -05:00
fritzsenpai aa3b7d8a1c Fix game freeze with no images loaded
Critical fix for desktop startup:
- Fixed startGame() function to properly handle new customImages object format
- Previously trying to call .length on object instead of array
- Added proper backward compatibility checking for both old array and new object formats
- Added comprehensive logging to debug image management screen freeze
- Now correctly counts custom images from both task and consequence categories

Fixes error where:
- User clicks Start Game with no images
- Game redirects to image management screen but freezes
- TypeError: customImages.length when customImages is {task: [], consequence: []}

Error resolved with proper object structure handling and logging.
2025-09-25 21:03:12 -05:00
fritzsenpai 85ea7f8938 Fix image deletion to remove files from disk
Critical fix for desktop mode:
- Updated deleteSelectedImages() to actually delete image files from disk
- Desktop mode now uses fileManager.deleteImage() to remove physical files
- Added proper category detection (task/consequence) for file deletion
- Enhanced error handling for file deletion operations
- Added different success messages for desktop vs web mode
- Maintains backward compatibility with web mode (storage-only deletion)

Previously:
- Images imported to images/tasks/ and images/consequences/ directories
- Deletion only removed references from localStorage
- Files remained on disk, causing clutter and storage waste

Now:
- Desktop deletion removes both file references AND physical files
- Clean filesystem management with no orphaned files
- Proper feedback about file vs reference deletion
- Robust error handling for file system operations
2025-09-25 20:43:57 -05:00
fritzsenpai d060f46292 Clean up image display interface
Visual improvements:
- Removed filename display from under images for cleaner look
- Removed 'Custom' badge to reduce visual clutter
- Added hover tooltip showing filename when mouse over image
- Simplified image-info section to only show enable/disable controls
- Cleaned up unused isCustom variable logic

Benefits:
- Much cleaner, more minimalist image gallery appearance
- Filename information still accessible via hover tooltip
- Less visual noise - focus on the images themselves
- Enable/disable functionality remains prominent and clear
- More professional gallery layout similar to modern image managers
2025-09-25 20:39:56 -05:00
fritzsenpai f4d695aa76 Remove bulk selection checkboxes, restore click-to-select
Interface simplification:
- Removed bulk selection checkboxes from image items
- Restored original click-to-select behavior for image selection
- Users can now click directly on images to select/deselect them
- Select All/Deselect All buttons now work by directly modifying image classes
- Kept Enable/Disable checkbox functionality unchanged

Benefits:
- Cleaner visual interface with fewer checkboxes
- More intuitive selection - click on image to select it
- Reduced visual clutter while maintaining all functionality
- Same bulk operations (select all, deselect all, delete selected) still work
- Original UX restored where selection was visual highlight, not checkbox
2025-09-25 20:36:19 -05:00
fritzsenpai 7597bc8eed Fix TypeError: customImages is not iterable
- Fixed updateImageCount() function to handle new customImages data structure
- Added compatibility for both old (array) and new (object) customImages format
- Function now properly handles { task: [], consequence: [] } structure
- Prevents TypeError when toggling image enabled/disabled states

Error was occurring when:
- User clicked checkbox to enable/disable images
- updateImageCount() tried to spread customImages as array
- But customImages was object with task/consequence properties

Fix ensures compatibility with both data formats for smooth migration.
2025-09-25 20:31:21 -05:00
fritzsenpai 0a7bcc91e9 Final interface cleanup and improvements
Interface updates:
- Removed 'Open Image Folders' button - functionality wasn't implemented
- Updated Storage Info to show desktop vs web-specific information
- Desktop mode now shows unlimited storage info with file system details
- Web mode shows traditional browser storage limitations

Storage Info improvements:
- Shows image counts by category (tasks/consequences)
- Desktop version highlights unlimited storage benefits
- Clearer information about native file system vs browser storage
- Better visual organization with emojis and sections

.gitignore updates:
- Added comprehensive image file exclusions (jpg, png, gif, webp, etc.)
- Added audio file exclusions (mp3, wav, ogg, m4a, etc.)
- Excluded user imported images directories (images/tasks/*, images/consequences/*)
- Prevents user content from being committed to repo

Benefits:
- Cleaner interface with fewer non-functional buttons
- Context-aware storage information based on platform
- Better repository hygiene by excluding user content files
2025-09-25 20:28:48 -05:00
fritzsenpai 18d0f8bba2 Clean up image management interface
Automatic scanning and button cleanup:
- Added automatic directory scanning on desktop app startup
- Removed manual 'Scan Image Directories' button - no longer needed
- Removed 'Clear Image Cache' button - functionality not useful in desktop mode
- Updated scan info text to reflect automatic scanning behavior
- Cleaned up setupImageManagementEventListeners by removing unused button handlers

Benefits:
- Cleaner, more streamlined interface
- Images automatically available without manual intervention
- Reduced cognitive load - fewer buttons to understand
- More professional desktop application experience
2025-09-25 20:24:57 -05:00
fritzsenpai ba4e532322 Fix automatic gallery refresh after image import
- Changed updateImageGalleryControls() to loadImageGallery() in import handlers
- Now gallery refreshes automatically after importing task or consequence images
- Also fixed scan button to refresh gallery after directory scanning
- No more need to navigate away and back to see newly imported images

Gallery now updates immediately showing:
- Newly imported images in the correct category tabs
- Updated image counts and selections
- Real-time visual feedback for successful imports
2025-09-25 20:21:07 -05:00
fritzsenpai 45adf1b757 Fix desktop application errors
Security and functionality fixes:
- Added Content Security Policy to index.html to address Electron security warning
- Fixed function name errors: updateImageGallery() -> updateImageGalleryControls()
- Enhanced error handling in desktop-file-manager.js path operations
- Added null checks for directory initialization to prevent undefined path errors
- Fixed category mapping for task/consequence directory access
- Improved error logging and user feedback for file operations

Fixes resolve:
- Electron CSP security warnings
- TypeError with undefined path arguments
- Missing function reference errors
- Desktop import button functionality
2025-09-25 20:17:30 -05:00
fritzsenpai 1aed657e74 Integrate desktop file manager with UI
Updates:
- Enhanced setupImageManagementEventListeners with desktop import buttons
- Added event handlers for Import Task Images and Import Consequence Images
- Integrated desktop file manager scanning with existing scan button
- Added desktop-specific CSS styling and responsive layouts
- Implemented desktop/web mode detection and UI adaptation

Desktop Features:
- Native file import dialogs for task and consequence images
- Seamless integration with existing image management system
- Desktop-optimized button layouts and hover effects
- Automatic UI adaptation based on Electron vs browser detection

UI Improvements:
- Enhanced button styling for desktop application
- Responsive upload controls with proper spacing
- Desktop-only elements hidden in web mode
- Professional desktop application appearance
2025-09-25 20:11:10 -05:00
fritzsenpai 8e7cf0d4bf Refactor to desktop application with Electron
Major Changes:
- Convert web game to cross-platform desktop app using Electron
- Add complete desktop file management system
- Implement native file dialogs and unlimited storage
- Create secure IPC bridge for file operations

New Files Added:
- main.js: Electron main process with native OS integration
- preload.js: Secure IPC bridge between main and renderer
- desktop-file-manager.js: Full file system access and operations
- package.json: Electron dependencies and build configuration
- setup.bat/setup.sh: Installation scripts for all platforms
- README-DESKTOP.md: Comprehensive desktop application guide

Desktop Features:
- Native file import dialogs (no browser limitations)
- Unlimited disk space for image storage
- Direct folder access and file management
- Cross-platform builds (Windows/Mac/Linux)
- Full offline functionality
- Native performance without web constraints

Benefits:
- Solves browser security sandbox limitations
- Unlimited image storage using file system
- Professional native application experience
- Easy installation and distribution
- True cross-platform compatibility
2025-09-25 20:07:45 -05:00
fritzsenpai 1879a8970f Initial commit: Task Challenge Game v1.4
Core Features:
- Complete task management game with point system
- Theme system with multiple visual styles
- Background music with playlist controls
- Comprehensive keyboard shortcuts (Enter/Ctrl/Shift+Ctrl/Space/P/M/H/Escape)

Image Management System:
- Categorized upload system (Task/Consequence images)
- High-quality image processing (1600x1200, 95% quality)
- Batch operations (select all, delete multiple)
- Storage quota management (50 image limit)
- Support for JPG/PNG/WebP up to 20MB

Technical Architecture:
- DataManager class for localStorage management
- TaskChallengeGame main controller
- Canvas-based image compression
- Cross-browser compatibility
- No dependencies - pure HTML/CSS/JS

Data Management:
- Local storage with auto-migration
- Export/import functionality
- Statistics tracking
- Game state persistence
2025-09-25 19:41:06 -05:00