Constellations/js/Share.js

42 lines
917 B
JavaScript
Raw Permalink Normal View History

import size from Config;
2022-08-10 21:12:39 +02:00
import {at, generate, iter, square} from Grid.Util;
import * as Decode from Share.Decoder.Protocol;
import * as Encode from Share.Encoder.Protocol;
import * as Encoder from Share.Encoder.Class;
import GUI;
import Grid;
var share = document.getElementById('share')
return {
get: get,
2022-08-10 21:12:39 +02:00
decode: Decode.grid,
link: link
}
function get() {
return share;
}
function naiveEncode(coloring) {
var encoder = Encoder.make();
iter(coloring, function(color) {
encoder.int(3)(color);
});
return encoder.output();
}
function naiveDecode(input) {
if(input != undefined) {
var decoder = Decoder.make(input);
return generate(size, size, function() {return decoder.int(3);});
}
}
function link() {
2022-08-10 21:12:39 +02:00
//share.href = '?game=' + naiveEncode(Grid.get().colors);
console.log(naiveEncode(Grid.get().colors));
2022-08-10 21:12:39 +02:00
share.href = '?game=' + Encode.grid(Grid.get().colors);
GUI.activate(true, share);
}