Constellations/js/Share.js

41 lines
917 B
JavaScript

import size from Config;
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,
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() {
//share.href = '?game=' + naiveEncode(Grid.get().colors);
console.log(naiveEncode(Grid.get().colors));
share.href = '?game=' + Encode.grid(Grid.get().colors);
GUI.activate(true, share);
}