-
Notifications
You must be signed in to change notification settings - Fork 1
/
userLog.html
148 lines (139 loc) · 5.54 KB
/
userLog.html
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
<!DOCTYPE HTML>
<html>
<!--
This code was taken from
https://www.html5canvastutorials.com/advanced/html5-canvas-blooming-flowers-effect/
-->
<head>
<meta charset="UTF-8">
<title>Flowers Editor</title>
<style type="text/css">
canvas {
margin: 0;
overflow: hidden;
background: -webkit-radial-gradient(left bottom, circle farthest-corner, #e1fd3e, #174709);
background: -moz-radial-gradient(left bottom, circle farthest-corner, #e1fd3e, #174709);
background: -ms-radial-gradient(left bottom, circle farthest-corner, #e1fd3e, #174709);
background: -o-radial-gradient(left bottom, circle farthest-corner, #e1fd3e, #174709);
background: radial-gradient(farthest-corner circle at left bottom, #e1fd3e, #174709);
}
</style>
<body>
<!--
<canvas id="flowerCanvas" width=300 height=300 style="border-style: solid; border-width: 2px"></canvas>
<canvas id="canvas" width=300 height=300 style="border-style: solid; border-width: 2px"></canvas>
-->
<canvas id="flowerCanvas" style="width: 100%; height: 90%;"></canvas>
<div id="controls">
<span id="buttons" class="buttons">
<button id="login">login</button>
<button id="save">save</button>
<span id="userInfo">null</span>
</span>
<span id="canvasStat" class="stats">stats</span><br>
<button id="updateButton">Update</button>
How Happy:<br>
<input id="happySlider" type="range" min="1" max="10"><br>
How Energetic:<br>
<input id="energySlider" type="range" min="2" max="10"><br>
</div>
<!--
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
-->
<script src="js/libs/jquery-3.1.0.min.js"></script>
<script src="js/libs/sprintf.js"></script>
<script src="js/libs/dat.gui.js"></script>
<script src="js/CanvasTool.js"></script>
<script src="js/GardenTool.js"></script>
<script src="js/Flower.js"></script>
<script src="js/util.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.15.5/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.15.5/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.15.5/firebase-database.js"></script>
<script>
var garden;
var gtool;
var editor;
var affect = 5;
var energy = 5;
var flower = null;
async function handleUpdate() {
var user = gtool.user;
console.log("handleUpdate", user);
if (!user)
return;
var t = getClockTime();
var uid = user.uid;
var flowerOpts = flower.getState();
flower.affect = affect;
var mood = {
email: user.email, uid, energy, affect, lastUpdate: t,
};
console.log("mood", mood);
var dbRef = gtool.firebaseDB.ref();
await dbRef.child("/user/state/" + uid + "/mood").set(mood);
await dbRef.child("/user/state/" + uid + "/flower").set(flowerOpts);
}
async function showUserUpdate(field, val) {
var user = gtool.user;
var t = getClockTime();
console.log(field, val, user);
if (user) {
var uid = user.uid;
var userState = {
email: user.email, uid, energy: 3, affect: 5, lastUpdate: t
};
userState[field] = Number(val);
console.log("userState", userState);
var dbRef = gtool.firebaseDB.ref();
//await dbRef.child("/userState/" + uid).set(userState);
await dbRef.child("/user/state/" + uid + "/mood").set(userState);
}
}
async function getFlowerOpts() {
if (!gtool.user) {
alert("No user id -- maybe you need to login");
return;
}
var uid = gtool.user.uid;
var opts = await gtool.getObjFromDB('/user/state/'+uid);
console.log("****** got opts", opts);
var fOpts = opts.flower;
console.log("**** got fOpts", fOpts);
flower.setProps(fOpts);
}
async function setupEditor() {
var opts = {};
var ftype = getParameterByName("flowerType");
if (ftype)
opts.type = ftype;
console.log("create flower");
var f = await gtool.addFlower(opts);
console.log("got it", f);
flower = f;
editor = new FlowerEditor(gtool, f);
setTimeout(getFlowerOpts, 1000);
}
$(document).ready(function () {
//garden = new FlowerGarden();
gtool = new GardenTool("flowerCanvas");
gtool.initFirebase();
gtool.start();
gtool.setView(0, 0, 800);
setupEditor();
$("#happySlider").change((v) => {
console.log("slider input", v);
affect = Number($("#happySlider").val());
console.log("affect", affect);
showUserUpdate("affect", affect);
})
$("#energySlider").change((v) => {
console.log("slider input", v);
energy = Number($("#energySlider").val());
console.log("energy", energy);
showUserUpdate("energy", energy);
});
$("#updateButton").click(handleUpdate);
});
</script>
</body>