Skip to content

Instantly share code, notes, and snippets.

@thedaniel
Created Sep 29, 2020
Embed
What would you like to do?
192.168.1.169 ~/dust/code/arcologies $ git diff --cached
diff --git a/lib/counters.lua b/lib/counters.lua
index 0f3bf45..4898b37 100644
--- a/lib/counters.lua
+++ b/lib/counters.lua
@@ -1,3 +1,5 @@
+include("arcologies/lib/filesystem")
+
counters = {}
function counters.init()
@@ -36,6 +38,9 @@ function counters.conductor()
keeper:collide_signals_and_cells()
keeper:delete_signals()
keeper:teardown()
+ if math.fmod(counters.music_generation, 4) then
+ filesystem.save_map("running", "/tmp/arcologies/")
+ end
redraw()
end
end
diff --git a/lib/filesystem.lua b/lib/filesystem.lua
index 9b5fa81..ce5b032 100644
--- a/lib/filesystem.lua
+++ b/lib/filesystem.lua
@@ -80,10 +80,11 @@ function filesystem:get_crypt()
return self.current
end
-function filesystem.save_map(text)
+function filesystem.save_map(text, maps_path)
+ maps_path = maps_path or filesystem.paths["maps_path"]
if text then
print("saving map...")
- local save_path = filesystem.paths.maps_path .. text ..".txt"
+ local save_path = maps_path .. text ..".txt"
local data = saveload:collect_data_for_map_save(text)
local file = io.open(save_path, "w")
io.output(file)
diff --git a/serve.js b/serve.js
new file mode 100644
index 0000000..4db1ece
--- /dev/null
+++ b/serve.js
@@ -0,0 +1,18 @@
+const fs = require('fs')
+const WS = require('ws')
+
+const wss = new WS.Server({
+ port: 8080
+})
+
+// yeah this should be streams and fully async but i'm just hackin here to test
+
+fs.watch('/tmp/arcologies/running.txt', {encoding: 'buffer'}, function (eventType, filename) {
+ console.log("change")
+ wss.clients.forEach(function each(client) {
+ if (client !== wss && client.readyState === WS.OPEN) {
+ console.log('sending')
+ client.send(fs.readFileSync('/tmp/arcologies/running.txt', {encoding: 'ascii'}));
+ }
+ })
+})
studio:arcologies-docs daniel$ git diff
diff --git a/_includes/mapper_input.html b/_includes/mapper_input.html
index f144f42..7545305 100644
--- a/_includes/mapper_input.html
+++ b/_includes/mapper_input.html
@@ -2,6 +2,7 @@
<div class="row">
<div class="col mb-5">
<h2>Input</h2>
+ <a id="load-ws" href="#">load ws</a>
<hr>
<textarea class="mapper-input" autofocus></textarea>
</div>
diff --git a/assets/javascript/mapper.js b/assets/javascript/mapper.js
index 68c3970..e7842d8 100644
--- a/assets/javascript/mapper.js
+++ b/assets/javascript/mapper.js
@@ -40,6 +40,16 @@ function buildCells(mapper) {
return out;
}
+let ws
+
+function onClickWS () {
+ ws = new WebSocket('ws://192.168.1.169:8080')
+ ws.onmessage = function (event) {
+ console.log(event.data)
+ $('.mapper-input').val(event.data).trigger('propertychange')
+ }
+}
+
function getInput() {
mapper = {};
mapperInput = $('.mapper-input').val().split("\n");
@@ -66,6 +76,7 @@ $('input[type=radio]').change(function () {
});
$(function() {
+ $('#load-ws').click(onClickWS)
$('.mapper-input').val($('pre.default').html());
redraw();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment