2022-08-06 18:33:10 +02:00
|
|
|
import * as Decoder from Share.Decoder;
|
|
|
|
import * as Encoder from Share.Encoder;
|
2022-08-06 20:18:30 +02:00
|
|
|
import {generate, iter, square} from Grid.Util;
|
|
|
|
import GUI;
|
|
|
|
import Grid;
|
|
|
|
|
|
|
|
var share = document.getElementById('share')
|
2022-08-06 18:33:10 +02:00
|
|
|
|
2022-08-02 17:57:29 +02:00
|
|
|
return {
|
2022-08-06 20:18:30 +02:00
|
|
|
get: get,
|
|
|
|
naiveDecode: naiveDecode,
|
|
|
|
link: link
|
2022-08-02 17:57:29 +02:00
|
|
|
}
|
|
|
|
|
2022-08-06 20:18:30 +02:00
|
|
|
function get() {
|
|
|
|
return share;
|
2022-08-02 17:57:29 +02:00
|
|
|
}
|
|
|
|
|
2022-08-06 18:33:10 +02:00
|
|
|
function naiveEncode(grid) {
|
|
|
|
var encoder = Encoder.make();
|
|
|
|
iter(grid, function(row, column) {
|
|
|
|
encoder.int(3)(grid[row][column]);
|
|
|
|
});
|
|
|
|
return encoder.output();
|
2022-08-02 17:57:29 +02:00
|
|
|
}
|
|
|
|
|
2022-08-06 18:33:10 +02:00
|
|
|
function naiveDecode(size, input) {
|
2022-08-06 20:18:30 +02:00
|
|
|
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);
|
|
|
|
GUI.activate(true, share);
|
2022-08-02 17:57:29 +02:00
|
|
|
}
|