- Added Faza1_Finalna.tmx/json with embedded tilesets - Configured Auto-Sync Watcher (tiled-watcher.js) - Fixed GameScene.js loop to properly render Tiled layers - Updated PreloadScene.js with all tileset assets - Enabled Amnesia Intro and Z-Sorting for Player/Objects - Cleaned up old/unused map files
75 lines
2.2 KiB
JavaScript
Executable File
75 lines
2.2 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
/**
|
|
* 🔥 TILED AUTO-SYNC WATCHER
|
|
* Spremlja Faza1_Finalna.tmx in avtomatsko exporta v JSON + reload Electron
|
|
*/
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { exec } = require('child_process');
|
|
|
|
const WATCH_FILE = path.join(__dirname, 'assets/maps/Faza1_Finalna.tmx');
|
|
const JSON_OUTPUT = path.join(__dirname, 'assets/maps/Faza1_Finalna.json');
|
|
const TILED_CLI = '/Applications/Tiled.app/Contents/MacOS/tiled'; // Mac path
|
|
|
|
let isProcessing = false;
|
|
let lastModified = 0;
|
|
|
|
console.log('🔥 TILED AUTO-SYNC WATCHER STARTED');
|
|
console.log(`📂 Watching: ${WATCH_FILE}`);
|
|
console.log(`📤 Output: ${JSON_OUTPUT}`);
|
|
console.log(`⚡ Auto-Reload: ENABLED\n`);
|
|
|
|
// Function to export TMX to JSON using Tiled CLI
|
|
function exportToJSON() {
|
|
if (isProcessing) return;
|
|
isProcessing = true;
|
|
|
|
console.log('🔄 Change detected! Exporting TMX → JSON...');
|
|
|
|
const exportCmd = `"${TILED_CLI}" --export-map json "${WATCH_FILE}" "${JSON_OUTPUT}"`;
|
|
|
|
exec(exportCmd, (error, stdout, stderr) => {
|
|
if (error) {
|
|
console.error('❌ Export failed:', error.message);
|
|
console.log('💡 Tip: Check if Tiled is installed at:', TILED_CLI);
|
|
isProcessing = false;
|
|
return;
|
|
}
|
|
|
|
if (stderr && !stderr.includes('QStandardPaths')) {
|
|
console.warn('⚠️ Export warning:', stderr);
|
|
}
|
|
|
|
console.log('✅ JSON exported successfully!');
|
|
console.log('⚡ Electron will auto-reload on Cmd+R\n');
|
|
console.log('👀 Waiting for changes...\n');
|
|
|
|
isProcessing = false;
|
|
});
|
|
}
|
|
|
|
// Watch for file changes
|
|
fs.watchFile(WATCH_FILE, { interval: 500 }, (curr, prev) => {
|
|
// Only trigger if file was actually modified (not just accessed)
|
|
if (curr.mtime.getTime() !== lastModified) {
|
|
lastModified = curr.mtime.getTime();
|
|
|
|
// Debounce - wait 100ms to avoid multiple triggers
|
|
setTimeout(() => {
|
|
exportToJSON();
|
|
}, 100);
|
|
}
|
|
});
|
|
|
|
// Initial message
|
|
console.log('👀 Watching for changes in Tiled map...');
|
|
console.log('💡 Save in Tiled (Cmd+S) → Auto-export → Cmd+R in Electron\n');
|
|
|
|
// Keep process running
|
|
process.on('SIGINT', () => {
|
|
console.log('\n🛑 Watcher stopped.');
|
|
process.exit(0);
|
|
});
|