Constellations/js/Share.js

39 lines
810 B
JavaScript

import {at, generate, iter, square} from Grid.Util;
import * as Decode from Share.Decoder.Protocol;
import * as Encode from Share.Encoder.Protocol;
import GUI;
import Grid;
var share = document.getElementById('share')
return {
get: get,
decode: Decode.grid,
link: link
}
function get() {
return share;
}
function naiveEncode(grid) {
var encoder = Encoder.make();
iter(grid, function(cell) {
encoder.int(3)(at(grid, cell));
});
return encoder.output();
}
function naiveDecode(size, input) {
if(input != undefined) {
var decoder = Decoder.make(input);
return generate(size, size, function() {return decoder.int(3);});
}
}
function link(grid) {
//share.href = '?game=' + naiveEncode(Grid.get().colors);
share.href = '?game=' + Encode.grid(Grid.get().colors);
GUI.activate(true, share);
}