-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
372 lines (306 loc) · 17.3 KB
/
index.js
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/*
----------------------------------------------
* Project: Virtual Pet Pom Clock Face
* Mail: darahbass@gmail.com
* Github: SarahBass
---------------------------------------------
NOTES:
This Clock will be larger than normal
because it has so many animations.
Images are ALL original artwork
---------------------------------------------
*/
/*--- Import Information from user Account ---*/
import { settingsStorage } from "settings";
import { me as appbit } from "appbit";
import { HeartRateSensor } from "heart-rate";
import clock from "clock";
import * as document from "document";
import { preferences } from "user-settings";
import * as util from "../common/utils";
import { battery } from 'power';
import { display } from "display";
import { today as userActivity } from "user-activity";
import {goals, today} from "user-activity";
import { units } from "user-settings";
/*--- Create Local Variables for Information Storage ---*/
let daytext = "day";
let monthtext = "month";
let goalreached = "NONE";
/*--- Import Information from index.gui ---*/
let background = document.getElementById("background");
let ampm = document.getElementById("ampm");
let date = document.getElementById("date");
let dog = document.getElementById("dog");
let monthobject = document.getElementById("monthobject");
let hearts = document.getElementById("hearts");
//Update the clock every second
clock.granularity = "seconds";
// Get a handle on the <text> elements
const myLabel = document.getElementById("myLabel");
const batteryLabel = document.getElementById("batteryLabel");
const stepsLabel = document.getElementById("stepsLabel");
const firelabel = document.getElementById("firelabel");
const boltlabel = document.getElementById("boltlabel");
const heartlabel = document.getElementById("heartlabel");
const stairslabel = document.getElementById("stairslabel");
const distancelabel = document.getElementById("distancelabel");
if (HeartRateSensor && appbit.permissions.granted("access_heart_rate")) {
const hrm = new HeartRateSensor();
hrm.addEventListener("reading", () => {
heartlabel.text = (`${hrm.heartRate}`);
});
display.addEventListener("change", () => {
// Automatically stop the sensor when the screen is off to conserve battery
display.on ? hrm.start() : hrm.stop();
});
hrm.start();
}else {heartlabel.text = "off";}
/*--- CLOCK START ---*/
clock.ontick = (evt) => {
let today = evt.date;
let hours = today.getHours();
let months = today.getMonth();
let days = today.getDay();
let dates = today.getDate();
let years = today.getFullYear();
let mins = util.zeroPad(today.getMinutes());
let seconds = today.getSeconds();
/*--- Update Stats for Screen ---*/
updateScene();
if (units.distance == "us"){
distancelabel.text = (0.000621371 * userActivity.adjusted.distance).toFixed(1) + " mi";}
else {distancelabel.text = (0.001 * userActivity.adjusted.distance).toFixed(1) + " km";}
stairslabel.text = userActivity.adjusted.elevationGain;
stepsLabel.text = userActivity.adjusted.steps;
firelabel.text = userActivity.adjusted.calories;
// targetlabel.text = parseInt(userActivity.adjusted.steps/goals.steps * 100) + "%";
boltlabel.text = userActivity.adjusted.activeZoneMinutes.total;
heartlabel.text = "off";
checkAndUpdateBatteryLevel();
//AM PM -Change the image based on 24 hours
if (util.zeroPad(hours) >= 12){ampm.text = "pm";}
else{ampm.text = "am";}
//Give dog hearts based on goal
//Get Prize from Steps Goal goals.steps
if (userActivity.adjusted.steps < goals.steps/5){hearts.image = "blank.png";}
else if ((userActivity.adjusted.steps < ((goals.steps)*2)/5) && (userActivity.adjusted.steps > ((goals.steps*1)/5)))
{hearts.image = "hearts/heart1.png";}
else if ((userActivity.adjusted.steps < ((goals.steps)*3)/5)&& (userActivity.adjusted.steps > ((goals.steps*2)/5)))
{hearts.image = "hearts/heart2.png";}
else if ((userActivity.adjusted.steps < ((goals.steps)*4)/5)&& (userActivity.adjusted.steps > ((goals.steps*3)/5)))
{hearts.image = "hearts/heart3.png";}
else if ((userActivity.adjusted.steps < goals.steps)&& (userActivity.adjusted.steps > ((goals.steps*4)/5)))
{hearts.image = "hearts/heart4.png";}
else if (userActivity.adjusted.steps > goals.steps){hearts.image = "hearts/heart5.png";}
else {hearts.image = "blank.png";}
//Change Background
if (((util.zeroPad(hours) >= 0) && (util.zeroPad(hours) < 5)) || (util.zeroPad(hours) >= 22)){
background.image = "night.jpeg";
distancelabel.class = "labelnightblue";
firelabel.class = "labelnightblue";
boltlabel.class = "labelnightblue";
heartlabel.class = "labelnightblue";
stairslabel.class = "labelnightblue";
}else{
background.image = "greenbg.jpeg";
distancelabel.class = "labellightblue";
firelabel.class = "labellightblue";
boltlabel.class = "labellightblue";
heartlabel.class = "labellightblue";
stairslabel.class = "labellightblue";
}
//Change Foreground
if (((util.zeroPad(hours) >= 0) && (util.zeroPad(hours) <= 5)) || (util.zeroPad(hours) >= 20)){
monthobject.image="background/"+ months+ "2.png";
if (userActivity.adjusted.steps/goals.steps > 0.8){
if ( parseInt(mins/10) == 1 ){
if (seconds % 2 == 0){dog.image = "dog/dog2start.png";}
else{dog.image = "dog/dog2happy0.png";}}
else if (parseInt(mins/10) == 2 ){
if (seconds % 2 == 0){dog.image = "dog/dog2start.png";}
else{dog.image = "dog/dog2happy1.png";}}
else if ( parseInt(mins/10) == 3 ){
if (seconds % 2 == 0){dog.image = "dog/dog2happy0.png";}
else{dog.image = "dog/dog2sad0.png";}}
else if (parseInt(mins/10) == 4 ){
if (seconds % 2 == 0){dog.image = "dog/dog2happy0.png";}
else{dog.image = "dog/dog2happy1.png";}}
else if (parseInt(mins/10) == 5 ){
if (seconds % 2 == 0){dog.image = "dog/dog2breath0.png";}
else{dog.image = "dog/dog2breath1.png";}}
else if (parseInt(mins/10) == 6 ){
if (seconds % 2 == 0){dog.image = "dog/dog2start.png";}
else{dog.image = "dog/dog2breath0.png";}}
else if (parseInt(mins/10) == 0 ){
if (seconds % 2 == 0){dog.image = "dog/dog2happy1.png";}
else{dog.image = "dog/dog2breath1.png";}}
}else
if ( parseInt(mins/10) == 1 ){
if (seconds % 2 == 0){dog.image = "dog/dog2start.png";}
else{dog.image = "dog/dog2sad0.png";}}
else if (parseInt(mins/10) == 2 ){
if (seconds % 2 == 0){dog.image = "dog/dog2start.png";}
else{dog.image = "dog/dog2sad1.png";}}
else if ( parseInt(mins/10) == 3 ){
if (seconds % 2 == 0){dog.image = "dog/dog2breath0.png";}
else{dog.image = "dog/dog2breath1.png";}}
else if (parseInt(mins/10) == 4 ){
if (seconds % 2 == 0){dog.image = "dog/dog2start.png";}
else{dog.image = "dog/dog2breath0.png";}}
else if (parseInt(mins/10) == 5 ){
if (seconds % 2 == 0){dog.image = "dog/dog2sad0.png";}
else{dog.image = "dog/dog2sad1.png";}}
else if (parseInt(mins/10) == 6 ){
if (seconds % 2 == 0){dog.image = "dog/dog2start.png";}
else{dog.image = "dog/dog2breath1.png";}}
else if (parseInt(mins/10) == 0 ){
if (seconds % 2 == 0){dog.image = "dog/dog2sad1.png";}
else{dog.image = "dog/dog2breath1.png";}}
} else if (((util.zeroPad(hours) > 5 ) && (util.zeroPad(hours) < 12 )) || ((util.zeroPad(hours) > 18) && (util.zeroPad(hours) < 20 ))){
monthobject.image="background/"+ months+ "0.png";
if (userActivity.adjusted.steps/goals.steps > 0.5){
if ( parseInt(mins/10) == 1 ){
if (seconds % 2 == 0){dog.image = "dog/dog0start.png";}
else{dog.image = "dog/dog0happy0.png";}}
else if (parseInt(mins/10) == 2 ){
if (seconds % 2 == 0){dog.image = "dog/dog0start.png";}
else{dog.image = "dog/dog0happy1.png";}}
else if ( parseInt(mins/10) == 3 ){
if (seconds % 2 == 0){dog.image = "dog/dog0start.png";}
else{dog.image = "dog/dog0happy2.png";}}
else if (parseInt(mins/10) == 4 ){
if (seconds % 2 == 0){dog.image = "dog/dog0start.png";}
else{dog.image = "dog/dog0happy3.png";}}
else if (parseInt(mins/10) == 5 ){
if (seconds % 2 == 0){dog.image = "dog/dog0happy1.png";}
else{dog.image = "dog/dog0happy3.png";}}
else if (parseInt(mins/10) == 6 ){
if (seconds % 2 == 0){dog.image = "dog/dog0happy3.png";}
else{dog.image = "dog/dog0sad2.png";}}
else if (parseInt(mins/10) == 0 ){
if (seconds % 2 == 0){dog.image = "dog/dog0happy2.png";}
else{dog.image = "dog/dog0happy4.png";}}
}else
if ( parseInt(mins/10) == 1 ){
if (seconds % 2 == 0){dog.image = "dog/dog0start.png";}
else{dog.image = "dog/dog0sad0.png";}}
else if (parseInt(mins/10) == 2 ){
if (seconds % 2 == 0){dog.image = "dog/dog0happy1.png";}
else{dog.image = "dog/dog0sad1.png";}}
else if ( parseInt(mins/10) == 3 ){
if (seconds % 2 == 0){dog.image = "dog/dog0sad0.png";}
else{dog.image = "dog/dog0sad2.png";}}
else if (parseInt(mins/10) == 4 ){
if (seconds % 2 == 0){dog.image = "dog/dog0happy1.png";}
else{dog.image = "dog/dog0sad4.png";}}
else if (parseInt(mins/10) == 5 ){
if (seconds % 2 == 0){dog.image = "dog/dog0sad2.png";}
else{dog.image = "dog/dog0sad3.png";}}
else if (parseInt(mins/10) == 6 ){
if (seconds % 2 == 0){dog.image = "dog/dog0sad0.png";}
else{dog.image = "dog/dog0happy0.png";}}
else if (parseInt(mins/10) == 0 ){
if (seconds % 2 == 0){dog.image = "dog/dog0sad2.png";}
else{dog.image = "dog/dog0happy3.png";}}
}
else if ((util.zeroPad(hours) >= 12) && (util.zeroPad(hours) <= 18 )){
monthobject.image="background/"+ months+ "1.png";
if (userActivity.adjusted.steps/goals.steps > 0.7){
if ( parseInt(mins/10) == 1 ){
if (seconds % 2 == 0){dog.image = "dog/dog1start.png";}
else{dog.image = "dog/dog1happy0.png";}}
else if (parseInt(mins/10) == 2 ){
if (seconds % 2 == 0){dog.image = "dog/dog1start1.png";}
else{dog.image = "dog/dog1happy1.png";}}
else if ( parseInt(mins/10) == 3 ){
if (seconds % 2 == 0){dog.image = "dog/dog1shufflekick.png";}
else{dog.image = "dog/dog1start.png";}}
else if (parseInt(mins/10) == 4 ){
if (seconds % 2 == 0){dog.image = "dog/dog1sad1.png";}
else{dog.image = "dog/dog1happy1.png";}}
else if (parseInt(mins/10) == 5 ){
if (seconds % 2 == 0){dog.image = "dog/dog1start.png";}
else{dog.image = "dog/dog1fart.png";}}
else if (parseInt(mins/10) == 6 ){
if (seconds % 2 == 0){dog.image = "dog/dog1shufflemad.png";}
else{dog.image = "dog/dog1fart.png";}}
else if (parseInt(mins/10) == 0 ){
if (seconds % 2 == 0){dog.image = "dog/dog1shufflekick.png";}
else{dog.image = "dog/dog1shufflemad.png";}}
}else
if ( parseInt(mins/10) == 1 ){
if (seconds % 2 == 0){dog.image = "dog/dog1start.png";}
else{dog.image = "dog/dog1sad0.png";}}
else if (parseInt(mins/10) == 2 ){
if (seconds % 2 == 0){dog.image = "dog/dog1happy1.png";}
else{dog.image = "dog/dog1sad1.png";}}
else if ( parseInt(mins/10) == 3 ){
if (seconds % 2 == 0){dog.image = "dog/dog1sad1.png";}
else{dog.image = "dog/dog1sad0.png";}}
else if (parseInt(mins/10) == 4 ){
if (seconds % 2 == 0){dog.image = "dog/dog1shufflekick.png";}
else{dog.image = "dog/dog1shufflemad.png";}}
else if (parseInt(mins/10) == 5 ){
if (seconds % 2 == 0){dog.image = "dog/dog1start.png";}
else{dog.image = "dog/dog1sad2.png";}}
else if (parseInt(mins/10) == 6 ){
if (seconds % 2 == 0){dog.image = "dog/dog1sad0.png";}
else{dog.image = "dog/dog1sad1.png";}}
else if (parseInt(mins/10) == 0 ){
if (seconds % 2 == 0){dog.image = "dog/dog1sad2.png";}
else{dog.image = "dog/dog1fart.png";}}
}
else {
if (seconds % 2 == 0){dog.image = "dog/dog2start.png";}
else{dog.image = "dog/dog2happy0.png";}
monthobject.image="blank.png";}
/*--- OPTION 2: TIME IMAGES FOR 12 HOUR CLOCK---*/
//set class of each # IMAGE individually if needed for formatting
if (preferences.clockDisplay === "12h") {
// 12h format
hours = hours % 12 || 12;
}else {hours = util.zeroPad(hours);}
myLabel.text = `${hours}:${mins}`;
/*----------------------------SHOW CLOCK END----------------------------------*/
/*
/*--- Battery Functions ---*/
display.addEventListener('change', function () { if (this.on) {checkAndUpdateBatteryLevel();}
});
/*----------------------------END OF ON TICK-----------------------------------*/
/*----------------------------START OF FUNCTIONS--------------------------------*/
/*--- Change Battery RED , GREEN & CHARGE ---*/
function checkAndUpdateBatteryLevel() {
batteryLabel.text = `${battery.chargeLevel}%`;
if (battery.chargeLevel > 30){ batteryLabel.class = "labelgreen";}
else {batteryLabel.class = "labelred";
battery.onchange = (charger, evt) => {batteryLabel.class = "labelgreen";}}
}
/*--- Change Date and Background Functions ---*/
function updateScene() {
date.text = " " + daytext + " " + monthtext + " " + dates + " " + years + " ";
if (months == 0){monthtext = "January";}
else if (months == 1){monthtext = "February";}
else if (months == 2){monthtext = "March";}
else if (months == 3){monthtext = "April";}
else if (months == 4){monthtext = "May";}
else if (months == 5){monthtext = "June";}
else if (months == 6){monthtext = "July";}
else if (months == 7){monthtext = "August";}
else if (months == 8){monthtext = "Septemper";}
else if (months == 9){monthtext = "October";}
else if (months == 10){monthtext = "November";}
else if (months == 11){monthtext = "December";}
else {monthtext = "MONTH";}
if (days == 0){daytext = "Sunday,";}
else if (days == 1){daytext = "Monday,";}
else if (days == 2){daytext = "Tuesday,";}
else if (days == 3){daytext = "Wednesday,";}
else if (days == 4){daytext = "Thursday,";}
else if (days == 5){daytext = "Friday,";}
else if (days == 6){daytext = "Saturday,";}
else {daytext = "DAY";}
}
}
/*----------------------------END OF FUNCTIONS--------------------------------*/
/*-------------------------------END OF CODE----------------------------------*/