├── .gitignore
├── img
├── favicon.ico
├── xx_logo.png
├── favicon-16x16.png
├── favicon-32x32.png
└── xx_logo.svg
├── README.md
├── package.json
├── Makefile
├── go.mod
├── js
├── code.js
├── solitaireVictory.js
└── bootstrap.min.js
├── index.html
├── LICENSE
├── main.js
├── client.go
├── main.go
├── css
├── select2.min.css
└── bootstrap-theme.min.css
└── go.sum
/.gitignore:
--------------------------------------------------------------------------------
1 | vendor
2 | xx-coin-game-ui
3 | xx-coin-game-ui.*
--------------------------------------------------------------------------------
/img/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xxfoundation/elixxir-xx-coin-game-ui/HEAD/img/favicon.ico
--------------------------------------------------------------------------------
/img/xx_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xxfoundation/elixxir-xx-coin-game-ui/HEAD/img/xx_logo.png
--------------------------------------------------------------------------------
/img/favicon-16x16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xxfoundation/elixxir-xx-coin-game-ui/HEAD/img/favicon-16x16.png
--------------------------------------------------------------------------------
/img/favicon-32x32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xxfoundation/elixxir-xx-coin-game-ui/HEAD/img/favicon-32x32.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Building
2 |
3 | ```
4 | go build
5 | /Users/anne/Downloads/nwjs-sdk-v0.52.0-osx-x64/nwjs.app/Contents/MacOS/nwjs .
6 | ```
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "xx-coin-game",
3 | "main": "index.html",
4 | "single-instance": true,
5 | "window": {
6 | "position": "center",
7 | "width": 650,
8 | "height": 433,
9 | "frame": true,
10 | "icon": "img/favicon-32x32.png"
11 | },
12 | "webkit": {
13 | "plugin": true
14 | },
15 | "version": "1.0.0"
16 | }
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY: update master release setup update_master update_release build clean
2 |
3 | setup:
4 | git config --global --add url."git@gitlab.com:".insteadOf "https://gitlab.com/"
5 |
6 | clean:
7 | rm -rf vendor/
8 | go mod vendor
9 |
10 | update:
11 | -GOFLAGS="" go get -u all
12 |
13 | build:
14 | go build ./...
15 | go mod tidy
16 |
17 | update_release:
18 | GOFLAGS="" go get gitlab.com/elixxir/client@release
19 |
20 | update_master:
21 | GOFLAGS="" go get gitlab.com/elixxir/client@master
22 |
23 | master: clean update_master build
24 |
25 | release: clean update_release build
26 |
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module gitlab.com/elixxir/xx-coin-game-ui
2 |
3 | go 1.13
4 |
5 | require (
6 | github.com/dtylman/gowd v0.0.0-20190619113956-15e38debca22
7 | github.com/nyaruka/phonenumbers v1.0.68 // indirect
8 | github.com/spf13/jwalterweatherman v1.1.0
9 | github.com/stretchr/testify v1.7.0 // indirect
10 | github.com/zeebo/assert v1.3.0 // indirect
11 | gitlab.com/elixxir/client v1.5.1-0.20210406013452-137c0c4e919c
12 | gitlab.com/xx_network/primitives v0.0.4-0.20210402222416-37c1c4d3fac4
13 | golang.org/x/net v0.0.0-20210323141857-08027d57d8cf // indirect
14 | google.golang.org/genproto v0.0.0-20210323160006-e668133fea6a // indirect
15 | gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
16 | )
17 |
--------------------------------------------------------------------------------
/js/code.js:
--------------------------------------------------------------------------------
1 | var pattern = ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'b', 'a'];
2 | var current = 0;
3 |
4 | var keyHandler = function (event) {
5 |
6 | // If the key isn't in the pattern, or isn't the current key in the pattern, reset
7 | if (pattern.indexOf(event.key) < 0 || event.key !== pattern[current]) {
8 | current = 0;
9 | return;
10 | }
11 |
12 | // Update how much of the pattern is complete
13 | current++;
14 |
15 | // If complete, alert and reset
16 | if (pattern.length === current) {
17 | current = 0;
18 | //window.alert('You found it!');
19 | $('img').solitaireVictory({fallToLeft: true});
20 | }
21 |
22 | };
23 |
24 | // Listen for keydown events
25 | document.addEventListener('keydown', keyHandler, false);
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | xx Coin Game
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 2-Clause License
2 |
3 | Copyright (c) 2021, xx network SEZC
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | 1. Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | 2. Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 |
--------------------------------------------------------------------------------
/img/xx_logo.svg:
--------------------------------------------------------------------------------
1 |
20 |
--------------------------------------------------------------------------------
/js/solitaireVictory.js:
--------------------------------------------------------------------------------
1 | (function( $ ) {
2 |
3 | $.fn.solitaireVictory = function(settings) {
4 |
5 | settings = settings || {};
6 |
7 | var g = settings.g || -3;
8 | var dt = settings.dt || 20;
9 | var bounce = settings.bounce || 0.7;
10 | var endVelocity = settings.endVelocity || 20;
11 | var stagger = settings.stagger || 200;
12 | var relativeToDocument = settings.relativeToDocument || false;
13 | var clear = settings.clear || false;
14 | var fallToLeft = settings.fallToLeft || false;
15 |
16 | var body = $('body');
17 | var windowHeight = (relativeToDocument ? $(document).height() : $(window).height());
18 |
19 | var fallIteration = function(elem, elemHeight, oldPos, dx, dy) {
20 | var copy = elem.clone();
21 | body.append(copy);
22 |
23 | var newTop = Math.min(windowHeight - elemHeight, oldPos.top + dy);
24 | var newPos = {
25 | left: oldPos.left + dx,
26 | top: newTop
27 | };
28 | copy.offset(newPos);
29 | if (Math.abs(newTop - (windowHeight - elemHeight)) < 5) {
30 | if (dy < 0 || dy > endVelocity) {
31 | dy *= -1*bounce;
32 | setTimeout(function() {
33 | fallIteration(copy, elemHeight, newPos, dx, dy);
34 | }, dt);
35 | }
36 | } else {
37 | dy = dy - g;
38 | setTimeout(function() {
39 | fallIteration(copy, elemHeight, newPos, dx, dy);
40 | }, dt);
41 | }
42 | };
43 |
44 | var startFall = function(elem, height, stagger) {
45 | var dx = settings.dx || Math.floor((Math.random()*10)) + 5;
46 | if (fallToLeft) {
47 | dx = -dx;
48 | }
49 | var copy = elem.clone();
50 | copy.addClass('solitaire-victory-clone');
51 | if (relativeToDocument) {
52 | copy.css('position', 'absolute');
53 | } else {
54 | copy.css('position', 'fixed');
55 | }
56 | var originalOffset = elem.offset();
57 | copy.offset({top: originalOffset.top, left: originalOffset.left});
58 | body.append(copy);
59 | setTimeout(function() {fallIteration(copy, height, copy.offset(), dx, 0);}, stagger);
60 | };
61 |
62 | if (clear) $('.solitaire-victory-clone').remove();
63 |
64 | this.each(function(index) {
65 | var obj = $(this);
66 | if (relativeToDocument || obj.offset().top < $(window).height()) {
67 | if (!obj.hasClass('solitaire-victory-clone')) {
68 | startFall(obj, obj.height(), index*stagger);
69 | }
70 | }
71 | });
72 | };
73 |
74 | }( jQuery ));
--------------------------------------------------------------------------------
/main.js:
--------------------------------------------------------------------------------
1 | var os = require('os');
2 | var child;
3 | var fails = 0;
4 | var goBinary = "./xx-coin-game-ui"; //or template.exe
5 |
6 | function setPage(html) {
7 | const container = document.getElementById("app");
8 | app.innerHTML = html;
9 | //set focus for autofocus element
10 | var elem = document.querySelector("input[autofocus]");
11 | if (elem != null) {
12 | elem.focus();
13 | }
14 | }
15 |
16 | function body_message(msg) {
17 | setPage('' + msg + '
');
18 | }
19 |
20 | function start_process() {
21 | body_message("Loading...");
22 |
23 | const spawn = require('child_process').spawn;
24 | child = spawn(goBinary, { maxBuffer: 1024 * 500 });
25 |
26 | const readline = require('readline');
27 | const rl = readline.createInterface({
28 | input: child.stdout
29 | })
30 |
31 | rl.on('line', (data) => {
32 | console.log(`Received: ${data}`);
33 |
34 | if (data.charAt(0) == "$") {
35 | data = data.substr(1);
36 | eval(data);
37 | } else {
38 | setPage(data);
39 | }
40 | });
41 |
42 | child.stderr.on('data', (data) => {
43 | console.log(`stderr: ${data}`);
44 | });
45 |
46 | child.on('close', (code) => {
47 | body_message(`process exited with code ${code}`);
48 | restart_process();
49 | });
50 |
51 | child.on('error', (err) => {
52 | body_message('Failed to start child process.');
53 | restart_process();
54 | });
55 | }
56 |
57 | function restart_process() {
58 | setTimeout(function () {
59 | fails++;
60 | if (fails > 5) {
61 | close();
62 | } else {
63 | start_process();
64 | }
65 | }, 5000);
66 | }
67 |
68 | function element_as_object(elem) {
69 | var obj = {
70 | properties: {}
71 | }
72 | for (var j = 0; j < elem.attributes.length; j++) {
73 | obj.properties[elem.attributes[j].name] = elem.attributes[j].value;
74 | }
75 | //overwrite attributes with properties
76 | if (elem.value != null) {
77 | obj.properties["value"] = elem.value.toString();
78 | }
79 | if (elem.checked != null && elem.checked) {
80 | obj.properties["checked"] = "true";
81 | } else {
82 | delete (obj.properties["checked"]);
83 | }
84 | return obj;
85 | }
86 |
87 | function element_by_tag_as_array(tag) {
88 | var items = [];
89 | var elems = document.getElementsByTagName(tag);
90 | for (var i = 0; i < elems.length; i++) {
91 | items.push(element_as_object(elems[i]));
92 | }
93 | return items;
94 | }
95 |
96 | function fire_event(name, sender) {
97 | var msg = {
98 | name: name,
99 | sender: element_as_object(sender),
100 | inputs: element_by_tag_as_array("input").concat(element_by_tag_as_array("select"))
101 | }
102 | child.stdin.write(JSON.stringify(msg));
103 | console.log(JSON.stringify(msg));
104 | }
105 |
106 | function fire_keypressed_event(e, keycode, name, sender) {
107 | if (e.keyCode === keycode) {
108 | e.preventDefault();
109 | fire_event(name, sender);
110 | }
111 | }
112 |
113 | function avoid_reload() {
114 | if (sessionStorage.getItem("loaded") == "true") {
115 | alert("go-webkit will fail when page reload. avoid using