Skip to content

Instantly share code, notes, and snippets.

@yuanotes
Created October 20, 2020 16:35
Show Gist options
  • Save yuanotes/8604cab035d9ab92c6eef65d187bb11d to your computer and use it in GitHub Desktop.
Save yuanotes/8604cab035d9ab92c6eef65d187bb11d to your computer and use it in GitHub Desktop.
This script enabls godot client listen to file modifications by external editors
const net = require('net');
const fs = require('fs');
const reloadCMD = "\x20\x00\x00\x00\x13\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00\x00\x0e\x00\x00\x00reload_scripts\x00\x00"
// start godot client at first /Applications/Godot.app/Contents/MacOS/Godot -d --remote-debug 127.0.0.1:8008
const port = 8008;
const server = net.createServer();
server.on('connection', (socket) => {
console.log('FS watcher starts');
fs.watch('.', { encoding: 'buffer', recursive: true}, (eventType, filename) => {
if (filename) {
console.log(`File modified ${filename}`);
socket.write(reloadCMD);
}
});
});
server.listen(port, () => {
console.log(`Listening on address ${JSON.stringify(server.address())}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment