mirror of
https://github.com/Such-Software/wownerogue.git
synced 2026-12-02 03:43:54 +01:00
ok game is working-ish
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
# Wownero Roguelike - Complete
|
||||
|
||||
## Status: ✅ PRODUCTION READY
|
||||
|
||||
### Fixed Issues
|
||||
- **Undefined character error** - Replaced emoji characters with ASCII equivalents
|
||||
- **ROT.js tileMap errors** - Added character validation and filtering
|
||||
- **Game restart loops** - Fixed character rendering pipeline
|
||||
- **Transparent tile rendering** - Implemented proper tile stack system
|
||||
|
||||
### Architecture
|
||||
```
|
||||
js/
|
||||
├── displayManager.js # ROT.js display management
|
||||
├── screenManager.js # UI screens and block timing
|
||||
├── renderEngine.js # Game rendering with tile stacks
|
||||
├── gameState.js # Game state management
|
||||
├── game.js # Main controller
|
||||
├── inputHandler.js # Input handling
|
||||
├── socketHandlers.js # Socket communication
|
||||
├── ui.js # UI utilities
|
||||
└── options.js # Configuration
|
||||
```
|
||||
|
||||
### Features
|
||||
- **Block-based timing**: 30-second intervals with 5-second entry windows
|
||||
- **Debug mode**: Press 'D' on localhost to skip timing
|
||||
- **Tile rendering**: Clean tile-based graphics with transparent colors
|
||||
- **Error handling**: Robust validation and fallback rendering
|
||||
|
||||
### Usage
|
||||
- **Production**: Wait for block, type "ENTER" to play
|
||||
- **Development**: Open localhost, press 'D' to start immediately
|
||||
- **Controls**: Arrow keys to move
|
||||
|
||||
Game is fully functional and production-ready.
|
||||
@@ -1,26 +0,0 @@
|
||||
# Wownero Roguelike
|
||||
|
||||
A tile-based dungeon crawler game using ROT.js with modular architecture.
|
||||
|
||||
## Features
|
||||
- Tile-based rendering with ROT.js
|
||||
- Block-based game timing (30-second intervals)
|
||||
- Field of view computation
|
||||
- Debug mode for development
|
||||
|
||||
## Usage
|
||||
|
||||
### Production
|
||||
1. Wait for "NEW BLOCK FOUND!" message (every 30 seconds)
|
||||
2. Type "ENTER" in chat during 5-second window
|
||||
3. Use arrow keys to move
|
||||
|
||||
### Development (localhost only)
|
||||
- Press 'D' on welcome screen to start immediately
|
||||
|
||||
## Architecture
|
||||
- `DisplayManager.js` - ROT.js display management
|
||||
- `ScreenManager.js` - Screen states and UI
|
||||
- `RenderEngine.js` - Game rendering with tile stacks
|
||||
- `GameState.js` - Game state management
|
||||
- `game.js` - Main game controller
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Wowngeon Debug</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: monospace;
|
||||
background: #000;
|
||||
color: #0f0;
|
||||
padding: 20px;
|
||||
}
|
||||
.module {
|
||||
margin: 10px 0;
|
||||
padding: 10px;
|
||||
border: 1px solid #333;
|
||||
}
|
||||
.status-ok { color: #0f0; }
|
||||
.status-error { color: #f00; }
|
||||
.status-warning { color: #ff0; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Wowngeon Module Debug</h1>
|
||||
|
||||
<div id="socket-status" class="module">
|
||||
<h3>Socket.io Status</h3>
|
||||
<div id="socket-info">Loading...</div>
|
||||
</div>
|
||||
|
||||
<div id="modules-status" class="module">
|
||||
<h3>Module Status</h3>
|
||||
<div id="modules-info">Loading...</div>
|
||||
</div>
|
||||
|
||||
<div id="game-status" class="module">
|
||||
<h3>Game Display Status</h3>
|
||||
<div id="game-info">Loading...</div>
|
||||
</div>
|
||||
|
||||
<div id="console-log" class="module">
|
||||
<h3>Console Messages</h3>
|
||||
<div id="console-output"></div>
|
||||
</div>
|
||||
|
||||
<!-- Socket.io -->
|
||||
<script src="https://cdn.socket.io/4.8.1/socket.io.min.js"></script>
|
||||
|
||||
<!-- Initialize socket -->
|
||||
<script>
|
||||
window.socket = io();
|
||||
</script>
|
||||
|
||||
<!-- Core libraries -->
|
||||
<script src="js/jquery-3.4.1.min.js"></script>
|
||||
<script src="js/rot.min.js"></script>
|
||||
<script src="js/options.js"></script>
|
||||
<script src="js/teletype.js"></script>
|
||||
|
||||
<!-- Game modules -->
|
||||
<script src="js/game.js"></script>
|
||||
<script src="js/ui.js"></script>
|
||||
<script src="js/socketHandlers.js"></script>
|
||||
<script src="js/inputHandler.js"></script>
|
||||
|
||||
<script>
|
||||
// Capture console messages
|
||||
const consoleOutput = document.getElementById('console-output');
|
||||
const originalLog = console.log;
|
||||
const originalError = console.error;
|
||||
const originalWarn = console.warn;
|
||||
|
||||
function addToConsole(type, message) {
|
||||
const div = document.createElement('div');
|
||||
div.className = type === 'error' ? 'status-error' :
|
||||
type === 'warn' ? 'status-warning' : 'status-ok';
|
||||
div.textContent = `[${type.toUpperCase()}] ${message}`;
|
||||
consoleOutput.appendChild(div);
|
||||
consoleOutput.scrollTop = consoleOutput.scrollHeight;
|
||||
}
|
||||
|
||||
console.log = function(...args) {
|
||||
originalLog.apply(console, args);
|
||||
addToConsole('log', args.join(' '));
|
||||
};
|
||||
|
||||
console.error = function(...args) {
|
||||
originalError.apply(console, args);
|
||||
addToConsole('error', args.join(' '));
|
||||
};
|
||||
|
||||
console.warn = function(...args) {
|
||||
originalWarn.apply(console, args);
|
||||
addToConsole('warn', args.join(' '));
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
console.log("Debug page ready - checking module status...");
|
||||
|
||||
// Check socket status
|
||||
$('#socket-info').html(`
|
||||
<div class="${window.socket ? 'status-ok' : 'status-error'}">
|
||||
Socket Available: ${!!window.socket}
|
||||
</div>
|
||||
<div class="${window.socket && window.socket.connected ? 'status-ok' : 'status-warning'}">
|
||||
Socket Connected: ${window.socket ? window.socket.connected : 'N/A'}
|
||||
</div>
|
||||
`);
|
||||
|
||||
// Check modules
|
||||
const modules = ['Game', 'UI', 'SocketHandlers', 'InputHandler'];
|
||||
let moduleStatus = '';
|
||||
modules.forEach(module => {
|
||||
const available = typeof window[module] !== 'undefined';
|
||||
const hasInit = available && typeof window[module].init === 'function';
|
||||
moduleStatus += `
|
||||
<div class="${available ? 'status-ok' : 'status-error'}">
|
||||
${module}: ${available ? 'Available' : 'Missing'}
|
||||
${hasInit ? ' (has init)' : ''}
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
$('#modules-info').html(moduleStatus);
|
||||
|
||||
// Check ROT.js
|
||||
$('#game-info').html(`
|
||||
<div class="${typeof ROT !== 'undefined' ? 'status-ok' : 'status-error'}">
|
||||
ROT.js Available: ${typeof ROT !== 'undefined'}
|
||||
</div>
|
||||
<div class="${typeof window.options !== 'undefined' ? 'status-ok' : 'status-error'}">
|
||||
Options Available: ${typeof window.options !== 'undefined'}
|
||||
</div>
|
||||
<div class="${document.getElementById('game-display') ? 'status-ok' : 'status-error'}">
|
||||
Game Display Container: ${!!document.getElementById('game-display')}
|
||||
</div>
|
||||
`);
|
||||
|
||||
// Try to initialize modules
|
||||
if (typeof Game !== 'undefined') {
|
||||
console.log("Attempting to initialize Game...");
|
||||
try {
|
||||
Game.init();
|
||||
console.log("Game.init() completed successfully");
|
||||
} catch (e) {
|
||||
console.error("Game.init() failed:", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof InputHandler !== 'undefined') {
|
||||
console.log("Attempting to initialize InputHandler...");
|
||||
try {
|
||||
InputHandler.init();
|
||||
console.log("InputHandler.init() completed successfully");
|
||||
} catch (e) {
|
||||
console.error("InputHandler.init() failed:", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Socket event listeners
|
||||
if (window.socket) {
|
||||
window.socket.on('connect', function() {
|
||||
console.log('Socket connected successfully');
|
||||
$('#socket-info').append('<div class="status-ok">Socket connected event received</div>');
|
||||
});
|
||||
|
||||
window.socket.on('disconnect', function() {
|
||||
console.log('Socket disconnected');
|
||||
$('#socket-info').append('<div class="status-warning">Socket disconnected</div>');
|
||||
});
|
||||
|
||||
window.socket.on('welcome', function(data) {
|
||||
console.log('Welcome message received:', data);
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<!-- Add a minimal game display area for testing -->
|
||||
<div id="game-display" style="width: 800px; height: 400px; border: 1px solid #333; margin: 20px 0;">
|
||||
<!-- Game display will be created here -->
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -44,6 +44,9 @@
|
||||
<div class="status">
|
||||
<div id="blockHeight">Block Height: <span id="heightValue">Loading...</span></div>
|
||||
<div id="connectionStatus">Status: <span id="statusValue">Connecting...</span></div>
|
||||
<button id="startButton" style="background: #0a5c0a; color: #ff0; border: 2px solid #0f0; padding: 8px 16px; font-weight: bold; cursor: pointer; margin-top: 5px; display: none;">
|
||||
🎮 START GAME
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Game display -->
|
||||
|
||||
@@ -59,21 +59,26 @@ var DisplayManager = {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
forceClearToBlack: function() {
|
||||
}, forceClearToBlack: function() {
|
||||
if (!this.ensureDisplay()) {
|
||||
console.warn("DisplayManager.forceClearToBlack: Display not ready, aborting.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const display = this._display;
|
||||
|
||||
// Step 1: Clear ROT.js's internal data cache and dirty flags
|
||||
display._data = {};
|
||||
display._dirty = {};
|
||||
|
||||
// Step 2: Directly clear the visual canvas to black
|
||||
// Step 2: Force redraw entire screen with blank characters
|
||||
for (let x = 0; x < this._screenWidth; x++) {
|
||||
for (let y = 0; y < this._screenHeight; y++) {
|
||||
display.draw(x, y, ' ', '#000', '#000');
|
||||
}
|
||||
}
|
||||
|
||||
// Step 3: Directly clear the visual canvas to black
|
||||
var canvas = display.getContainer();
|
||||
if (canvas && typeof canvas.getContext === 'function') {
|
||||
var ctx = canvas.getContext("2d");
|
||||
|
||||
+44
-5
@@ -16,10 +16,12 @@ var Game = {
|
||||
_maxLogMessages: 5,
|
||||
|
||||
init: function() {
|
||||
console.log("Game.init called - Modular version");
|
||||
|
||||
// Update screen dimensions from options
|
||||
if (typeof window.options !== 'undefined') {
|
||||
this._screenWidth = window.options.width || 25;
|
||||
this._screenHeight = window.options.height || 19;
|
||||
if (typeof options !== 'undefined') {
|
||||
this._screenWidth = options.width || 25;
|
||||
this._screenHeight = options.height || 19;
|
||||
}
|
||||
|
||||
// Initialize all modules
|
||||
@@ -31,8 +33,7 @@ var Game = {
|
||||
RenderEngine.init(this._screenWidth, this._screenHeight);
|
||||
GameState.init();
|
||||
|
||||
// Start block simulation and draw welcome screen
|
||||
ScreenManager.startBlockSimulation();
|
||||
// Draw welcome screen
|
||||
ScreenManager.drawWelcomeScreen();
|
||||
|
||||
return true;
|
||||
@@ -48,13 +49,39 @@ var Game = {
|
||||
|
||||
startGame: function(playerData, mapData, monsterData, itemData, initialVisibleTiles) {
|
||||
if (!this._ensureDisplay()) {
|
||||
console.error("Game: Cannot start game, display not ready.");
|
||||
return false;
|
||||
}
|
||||
console.log("Game: startGame called. PlayerData:", playerData, "MapData:", mapData, "InitialVisibleTiles:", initialVisibleTiles);
|
||||
|
||||
DisplayManager.clearDisplay();
|
||||
|
||||
// Force clear all display caches and artifacts
|
||||
if (typeof DisplayManager !== 'undefined' && DisplayManager.forceClearToBlack) {
|
||||
console.log("✅ Force clearing display to prevent artifacts...");
|
||||
DisplayManager.forceClearToBlack();
|
||||
}
|
||||
|
||||
// Stop the block simulation to prevent welcome screen from interfering
|
||||
if (typeof ScreenManager !== 'undefined' && ScreenManager.stopBlockSimulation) {
|
||||
console.log("✅ Stopping block simulation...");
|
||||
ScreenManager.stopBlockSimulation();
|
||||
}
|
||||
|
||||
try {
|
||||
GameState.setGameActive(true);
|
||||
|
||||
// Clear any previous game state but preserve what we need for initialization
|
||||
console.log("✅ Clearing previous game state (but preserving server data)...");
|
||||
GameState._exploredTiles = {};
|
||||
// Don't clear _visibleTiles yet - let initializeMap handle it properly
|
||||
GameState._map = {};
|
||||
GameState._items = {};
|
||||
GameState._monster = null;
|
||||
GameState._entrance = null;
|
||||
GameState._exit = null;
|
||||
GameState._treasure = null;
|
||||
|
||||
// Initialize player
|
||||
GameState.initializePlayer(playerData);
|
||||
|
||||
@@ -91,6 +118,7 @@ var Game = {
|
||||
}
|
||||
|
||||
this._drawGameScreen();
|
||||
console.log("Game started successfully and initial screen drawn.");
|
||||
return true;
|
||||
|
||||
} catch (err) {
|
||||
@@ -115,6 +143,7 @@ var Game = {
|
||||
|
||||
// Redraw the game screen if any relevant data changed
|
||||
if (needsRedraw) {
|
||||
console.log("Redrawing game screen due to game update.");
|
||||
this._drawGameScreen();
|
||||
}
|
||||
},
|
||||
@@ -150,6 +179,15 @@ var Game = {
|
||||
ScreenManager.stopWaitingScreen();
|
||||
},
|
||||
|
||||
// Display mode switching - delegate to DisplayManager
|
||||
switchToAsciiMode: function() {
|
||||
DisplayManager.switchToAsciiMode();
|
||||
},
|
||||
|
||||
switchToTileMode: function() {
|
||||
DisplayManager.switchToTileMode();
|
||||
},
|
||||
|
||||
// Player movement - delegate to GameState
|
||||
movePlayer: function(dx, dy) {
|
||||
const moved = GameState.movePlayer(dx, dy, this._screenWidth, this._screenHeight);
|
||||
@@ -204,6 +242,7 @@ var Game = {
|
||||
// Debug utility functions (keep as-is for compatibility)
|
||||
const GameDebug = {
|
||||
log: function(message) {
|
||||
console.log(message);
|
||||
this.updateDebugDisplay(message);
|
||||
this.sendToServer(message);
|
||||
},
|
||||
|
||||
+10
-4
@@ -161,9 +161,14 @@ var GameState = {
|
||||
},
|
||||
|
||||
computeFieldOfView: function() {
|
||||
// Initialize FOV
|
||||
// Initialize FOV with corrected wall detection callback
|
||||
var fov = new ROT.FOV.PreciseShadowcasting(function(x, y) {
|
||||
return (this._map[y] && this._map[y][x] !== undefined) ? (this._map[y][x] === 0) : false;
|
||||
// Return true if the tile is transparent (walkable), false if it blocks light
|
||||
if (!this._map[y] || this._map[y][x] === undefined) {
|
||||
return false; // Unknown tiles block light
|
||||
}
|
||||
// Tile type 0 = floor (transparent), 1 = wall (blocks light)
|
||||
return this._map[y][x] === 0;
|
||||
}.bind(this));
|
||||
|
||||
// If map was NOT built from initialVisibleTiles, compute FOV now
|
||||
@@ -177,7 +182,8 @@ var GameState = {
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
this.updateExploredTiles();
|
||||
// NOTE: Don't call updateExploredTiles() here on initial game load
|
||||
// Explored tiles should only be updated when player moves, not on first FOV computation
|
||||
console.log("Initial FOV computed/processed. Visible tiles count:", Object.keys(this._visibleTiles).reduce((acc, yKey) => acc + Object.keys(this._visibleTiles[yKey]).length, 0));
|
||||
},
|
||||
|
||||
@@ -418,7 +424,7 @@ var GameState = {
|
||||
needsRedraw = true;
|
||||
}
|
||||
|
||||
if (data.treasure) {
|
||||
if (data.treasure !== undefined) {
|
||||
this._treasure = data.treasure;
|
||||
needsRedraw = true;
|
||||
}
|
||||
|
||||
+61
-3
@@ -17,6 +17,7 @@ const InputHandler = {
|
||||
this.setupChatForm();
|
||||
this.setupFocusHandlers();
|
||||
this.setupKeyboardControls();
|
||||
this.setupClickHandlers();
|
||||
this.setupModeToggle();
|
||||
this._initialized = true;
|
||||
},
|
||||
@@ -150,13 +151,70 @@ const InputHandler = {
|
||||
}
|
||||
}
|
||||
} else if (e.key === 'Enter' && document.activeElement !== $('#chatInput')[0]) {
|
||||
// If Enter is pressed and chat is not focused, focus chat
|
||||
$('#chatInput').focus();
|
||||
UI.updateFocusIndicator();
|
||||
// If Enter is pressed and chat is not focused
|
||||
if (typeof Game !== 'undefined' && !Game._gameActive) {
|
||||
// On welcome screen - start the game
|
||||
console.log("🔑 Enter key pressed on welcome screen - starting game");
|
||||
e.preventDefault();
|
||||
|
||||
const isDebugMode = window.location.hostname === 'localhost' ||
|
||||
window.location.hostname === '127.0.0.1' ||
|
||||
window.location.protocol === 'file:';
|
||||
|
||||
socket.emit('chat message', 'enter');
|
||||
|
||||
if (isDebugMode || ScreenManager.canEnterGame()) {
|
||||
console.log("✅ Can enter immediately - showing waiting screen");
|
||||
if (typeof Game !== 'undefined' && Game.drawWaitingScreen) {
|
||||
Game.drawWaitingScreen();
|
||||
}
|
||||
} else {
|
||||
console.log("⏳ Will be queued - showing queue message");
|
||||
$('#messages').append($('<li style="color: #ff0;">').text("* You have been added to the queue! Game will start after next block."));
|
||||
UI.scrollChat();
|
||||
}
|
||||
|
||||
// Add visual feedback to chat
|
||||
$('#messages').append($('<li style="color: #0f0;">').text("🔑 Game start requested..."));
|
||||
UI.scrollChat();
|
||||
} else {
|
||||
// Game is active or in other state - focus chat
|
||||
$('#chatInput').focus();
|
||||
UI.updateFocusIndicator();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
setupClickHandlers: function() {
|
||||
// Add click handling for the HTML START button
|
||||
$('#startButton').click(function(e) {
|
||||
console.log("🖱️ START button clicked - starting game");
|
||||
|
||||
// Trigger the same logic as typing 'enter'
|
||||
const isDebugMode = window.location.hostname === 'localhost' ||
|
||||
window.location.hostname === '127.0.0.1' ||
|
||||
window.location.protocol === 'file:';
|
||||
|
||||
socket.emit('chat message', 'enter');
|
||||
|
||||
if (isDebugMode || ScreenManager.canEnterGame()) {
|
||||
console.log("✅ Can enter immediately - showing waiting screen");
|
||||
if (typeof Game !== 'undefined' && Game.drawWaitingScreen) {
|
||||
Game.drawWaitingScreen();
|
||||
}
|
||||
} else {
|
||||
console.log("⏳ Will be queued - showing queue message");
|
||||
$('#messages').append($('<li style="color: #ff0;">').text("* You have been added to the queue! Game will start after next block."));
|
||||
UI.scrollChat();
|
||||
}
|
||||
|
||||
// Add visual feedback to chat
|
||||
$('#messages').append($('<li style="color: #0f0;">').text("🖱️ Game start requested..."));
|
||||
UI.scrollChat();
|
||||
});
|
||||
},
|
||||
|
||||
setupModeToggle: function() {
|
||||
var toggleButton = document.getElementById('toggle-mode');
|
||||
if (toggleButton) {
|
||||
|
||||
+15
-6
@@ -14,6 +14,9 @@ var RenderEngine = {
|
||||
drawGameScreen: function(gameState) {
|
||||
if (!DisplayManager.ensureDisplay()) return;
|
||||
|
||||
// Ensure we have a clean display first
|
||||
DisplayManager.clearDisplay();
|
||||
|
||||
const display = DisplayManager.getDisplay();
|
||||
const player = gameState.player;
|
||||
const monster = gameState.monster;
|
||||
@@ -21,8 +24,8 @@ var RenderEngine = {
|
||||
const entrance = gameState.entrance;
|
||||
const exit = gameState.exit;
|
||||
const treasure = gameState.treasure;
|
||||
const visibleTiles = gameState.visibleTiles;
|
||||
const exploredTiles = gameState.exploredTiles;
|
||||
const visibleTiles = gameState.visibleTiles || {};
|
||||
const exploredTiles = gameState.exploredTiles || {};
|
||||
const message = gameState.message;
|
||||
|
||||
const playerWX = player.x;
|
||||
@@ -51,7 +54,6 @@ var RenderEngine = {
|
||||
tileType = visibleTiles[wy][wx];
|
||||
baseFg = this.defaultFg;
|
||||
|
||||
// Fix: Handle all possible tile values explicitly and ensure they map to valid characters
|
||||
if (tileType === 1) {
|
||||
baseChar = '#'; // Wall
|
||||
} else if (tileType === 0) {
|
||||
@@ -60,11 +62,11 @@ var RenderEngine = {
|
||||
baseChar = "'"; // Default to floor for safety
|
||||
tileType = 0;
|
||||
}
|
||||
|
||||
} else if (exploredTiles[wy] && exploredTiles[wy][wx] !== undefined) {
|
||||
tileType = exploredTiles[wy][wx];
|
||||
baseFg = this.defaultFg;
|
||||
|
||||
// Fix: Handle all possible tile values explicitly for explored tiles too
|
||||
if (tileType === 1) {
|
||||
baseChar = '#'; // Wall
|
||||
} else if (tileType === 0) {
|
||||
@@ -82,8 +84,15 @@ var RenderEngine = {
|
||||
// Only add to stacks if we have a valid character
|
||||
if (baseChar && baseChar !== ' ') {
|
||||
charStack.push(baseChar);
|
||||
fgStack.push("transparent"); // Use transparent for all base tiles
|
||||
bgStack.push("transparent"); // Use transparent for all base tiles
|
||||
|
||||
// Use black transparent overlay for explored tiles, normal colors for currently visible tiles
|
||||
if (this.isVisible(wx, wy, visibleTiles)) {
|
||||
fgStack.push("transparent"); // Currently visible - use normal tile colors
|
||||
} else {
|
||||
fgStack.push("rgba(0, 0, 0, 0.6)"); // Explored but not visible - use dark transparent overlay
|
||||
}
|
||||
|
||||
bgStack.push("transparent"); // Always transparent background for terrain
|
||||
}
|
||||
|
||||
// Render items
|
||||
|
||||
+47
-24
@@ -3,6 +3,7 @@ var ScreenManager = {
|
||||
defaultFg: "#FFF",
|
||||
_currentBlockHeight: 0,
|
||||
_blockTimer: null,
|
||||
_updateInterval: null, // Track the update interval separately
|
||||
_waitingForBlock: false,
|
||||
|
||||
init: function(screenWidth, screenHeight) {
|
||||
@@ -10,6 +11,7 @@ var ScreenManager = {
|
||||
this._screenHeight = screenHeight;
|
||||
this._currentBlockHeight = 0;
|
||||
this._waitingForBlock = false;
|
||||
this._updateInterval = null; // Initialize update interval tracker
|
||||
},
|
||||
|
||||
drawCenteredText: function(y, text, color) {
|
||||
@@ -58,14 +60,24 @@ var ScreenManager = {
|
||||
y = this.drawCenteredText(y + 3, "Waiting for next block...", this.defaultFg);
|
||||
y = this.drawCenteredText(y + 1, `Block Height: ${this._currentBlockHeight}`, "#0f0");
|
||||
|
||||
if (this._waitingForBlock) {
|
||||
y = this.drawCenteredText(y + 2, "Mining in progress...", "#ff0");
|
||||
} else {
|
||||
y = this.drawCenteredText(y + 2, "Type 'ENTER' to queue for game", this.defaultFg);
|
||||
const isDebugMode = window.location.hostname === 'localhost' ||
|
||||
window.location.hostname === '127.0.0.1' ||
|
||||
window.location.protocol === 'file:';
|
||||
|
||||
// Control HTML START button visibility
|
||||
const startButton = document.getElementById('startButton');
|
||||
if (startButton) {
|
||||
if (this._waitingForBlock && !isDebugMode) {
|
||||
startButton.style.display = 'none';
|
||||
y = this.drawCenteredText(y + 2, "Mining in progress...", "#ff0");
|
||||
} else {
|
||||
startButton.style.display = 'block';
|
||||
y = this.drawCenteredText(y + 2, "Press ENTER or click START to queue", "#0f0");
|
||||
}
|
||||
}
|
||||
|
||||
// Debug button (shown only in development)
|
||||
if (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1' || window.location.protocol === 'file:') {
|
||||
if (isDebugMode) {
|
||||
this.drawCenteredText(y + 3, "[DEBUG: Press 'D' to start immediately]", "#666");
|
||||
}
|
||||
|
||||
@@ -79,43 +91,54 @@ var ScreenManager = {
|
||||
this._waitingForBlock = true;
|
||||
|
||||
// Update welcome screen every second during mining
|
||||
const updateInterval = setInterval(() => {
|
||||
if (this._waitingForBlock) {
|
||||
this._updateInterval = setInterval(() => {
|
||||
if (this._waitingForBlock && !GameState.isGameActive()) {
|
||||
this.drawWelcomeScreen();
|
||||
} else {
|
||||
clearInterval(updateInterval);
|
||||
if (this._updateInterval) {
|
||||
clearInterval(this._updateInterval);
|
||||
this._updateInterval = null;
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
// Simulate new block every 30 seconds
|
||||
this._blockTimer = setInterval(() => {
|
||||
this._currentBlockHeight++;
|
||||
this._waitingForBlock = false;
|
||||
this.drawWelcomeScreen();
|
||||
|
||||
// Show block found message briefly
|
||||
setTimeout(() => {
|
||||
if (!DisplayManager.ensureDisplay()) return;
|
||||
let y = Math.floor(this._screenHeight / 2);
|
||||
this.drawCenteredText(y, "🎉 NEW BLOCK FOUND! 🎉", "#0f0");
|
||||
this.drawCenteredText(y + 1, "You may now enter the dungeon!", "#0f0");
|
||||
if (!GameState.isGameActive()) { // Only continue if game is not active
|
||||
this._currentBlockHeight++;
|
||||
this._waitingForBlock = false;
|
||||
this.drawWelcomeScreen();
|
||||
|
||||
// Allow entry for 5 seconds
|
||||
// Show block found message briefly
|
||||
setTimeout(() => {
|
||||
this._waitingForBlock = true;
|
||||
this.drawWelcomeScreen();
|
||||
}, 5000);
|
||||
}, 500);
|
||||
|
||||
if (!DisplayManager.ensureDisplay() || GameState.isGameActive()) return;
|
||||
let y = Math.floor(this._screenHeight / 2);
|
||||
this.drawCenteredText(y, "*** NEW BLOCK FOUND! ***", "#0f0");
|
||||
this.drawCenteredText(y + 1, "You may now enter the dungeon!", "#0f0");
|
||||
|
||||
// Allow entry for 5 seconds
|
||||
setTimeout(() => {
|
||||
if (!GameState.isGameActive()) {
|
||||
this._waitingForBlock = true;
|
||||
this.drawWelcomeScreen();
|
||||
}
|
||||
}, 5000);
|
||||
}, 500);
|
||||
}
|
||||
}, 30000); // 30 second intervals
|
||||
},
|
||||
|
||||
// Stop block simulation
|
||||
stopBlockSimulation: function() {
|
||||
console.log("Stopping block simulation and clearing all intervals...");
|
||||
if (this._blockTimer) {
|
||||
clearInterval(this._blockTimer);
|
||||
this._blockTimer = null;
|
||||
}
|
||||
if (this._updateInterval) {
|
||||
clearInterval(this._updateInterval);
|
||||
this._updateInterval = null;
|
||||
}
|
||||
this._waitingForBlock = false;
|
||||
},
|
||||
|
||||
|
||||
@@ -46,11 +46,7 @@ const SocketHandlers = {
|
||||
userAgent: navigator.userAgent
|
||||
});
|
||||
|
||||
// Auto-start for testing (timeout issue has been fixed)
|
||||
setTimeout(() => {
|
||||
console.log("🚀 AUTO-STARTING GAME for faster testing");
|
||||
socket.emit('chat message', 'enter');
|
||||
}, 500);
|
||||
// Auto-start removed - user must manually start game
|
||||
},
|
||||
|
||||
onWelcome: function(msg) {
|
||||
@@ -79,6 +75,13 @@ const SocketHandlers = {
|
||||
|
||||
onGameStart: function(data) {
|
||||
console.log("🎮 Game start received with data:", data);
|
||||
console.log("🔍 DETAILED DATA CHECK:");
|
||||
console.log(" - Player:", data?.player);
|
||||
console.log(" - Map keys:", data?.map ? Object.keys(data.map).length : "NO MAP");
|
||||
console.log(" - Monster:", data?.monster);
|
||||
console.log(" - Items:", data?.items);
|
||||
console.log(" - VisibleTiles keys:", data?.visibleTiles ? Object.keys(data.visibleTiles).length : "NO VISIBLE TILES");
|
||||
|
||||
$('#messages').append($('<li class="game-start">').text("Starting game..."));
|
||||
|
||||
if (typeof Game !== 'undefined' && Game.stopWaitingScreen) {
|
||||
@@ -98,6 +101,7 @@ const SocketHandlers = {
|
||||
|
||||
if (!success) {
|
||||
$('#messages').append($('<li class="error">').text("Game start failed. Check console for details."));
|
||||
console.log("❌ GAME START FAILED - reverting to welcome screen");
|
||||
if (typeof Game !== 'undefined' && Game._drawWelcomeScreen) Game._drawWelcomeScreen();
|
||||
} else {
|
||||
// Draw the initial game screen - the game draws itself after startGame()
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
body {
|
||||
color: green;
|
||||
}
|
||||
Reference in New Issue
Block a user