433 lines
16 KiB
JavaScript
433 lines
16 KiB
JavaScript
/**
|
||
* SystemsTestScene.js
|
||
* Test environment for all game systems
|
||
* NO SPRITES REQUIRED - Console-based testing
|
||
* Created: January 4, 2026
|
||
*/
|
||
|
||
|
||
|
||
|
||
class SystemsTestScene extends Phaser.Scene {
|
||
constructor() {
|
||
super({ key: 'SystemsTestScene' });
|
||
}
|
||
|
||
create() {
|
||
console.log('🧪 === SYSTEMS TEST SCENE LOADING ===');
|
||
|
||
// Black background
|
||
this.cameras.main.setBackgroundColor('#000000');
|
||
|
||
// Initialize mock player
|
||
this.initializeMockPlayer();
|
||
|
||
// Initialize master systems
|
||
this.initializeSystems();
|
||
|
||
// Create test UI
|
||
this.createTestUI();
|
||
|
||
// Setup keyboard controls
|
||
this.setupControls();
|
||
|
||
// Auto-run basic tests
|
||
this.runBasicTests();
|
||
|
||
console.log('✅ Systems Test Scene Ready!');
|
||
console.log('📌 Access systems: window.testSystems or game.scene.scenes[0].masterSystems');
|
||
}
|
||
|
||
initializeMockPlayer() {
|
||
// Create mock player object
|
||
this.player = {
|
||
energy: 50,
|
||
maxEnergy: 100,
|
||
money: 10000,
|
||
farmLevel: 1,
|
||
isMarried: false,
|
||
spouse: null,
|
||
farmhouseLevel: 0,
|
||
|
||
// Mock inventory
|
||
inventory: {
|
||
items: new Map(),
|
||
addItem: function (itemId, amount) {
|
||
const current = this.items.get(itemId) || 0;
|
||
this.items.set(itemId, current + amount);
|
||
console.log(` 📦 Added ${amount}x ${itemId} (total: ${current + amount})`);
|
||
},
|
||
removeItem: function (itemId, amount) {
|
||
const current = this.items.get(itemId) || 0;
|
||
const newAmount = Math.max(0, current - amount);
|
||
this.items.set(itemId, newAmount);
|
||
console.log(` 📦 Removed ${amount}x ${itemId} (total: ${newAmount})`);
|
||
},
|
||
hasItem: function (itemId) {
|
||
return this.items.has(itemId) && this.items.get(itemId) > 0;
|
||
},
|
||
getItemCount: function (itemId) {
|
||
return this.items.get(itemId) || 0;
|
||
}
|
||
},
|
||
|
||
// Mock methods
|
||
hasCompletedQuest: function (questId) {
|
||
return this.completedQuests.includes(questId);
|
||
},
|
||
hasBuilding: function (buildingId) {
|
||
return this.buildings.includes(buildingId);
|
||
},
|
||
hasMaterials: function (materials) {
|
||
for (const [item, amount] of Object.entries(materials)) {
|
||
if (this.inventory.getItemCount(item) < amount) {
|
||
return false;
|
||
}
|
||
}
|
||
return true;
|
||
},
|
||
removeMaterials: function (materials) {
|
||
for (const [item, amount] of Object.entries(materials)) {
|
||
this.inventory.removeItem(item, amount);
|
||
}
|
||
},
|
||
getRelationshipHearts: function (npcId) {
|
||
return this.relationships[npcId] || 0;
|
||
},
|
||
getRelationshipLevel: function (npcId) {
|
||
return this.relationships[npcId] || 0;
|
||
},
|
||
getSkillLevel: function (skill) {
|
||
return this.skills[skill] || 0;
|
||
},
|
||
hasMetNPC: function (npcId) {
|
||
return this.metNPCs.includes(npcId);
|
||
},
|
||
getPosition: function () {
|
||
return { x: 512, y: 384 };
|
||
},
|
||
rebuildSprite: function (appearance) {
|
||
console.log(' 👤 Player sprite rebuilt:', appearance);
|
||
},
|
||
teleportToLocation: function (location) {
|
||
console.log(` 🚪 Teleported to: ${location}`);
|
||
},
|
||
|
||
// Data
|
||
completedQuests: [],
|
||
buildings: [],
|
||
metNPCs: ['kai', 'ana', 'gronk'],
|
||
relationships: { kai: 5, ana: 10, gronk: 3 },
|
||
skills: { farming: 2, combat: 1, alchemy: 0 },
|
||
debt: 0
|
||
};
|
||
|
||
// Expose to window for console access
|
||
window.testPlayer = this.player;
|
||
|
||
// Mock game object
|
||
this.game.player = this.player;
|
||
|
||
console.log(' ✓ Mock player created');
|
||
}
|
||
|
||
initializeSystems() {
|
||
try {
|
||
// Initialize Master Systems Manager
|
||
this.masterSystems = new MasterGameSystemsManager(this);
|
||
|
||
// Expose to window for console access
|
||
window.testSystems = this.masterSystems;
|
||
|
||
console.log(' ✓ Master Systems Manager initialized');
|
||
console.log(' ✓ All 9 systems loaded');
|
||
|
||
} catch (error) {
|
||
console.error('❌ Error initializing systems:', error);
|
||
this.showError('System initialization failed: ' + error.message);
|
||
}
|
||
}
|
||
|
||
createTestUI() {
|
||
// Title
|
||
this.add.text(512, 40, '🧪 SYSTEMS TEST SCENE', {
|
||
fontSize: '36px',
|
||
color: '#00ff00',
|
||
fontFamily: 'monospace',
|
||
fontStyle: 'bold'
|
||
}).setOrigin(0.5);
|
||
|
||
// Status panel
|
||
const statusText = [
|
||
'═══════════════════════════════════════════════════════════',
|
||
'SYSTEMS STATUS:',
|
||
'✅ Sleep System: Ready',
|
||
'✅ Crafting Tables: Ready',
|
||
'✅ Bakery Shop: Ready',
|
||
'✅ Barber Shop: Ready',
|
||
'✅ Lawyer Office: Ready',
|
||
'✅ Zombie Miners: Ready',
|
||
'✅ Town Growth: Ready',
|
||
'✅ NPC Privacy: Ready',
|
||
'✅ Master Coordinator: Ready',
|
||
'═══════════════════════════════════════════════════════════'
|
||
].join('\n');
|
||
|
||
this.statusPanel = this.add.text(50, 100, statusText, {
|
||
fontSize: '14px',
|
||
color: '#00ff00',
|
||
fontFamily: 'monospace',
|
||
lineSpacing: 3
|
||
});
|
||
|
||
// Instructions
|
||
const instructions = [
|
||
'',
|
||
'🎮 KEYBOARD CONTROLS:',
|
||
' [1] - Test Sleep System',
|
||
' [2] - Test Crafting System',
|
||
' [3] - Test Bakery Shop',
|
||
' [4] - Test Town Growth',
|
||
' [5] - Test Save/Load',
|
||
' [R] - Run All Tests',
|
||
' [ESC] - Return to Main Menu',
|
||
'',
|
||
'💻 CONSOLE ACCESS:',
|
||
' window.testSystems → All systems',
|
||
' window.testPlayer → Mock player',
|
||
' Quick: const s = window.testSystems;',
|
||
'',
|
||
'📝 EXAMPLE COMMANDS:',
|
||
' s.sleepSystem.sleep()',
|
||
' s.craftingSystem.canCraft("wooden_hoe")',
|
||
' s.townGrowthSystem.population',
|
||
' s.saveAllSystems()',
|
||
'',
|
||
'Press [1-5] to run tests or open browser console!'
|
||
].join('\n');
|
||
|
||
this.add.text(50, 340, instructions, {
|
||
fontSize: '13px',
|
||
color: '#ffff00',
|
||
fontFamily: 'monospace',
|
||
lineSpacing: 2
|
||
});
|
||
|
||
// Test results panel
|
||
this.testResultsY = 100;
|
||
this.testResults = [];
|
||
}
|
||
|
||
setupControls() {
|
||
// ESC to exit
|
||
this.input.keyboard.on('keydown-ESC', () => {
|
||
console.log('Returning to PreloadScene...');
|
||
this.scene.start('PreloadScene');
|
||
});
|
||
|
||
// Number keys for tests
|
||
this.input.keyboard.on('keydown-ONE', () => this.testSleepSystem());
|
||
this.input.keyboard.on('keydown-TWO', () => this.testCraftingSystem());
|
||
this.input.keyboard.on('keydown-THREE', () => this.testBakerySystem());
|
||
this.input.keyboard.on('keydown-FOUR', () => this.testTownGrowth());
|
||
this.input.keyboard.on('keydown-FIVE', () => this.testSaveLoad());
|
||
this.input.keyboard.on('keydown-R', () => this.runAllTests());
|
||
}
|
||
|
||
runBasicTests() {
|
||
console.log('\n🔬 === RUNNING BASIC TESTS ===\n');
|
||
|
||
// Test 1: Systems exist
|
||
console.log('TEST 1: Systems Initialization');
|
||
console.log(' Sleep System:', this.masterSystems.sleepSystem ? '✅' : '❌');
|
||
console.log(' Crafting System:', this.masterSystems.craftingSystem ? '✅' : '❌');
|
||
console.log(' Bakery System:', this.masterSystems.bakerySystem ? '✅' : '❌');
|
||
console.log(' Barber System:', this.masterSystems.barberSystem ? '✅' : '❌');
|
||
console.log(' Lawyer System:', this.masterSystems.lawyerSystem ? '✅' : '❌');
|
||
console.log(' Zombie Miners:', this.masterSystems.zombieMinerSystem ? '✅' : '❌');
|
||
console.log(' Town Growth:', this.masterSystems.townGrowthSystem ? '✅' : '❌');
|
||
console.log(' NPC Privacy:', this.masterSystems.npcPrivacySystem ? '✅' : '❌');
|
||
|
||
// Test 2: Mock player
|
||
console.log('\nTEST 2: Mock Player');
|
||
console.log(' Energy:', this.player.energy + '/' + this.player.maxEnergy, '✅');
|
||
console.log(' Money:', this.player.money + 'g', '✅');
|
||
console.log(' Inventory:', this.player.inventory ? '✅' : '❌');
|
||
|
||
console.log('\n✅ Basic tests complete!\n');
|
||
}
|
||
|
||
testSleepSystem() {
|
||
console.log('\n🌙 === TESTING SLEEP SYSTEM ===\n');
|
||
|
||
const sleep = this.masterSystems.sleepSystem;
|
||
|
||
// Test 1: Can sleep check
|
||
const canSleep = sleep.canSleepNow();
|
||
console.log('TEST 1: Can Sleep Now?', canSleep.canSleep ? '✅' : '❌', canSleep.message || '');
|
||
|
||
// Test 2: Current bed info
|
||
const bedInfo = sleep.getCurrentBedInfo();
|
||
console.log('TEST 2: Current Bed:', bedInfo.name, '✅');
|
||
console.log(' Energy Regen:', bedInfo.energyRegen + '%');
|
||
|
||
// Test 3: Try to sleep
|
||
console.log('TEST 3: Attempting Sleep...');
|
||
const result = sleep.sleep();
|
||
console.log(' Result:', result.success ? '✅ SUCCESS' : '❌ FAILED', result.message || '');
|
||
|
||
console.log('\n✅ Sleep System tests complete!\n');
|
||
}
|
||
|
||
testCraftingSystem() {
|
||
console.log('\n🔨 === TESTING CRAFTING SYSTEM ===\n');
|
||
|
||
const crafting = this.masterSystems.craftingSystem;
|
||
|
||
// Test 1: Check recipe without ingredients
|
||
console.log('TEST 1: Can craft wooden_hoe (no ingredients)?');
|
||
let check = crafting.canCraft('wooden_hoe');
|
||
console.log(' Result:', check.canCraft ? '✅' : '❌', check.reason || '');
|
||
if (check.missingIngredients) {
|
||
console.log(' Missing:', JSON.stringify(check.missingIngredients));
|
||
}
|
||
|
||
// Test 2: Add ingredients
|
||
console.log('\nTEST 2: Adding ingredients...');
|
||
this.player.inventory.addItem('wood', 20);
|
||
this.player.inventory.addItem('rope', 5);
|
||
|
||
// Test 3: Check recipe with ingredients
|
||
console.log('\nTEST 3: Can craft wooden_hoe (with ingredients)?');
|
||
check = crafting.canCraft('wooden_hoe');
|
||
console.log(' Result:', check.canCraft ? '✅ CAN CRAFT' : '❌ CANNOT CRAFT');
|
||
|
||
// Test 4: Try crafting
|
||
if (check.canCraft) {
|
||
console.log('\nTEST 4: Crafting wooden_hoe...');
|
||
const result = crafting.craft('wooden_hoe', 1);
|
||
console.log(' Result:', result.success ? '✅ SUCCESS' : '❌ FAILED');
|
||
console.log(' Message:', result.message);
|
||
}
|
||
|
||
console.log('\n✅ Crafting System tests complete!\n');
|
||
}
|
||
|
||
testBakerySystem() {
|
||
console.log('\n🥖 === TESTING BAKERY SYSTEM ===\n');
|
||
|
||
const bakery = this.masterSystems.bakerySystem;
|
||
|
||
// Test 1: Shop status
|
||
console.log('TEST 1: Bakery Status');
|
||
const shopData = bakery.getShopUIData();
|
||
console.log(' Unlocked:', shopData.isUnlocked ? '✅' : '❌');
|
||
console.log(' Open:', shopData.isOpen ? '✅' : '❌');
|
||
|
||
// Test 2: Try to buy item
|
||
console.log('\nTEST 2: Buying fresh_bread...');
|
||
const result = bakery.buyItem('fresh_bread', 2);
|
||
console.log(' Result:', result.success ? '✅ SUCCESS' : '❌ FAILED');
|
||
console.log(' Message:', result.message || 'Item purchased');
|
||
|
||
console.log('\n✅ Bakery System tests complete!\n');
|
||
}
|
||
|
||
testTownGrowth() {
|
||
console.log('\n🏘️ === TESTING TOWN GROWTH SYSTEM ===\n');
|
||
|
||
const town = this.masterSystems.townGrowthSystem;
|
||
|
||
// Test 1: Current population
|
||
console.log('TEST 1: Population Status');
|
||
console.log(' Current:', town.population + '/' + town.maxPopulation, '✅');
|
||
console.log(' Status:', town.getTownStatus(), '✅');
|
||
|
||
// Test 2: Check unlock requirements
|
||
console.log('\nTEST 2: Population Slot Requirements');
|
||
let unlockedCount = 0;
|
||
let lockedCount = 0;
|
||
town.populationSlots.forEach((slot, index) => {
|
||
if (slot.unlocked) {
|
||
unlockedCount++;
|
||
} else {
|
||
lockedCount++;
|
||
if (index < 10) { // Show first few
|
||
console.log(` Slot ${index}:`, JSON.stringify(slot.requirement));
|
||
}
|
||
}
|
||
});
|
||
console.log(' Unlocked:', unlockedCount, '✅');
|
||
console.log(' Locked:', lockedCount, '✅');
|
||
|
||
// Test 3: Check for new unlocks
|
||
console.log('\nTEST 3: Checking for new unlocks...');
|
||
const newUnlocks = town.checkPopulationUnlocks();
|
||
console.log(' New slots unlocked:', newUnlocks, '✅');
|
||
|
||
console.log('\n✅ Town Growth tests complete!\n');
|
||
}
|
||
|
||
testSaveLoad() {
|
||
console.log('\n💾 === TESTING SAVE/LOAD SYSTEM ===\n');
|
||
|
||
// Test 1: Save all systems
|
||
console.log('TEST 1: Saving all systems...');
|
||
const saveData = this.masterSystems.saveAllSystems();
|
||
console.log(' Save data created:', saveData ? '✅' : '❌');
|
||
console.log(' Systems saved:', Object.keys(saveData.systems).length);
|
||
|
||
// Test 2: Store in localStorage
|
||
console.log('\nTEST 2: Storing to localStorage...');
|
||
try {
|
||
localStorage.setItem('game_save_test', JSON.stringify(saveData));
|
||
console.log(' Stored successfully ✅');
|
||
} catch (error) {
|
||
console.error(' Storage failed ❌', error);
|
||
}
|
||
|
||
// Test 3: Modify state
|
||
console.log('\nTEST 3: Modifying state...');
|
||
const originalMoney = this.player.money;
|
||
this.player.money = 999999;
|
||
console.log(' Money changed:', originalMoney, '→', this.player.money, '✅');
|
||
|
||
// Test 4: Load from localStorage
|
||
console.log('\nTEST 4: Loading from localStorage...');
|
||
try {
|
||
const loadedData = JSON.parse(localStorage.getItem('game_save_test'));
|
||
this.masterSystems.loadAllSystems(loadedData);
|
||
console.log(' Loaded successfully ✅');
|
||
} catch (error) {
|
||
console.error(' Load failed ❌', error);
|
||
}
|
||
|
||
console.log('\n✅ Save/Load tests complete!\n');
|
||
}
|
||
|
||
runAllTests() {
|
||
console.log('\n🔬 === RUNNING ALL TESTS ===\n');
|
||
this.testSleepSystem();
|
||
this.testCraftingSystem();
|
||
this.testBakerySystem();
|
||
this.testTownGrowth();
|
||
this.testSaveLoad();
|
||
console.log('\n✅ ALL TESTS COMPLETE!\n');
|
||
}
|
||
|
||
showError(message) {
|
||
this.add.text(512, 600, '❌ ERROR: ' + message, {
|
||
fontSize: '18px',
|
||
color: '#ff0000',
|
||
fontFamily: 'monospace'
|
||
}).setOrigin(0.5);
|
||
}
|
||
|
||
update(time, delta) {
|
||
// Update master systems
|
||
if (this.masterSystems) {
|
||
this.masterSystems.update(time, delta);
|
||
}
|
||
}
|
||
}
|