aboutsummaryrefslogtreecommitdiff
path: root/gui.js
blob: 7f28fd0e43f8edb6cf8c6353d84a17b790afb701 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"use strict";

// Define the menu interface
Gui.prototype = Object.create(dat.GUI.prototype);

function Gui()
{
    dat.GUI.call(this);

    var self = this;

    var cmd;
    cmd = this.add(Cubie.prototype, 'explosion', 0.50, 2.00);
    cmd.name("Explode");
    cmd.onChange(function (value)
    {
        Cubie.prototype.explosion = value;
        for (var i = 0; i < cubies.size; i++)
        {
            cubies.get(i).updateExplosion();
        }
        needsRender = true;
    });

    cmd = this.add({ func: solvedCube }, 'func');
    cmd.name("Solved Cube");

    cmd = this.add({ func: scramble }, 'func');
    cmd.name("Scramble");

    cmd = this.add({ func: function(){ selectFile(false); } }, 'func');
    cmd.name("Load File");

    cmd = this.add({ func: function(){
        // Default name
        // This is used if the browser is *not* configured to prompt for a name
        // (and location) to save a new file.
        var filename = "rubik.txt"
        var content =  "Answer: 0\n"
        for (var i = 0; i < cubies.size; i++)
        {
            let cubie = cubies.get(i)
            content += `is(0,${i},${cubie.colors[0].value},${cubie.colors[1].value},${cubie.colors[2].value}) `
        }

        saveToFile(filename,content);
    } }, 'func');
    cmd.name("Save to File");

    var pos_commands_folder = this.addFolder('Commands (Positive)');
    var neg_commands_folder = this.addFolder('Commands (Negative)');
    animations.forEach(function(value,key)
    { 
        cmd = pos_commands_folder.add({ dummy: function(){} }, 'dummy');
        cmd.name(key);
        cmd.onChange(function()
        {
            startAnimation(key,1.0);
        })

        cmd = neg_commands_folder.add({ dummy: function(){} }, 'dummy');
        cmd.name(key);
        cmd.onChange(function()
        {
            startAnimation(key,-1.0);
        })
    });
    // pos_commands_folder.open();
    // neg_commands_folder.open();
}