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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
(()=>{
var root = document.body;
const cdata = {
thing: { color:"lime" },
apioform: { color:"yellow" },
violetstar: { color:"#8050FF" },
undefinedium: { color:"#FF00FF" },
four: { color:"#3040FF" },
}
let sdata;
try {
sdata = JSON.parse(localStorage.savedata);
} catch(e) {
sdata = {
unlocks: {thingbutton:1},
currencies:{thing:{amount:0,visible:true}},
};
}
let am = sdata.currencies;
for (let i in cdata){
if (!am[i]){
am[i]={amount:0,visible:false};
}
}
var ThingButton = {
view: ()=>{
return m("button",{
onclick:()=>{if (!sdata.autothing) am.thing.amount+=1}
},sdata.autothing?get_msg('unavailable'):get_msg('attain_a_thing'));
}
}
var AutoThing = {
view: ()=>{
return m("button",{onclick:()=>sdata.autothing = !sdata.autothing},[
get_msg('autothing'),
m("span",{
style:"color:"+(sdata.autothing?"lime":"grey")+";"},
sdata.autothing?get_msg('on'):get_msg('off')),
]);
}
}
let autothing_timeout = "none";
setInterval(()=>{localStorage.savedata = JSON.stringify(sdata)},1000);
var MainComponent = {
view: ()=>{
let res = [
m("h1",{style:"text-align:center;"},"Incremental"),
m("hr"),
m(CBar,{data:am}),
];
if (am.thing.amount >= 50) {
am.apioform.visible = true;
sdata.unlocks.autothing = 1;
}
if (sdata.unlocks.thingbutton) res.push(m(ThingButton));
if (sdata.unlocks.autothing) res.push(m(AutoThing));
if (!sdata.autothing && autothing_timeout != "none"){
clearInterval(autothing_timeout);
autothing_timeout = "none";
}
if (sdata.autothing && autothing_timeout == "none"){
autothing_timeout = setInterval(()=>{am.thing.amount++;m.redraw()},500);
}
return m("main",res);
}
}
var CIcon = {
view: vnode => {
let a = vnode.attrs.currency || "undefinedium";
a = "sprites/"+a+".png";
return m("img",{title:cdata[vnode.attrs.currency].plural,src:a,width:32,height:32});
}
}
var CDisp = {
view: vnode => {
let a = vnode.attrs;
return m(".currencydisplay",[
m(CIcon,{currency:a.currency}),
m(".currencycount",{
style:"color:"+cdata[a.currency].color},
a.amount==undefined?get_msg('something_broke'):a.amount),
]);
}
}
var CBar = {
view: vnode => {
let a = vnode.attrs;
let res = [];
for (let i in a.data||{}){
if (a.data[i].visible){
res.push(m(CDisp,{currency:i,amount:a.data[i].amount}));
}
}
return m(".currencybar",res);
}
}
m.mount(root,MainComponent);
})();
|