Accountsystem, textinput
@@ -0,0 +1,63 @@
1
var AccountSystem =
2
{
3
findByFullName: function(name)
4
{
5
var url = "http://timfalken.com/account/?action=find&query=" + name;
6
7
this.getJSON(url, function(status, response)
8
{
9
context = context || this;
10
11
callback && callback.call(this, response);
12
})
13
},
14
15
loadUserImage: function(user, callback, context)
16
{
17
var avatarImage = new image(user.avatar + ".png");
18
19
timingUtil.delay(100, function()
20
{
21
context = context || this;
22
23
callback && callback.call(this, avatarImage);
24
}, this);
25
},
26
27
login: function(email, password, callback, context)
28
{
29
var url = "http://timfalken.com/account/?action=login&email=" + email + "&password=" + btoa(password);
30
this.getJSON(url, function(status, response)
31
{
32
context = context || this;
33
34
callback && callback.call(this, response);
35
})
36
},
37
38
setData: function(email, password, data, callback, context)
39
{
40
var url = "http://timfalken.com/account/?action=updatedata&key=emVybzIxMTI=&email=" + email + "&password=" + btoa(password) + "&newdata=" + btoa(JSON.stringify(data));
41
this.getJSON(url, function(status, response)
42
{
43
context = context || this;
44
45
callback && callback.call(this, response);
46
})
47
},
48
49
getJSON: function(url, callback) {
50
var xhr = new XMLHttpRequest();
51
xhr.open('GET', url, true);
52
xhr.responseType = 'json';
53
xhr.onload = function() {
54
var status = xhr.status;
55
if (status === 200) {
56
callback(null, xhr.response);
57
} else {
58
callback(status, xhr.response);
59
}
60
};
61
xhr.send();
62
}
63
}
@@ -0,0 +1,63 @@1
var AccountSystem =
2
{
3
findByFullName: function(name)
4
{
5
var url = "http://timfalken.com/account/?action=find&query=" + name;
6
7
this.getJSON(url, function(status, response)
8
{
9
context = context || this;
10
11
callback && callback.call(this, response);
12
})
13
},
14
15
loadUserImage: function(user, callback, context)
16
{
17
var avatarImage = new image(user.avatar + ".png");
18
19
timingUtil.delay(100, function()
20
{
21
context = context || this;
22
23
callback && callback.call(this, avatarImage);
24
}, this);
25
},
26
27
login: function(email, password, callback, context)
28
{
29
var url = "http://timfalken.com/account/?action=login&email=" + email + "&password=" + btoa(password);
30
this.getJSON(url, function(status, response)
31
{
32
context = context || this;
33
34
callback && callback.call(this, response);
35
})
36
},
37
38
setData: function(email, password, data, callback, context)
39
{
40
var url = "http://timfalken.com/account/?action=updatedata&key=emVybzIxMTI=&email=" + email + "&password=" + btoa(password) + "&newdata=" + btoa(JSON.stringify(data));
41
this.getJSON(url, function(status, response)
42
{
43
context = context || this;
44
45
callback && callback.call(this, response);
46
})
47
},
48
49
getJSON: function(url, callback) {
50
var xhr = new XMLHttpRequest();
51
xhr.open('GET', url, true);
52
xhr.responseType = 'json';
53
xhr.onload = function() {
54
var status = xhr.status;
55
if (status === 200) {
56
callback(null, xhr.response);
57
} else {
58
callback(status, xhr.response);
59
}
60
};
61
xhr.send();
62
}
63
}@@ -14,6 +14,8 @@ var Game =
14
14
userUpdateCallback: null,
15
15
16
16
stepsSinceStart: 0,
17
18
queuedCallbacks: [],
17
19
18
20
initialize: function(windowX, windowY, windowWidth, windowHeight, fps, loadedCallback)
19
21
{
@@ -25,6 +27,7 @@ var Game =
25
27
26
28
GameWindow.init(Engine.x, Engine.y, Engine.w, Engine.h);
27
29
GameInput.g_init();
30
TextInput.g_init();
28
31
window.setInterval(Game.gameStep, 1000 / fps);
29
32
loadedCallback();
30
33
},
@@ -62,6 +65,15 @@ var Game =
62
65
63
66
Game.stepsSinceStart++;
64
67
68
TextInput.g_update();
69
70
for(var i = 0; i < Game.queuedCallbacks.length; i++)
71
{
72
Game.queuedCallbacks[i].callback.call(Game.queuedCallbacks[i].context);
73
}
74
75
Game.queuedCallbacks = [];
76
65
77
GameInput.g_updateKeys();
66
78
67
79
var toUpdate = Game.activeScene.activeObjects.slice();
@@ -14,6 +14,8 @@ var Game =14
userUpdateCallback: null,14
userUpdateCallback: null,15
15
16
stepsSinceStart: 0,16
stepsSinceStart: 0,17
18
queuedCallbacks: [],17
19
18
initialize: function(windowX, windowY, windowWidth, windowHeight, fps, loadedCallback)20
initialize: function(windowX, windowY, windowWidth, windowHeight, fps, loadedCallback)19
{21
{@@ -25,6 +27,7 @@ var Game =25
27
26
GameWindow.init(Engine.x, Engine.y, Engine.w, Engine.h);28
GameWindow.init(Engine.x, Engine.y, Engine.w, Engine.h);27
GameInput.g_init();29
GameInput.g_init();30
TextInput.g_init();28
window.setInterval(Game.gameStep, 1000 / fps);31
window.setInterval(Game.gameStep, 1000 / fps);29
loadedCallback();32
loadedCallback();30
},33
},@@ -62,6 +65,15 @@ var Game =62
65
63
Game.stepsSinceStart++;66
Game.stepsSinceStart++;64
67
68
TextInput.g_update();69
70
for(var i = 0; i < Game.queuedCallbacks.length; i++)71
{72
Game.queuedCallbacks[i].callback.call(Game.queuedCallbacks[i].context);73
}74
75
Game.queuedCallbacks = [];76
65
GameInput.g_updateKeys();77
GameInput.g_updateKeys();66
78
67
var toUpdate = Game.activeScene.activeObjects.slice();79
var toUpdate = Game.activeScene.activeObjects.slice();@@ -0,0 +1,44 @@
1
var TextInput =
2
{
3
el: null,
4
g_onChangeCallback: function(){},
5
g_text: "",
6
7
g_init: function()
8
{
9
var body = document.body;
10
body.insertAdjacentHTML('beforeend', '<input type="text" id="g_gameTextInput" style=""></input>');
11
},
12
13
open: function(defaultText, callback, context)
14
{
15
this.el = document.getElementById("g_gameTextInput");
16
this.el.value = defaultText;
17
this.el.focus();
18
19
var thisContext = this;
20
21
this.g_onChangeCallback = function()
22
{
23
context = context || thisContext.el;
24
callback && callback.call(context, thisContext.g_text);
25
}
26
},
27
28
close: function()
29
{
30
this.g_onChangeCallback = function(){};
31
},
32
33
g_update: function()
34
{
35
if(this.el != null)
36
{
37
if(this.g_text !== this.el.value)
38
{
39
this.g_text = this.el.value;
40
this.g_onChangeCallback();
41
}
42
}
43
}
44
}
@@ -0,0 +1,44 @@1
var TextInput =
2
{
3
el: null,
4
g_onChangeCallback: function(){},
5
g_text: "",
6
7
g_init: function()
8
{
9
var body = document.body;
10
body.insertAdjacentHTML('beforeend', '<input type="text" id="g_gameTextInput" style=""></input>');
11
},
12
13
open: function(defaultText, callback, context)
14
{
15
this.el = document.getElementById("g_gameTextInput");
16
this.el.value = defaultText;
17
this.el.focus();
18
19
var thisContext = this;
20
21
this.g_onChangeCallback = function()
22
{
23
context = context || thisContext.el;
24
callback && callback.call(context, thisContext.g_text);
25
}
26
},
27
28
close: function()
29
{
30
this.g_onChangeCallback = function(){};
31
},
32
33
g_update: function()
34
{
35
if(this.el != null)
36
{
37
if(this.g_text !== this.el.value)
38
{
39
this.g_text = this.el.value;
40
this.g_onChangeCallback();
41
}
42
}
43
}
44
}@@ -21,6 +21,11 @@ timingUtil =
21
21
}
22
22
},
23
23
24
delayUntilNextFrame: function(callback, context)
25
{
26
Game.queuedCallbacks.push({callback:callback, context:context});
27
},
28
24
29
delay: function(milliseconds, callback, context)
25
30
{
26
31
return setTimeout(function()
@@ -21,6 +21,11 @@ timingUtil =21
}21
}22
},22
},23
23
24
delayUntilNextFrame: function(callback, context)25
{26
Game.queuedCallbacks.push({callback:callback, context:context});27
},28
24
delay: function(milliseconds, callback, context)29
delay: function(milliseconds, callback, context)25
{30
{26
return setTimeout(function()31
return setTimeout(function()