BlueGit

timfa frameworkv3

move to dirs

timfa Tim · pushed by timfa

Authored 2022-10-15 · 4 years ago

Hash
e719f4ca1aa46406121bd65f8fdbc598b330f7f3
Parent
5c1314b8
15 files changed +147 −147
framework/engine.js framework/engine/engine.js renamed +0 −0
framework/image.js framework/engine/image.js renamed +0 −0
framework/object.js framework/engine/object.js renamed +0 −0
framework/scene.js framework/engine/scene.js renamed +85 −85
@@ -1,86 +1,86 @@
1 class Scene
2 {
3 static idCount = 0;
4 activeObjects = [];
5 position = new vector(0, 0);
6 size = new vector(0, 0);
7 cameraPosition = new vector(0, 0);
8 parentScene = null;
9 fullscreen = false;
10
11 cv_canvas = null;
12 cv_context = null;
13
14 constructor(x, y, width, height, fullscreen = false)
15 {
16 Scene.idCount++;
17
18 this.position.x = x;
19 this.position.y = y;
20 this.size.x = width;
21 this.size.y = height;
22 this.fullscreen = fullscreen;
23
24 let body = document.body;
25
26 body.insertAdjacentHTML('beforeend', '<canvas id="canvas_' + Scene.idCount + '" style="position: absolute; left: ' + x + 'px; top: ' + y + 'px;" width="' + GameWindow.width + '" height="' + GameWindow.height + '"></canvas>');
27
28 this.cv_canvas = document.getElementById('canvas_' + Scene.idCount);
29 this.cv_canvasContext = this.cv_canvas.getContext('2d');
30 }
31
32 backgroundColor =
33 {
34 r: 255,
35 g: 255,
36 b: 255
37 }
38
39 get canvas()
40 {
41 return this.canvas;
42 }
43
44 get context()
45 {
46 return this.canvasContext;
47 }
48
49 addObject(obj)
50 {
51 this.activeObjects.push(obj);
52 }
53
54 destroy()
55 {
56 for(var i = 0; i < this.activeObjects.length; i++)
57 {
58 this.activeObjects[i].destroy();
59 }
60 }
61
62 redraw()
63 {
64 if(this.fullscreen)
65 {
66 this.size.width = window.innerWidth - 2;
67 this.size.height = window.innerHeight - 2;
68 }
69
70 this.canvas.width = this.size.width;
71 this.canvas.height = this.size.height;
72
73 this.canvas.style = 'position: absolute; left: ' + this.position.x + 'px; top: ' + this.position.y + 'px;'; //todo: only call when changed?
74
75 this.canvasContext.fillStyle = "rgb(" + this.backgroundColor.r + "," + GameWindow.backgroundColor.g + "," + GameWindow.backgroundColor.b + ")"; // sets the color to fill in the rectangle with
76 this.canvasContext.fillRect(0, 0, this.size.width, this.size.height);
77
78 for(var i = 0; i < this.activeObjects.length; i++)
79 {
80 if(this.activeObjects[i].active && this.activeObjects[i].renderer.visible)
81 this.activeObjects[i].g_draw(this.canvasContext);
82 }
83
84 //requestAnimationFrame(GameWindow.redraw); // <- This must be called in global game update loop!
85 }
1 class Scene
2 {
3 static idCount = 0;
4 activeObjects = [];
5 position = new vector(0, 0);
6 size = new vector(0, 0);
7 cameraPosition = new vector(0, 0);
8 parentScene = null;
9 fullscreen = false;
10
11 cv_canvas = null;
12 cv_context = null;
13
14 constructor(x, y, width, height, fullscreen = false)
15 {
16 Scene.idCount++;
17
18 this.position.x = x;
19 this.position.y = y;
20 this.size.x = width;
21 this.size.y = height;
22 this.fullscreen = fullscreen;
23
24 let body = document.body;
25
26 body.insertAdjacentHTML('beforeend', '<canvas id="canvas_' + Scene.idCount + '" style="position: absolute; left: ' + x + 'px; top: ' + y + 'px;" width="' + GameWindow.width + '" height="' + GameWindow.height + '"></canvas>');
27
28 this.cv_canvas = document.getElementById('canvas_' + Scene.idCount);
29 this.cv_canvasContext = this.cv_canvas.getContext('2d');
30 }
31
32 backgroundColor =
33 {
34 r: 255,
35 g: 255,
36 b: 255
37 }
38
39 get canvas()
40 {
41 return this.canvas;
42 }
43
44 get context()
45 {
46 return this.canvasContext;
47 }
48
49 addObject(obj)
50 {
51 this.activeObjects.push(obj);
52 }
53
54 destroy()
55 {
56 for(var i = 0; i < this.activeObjects.length; i++)
57 {
58 this.activeObjects[i].destroy();
59 }
60 }
61
62 redraw()
63 {
64 if(this.fullscreen)
65 {
66 this.size.width = window.innerWidth - 2;
67 this.size.height = window.innerHeight - 2;
68 }
69
70 this.canvas.width = this.size.width;
71 this.canvas.height = this.size.height;
72
73 this.canvas.style = 'position: absolute; left: ' + this.position.x + 'px; top: ' + this.position.y + 'px;'; //todo: only call when changed?
74
75 this.canvasContext.fillStyle = "rgb(" + this.backgroundColor.r + "," + GameWindow.backgroundColor.g + "," + GameWindow.backgroundColor.b + ")"; // sets the color to fill in the rectangle with
76 this.canvasContext.fillRect(0, 0, this.size.width, this.size.height);
77
78 for(var i = 0; i < this.activeObjects.length; i++)
79 {
80 if(this.activeObjects[i].active && this.activeObjects[i].renderer.visible)
81 this.activeObjects[i].g_draw(this.canvasContext);
82 }
83
84 //requestAnimationFrame(GameWindow.redraw); // <- This must be called in global game update loop!
85 }
86 86 }
@@ -1,86 +1,86 @@
1class Scene
1class Scene
2{
2{
3 static idCount = 0;
3 static idCount = 0;
4 activeObjects = [];
4 activeObjects = [];
5 position = new vector(0, 0);
5 position = new vector(0, 0);
6 size = new vector(0, 0);
6 size = new vector(0, 0);
7 cameraPosition = new vector(0, 0);
7 cameraPosition = new vector(0, 0);
8 parentScene = null;
8 parentScene = null;
9 fullscreen = false;
9 fullscreen = false;
10
10
11 cv_canvas = null;
11 cv_canvas = null;
12 cv_context = null;
12 cv_context = null;
13
13
14 constructor(x, y, width, height, fullscreen = false)
14 constructor(x, y, width, height, fullscreen = false)
15 {
15 {
16 Scene.idCount++;
16 Scene.idCount++;
17
17
18 this.position.x = x;
18 this.position.x = x;
19 this.position.y = y;
19 this.position.y = y;
20 this.size.x = width;
20 this.size.x = width;
21 this.size.y = height;
21 this.size.y = height;
22 this.fullscreen = fullscreen;
22 this.fullscreen = fullscreen;
23
23
24 let body = document.body;
24 let body = document.body;
25
25
26 body.insertAdjacentHTML('beforeend', '<canvas id="canvas_' + Scene.idCount + '" style="position: absolute; left: ' + x + 'px; top: ' + y + 'px;" width="' + GameWindow.width + '" height="' + GameWindow.height + '"></canvas>');
26 body.insertAdjacentHTML('beforeend', '<canvas id="canvas_' + Scene.idCount + '" style="position: absolute; left: ' + x + 'px; top: ' + y + 'px;" width="' + GameWindow.width + '" height="' + GameWindow.height + '"></canvas>');
27
27
28 this.cv_canvas = document.getElementById('canvas_' + Scene.idCount);
28 this.cv_canvas = document.getElementById('canvas_' + Scene.idCount);
29 this.cv_canvasContext = this.cv_canvas.getContext('2d');
29 this.cv_canvasContext = this.cv_canvas.getContext('2d');
30 }
30 }
31
31
32 backgroundColor =
32 backgroundColor =
33 {
33 {
34 r: 255,
34 r: 255,
35 g: 255,
35 g: 255,
36 b: 255
36 b: 255
37 }
37 }
38
38
39 get canvas()
39 get canvas()
40 {
40 {
41 return this.canvas;
41 return this.canvas;
42 }
42 }
43
43
44 get context()
44 get context()
45 {
45 {
46 return this.canvasContext;
46 return this.canvasContext;
47 }
47 }
48
48
49 addObject(obj)
49 addObject(obj)
50 {
50 {
51 this.activeObjects.push(obj);
51 this.activeObjects.push(obj);
52 }
52 }
53
53
54 destroy()
54 destroy()
55 {
55 {
56 for(var i = 0; i < this.activeObjects.length; i++)
56 for(var i = 0; i < this.activeObjects.length; i++)
57 {
57 {
58 this.activeObjects[i].destroy();
58 this.activeObjects[i].destroy();
59 }
59 }
60 }
60 }
61
61
62 redraw()
62 redraw()
63 {
63 {
64 if(this.fullscreen)
64 if(this.fullscreen)
65 {
65 {
66 this.size.width = window.innerWidth - 2;
66 this.size.width = window.innerWidth - 2;
67 this.size.height = window.innerHeight - 2;
67 this.size.height = window.innerHeight - 2;
68 }
68 }
69
69
70 this.canvas.width = this.size.width;
70 this.canvas.width = this.size.width;
71 this.canvas.height = this.size.height;
71 this.canvas.height = this.size.height;
72
72
73 this.canvas.style = 'position: absolute; left: ' + this.position.x + 'px; top: ' + this.position.y + 'px;'; //todo: only call when changed?
73 this.canvas.style = 'position: absolute; left: ' + this.position.x + 'px; top: ' + this.position.y + 'px;'; //todo: only call when changed?
74
74
75 this.canvasContext.fillStyle = "rgb(" + this.backgroundColor.r + "," + GameWindow.backgroundColor.g + "," + GameWindow.backgroundColor.b + ")"; // sets the color to fill in the rectangle with
75 this.canvasContext.fillStyle = "rgb(" + this.backgroundColor.r + "," + GameWindow.backgroundColor.g + "," + GameWindow.backgroundColor.b + ")"; // sets the color to fill in the rectangle with
76 this.canvasContext.fillRect(0, 0, this.size.width, this.size.height);
76 this.canvasContext.fillRect(0, 0, this.size.width, this.size.height);
77
77
78 for(var i = 0; i < this.activeObjects.length; i++)
78 for(var i = 0; i < this.activeObjects.length; i++)
79 {
79 {
80 if(this.activeObjects[i].active && this.activeObjects[i].renderer.visible)
80 if(this.activeObjects[i].active && this.activeObjects[i].renderer.visible)
81 this.activeObjects[i].g_draw(this.canvasContext);
81 this.activeObjects[i].g_draw(this.canvasContext);
82 }
82 }
83
83
84 //requestAnimationFrame(GameWindow.redraw); // <- This must be called in global game update loop!
84 //requestAnimationFrame(GameWindow.redraw); // <- This must be called in global game update loop!
85 }
85 }
86}
86}
framework/extentions.js framework/extensions/extentions.js renamed +0 −0
framework/polyfills.js framework/extensions/polyfills.js renamed +0 −0
framework/thirdparty.js framework/extensions/thirdparty.js renamed +0 −0
framework/audio.js framework/util/audio.js renamed +0 −0
framework/ease.js framework/util/ease.js renamed +0 −0
framework/input.js framework/util/input.js renamed +0 −0
framework/signal.js framework/util/signal.js renamed +0 −0
framework/textInput.js framework/util/textInput.js renamed +43 −43
@@ -1,44 +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 }
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 44 }
@@ -1,44 +1,44 @@
1var TextInput =
1var TextInput =
2{
2{
3 el: null,
3 el: null,
4 g_onChangeCallback: function(){},
4 g_onChangeCallback: function(){},
5 g_text: "",
5 g_text: "",
6
6
7 g_init: function()
7 g_init: function()
8 {
8 {
9 var body = document.body;
9 var body = document.body;
10 body.insertAdjacentHTML('beforeend', '<input type="text" id="g_gameTextInput" style=""></input>');
10 body.insertAdjacentHTML('beforeend', '<input type="text" id="g_gameTextInput" style=""></input>');
11 },
11 },
12
12
13 open: function(defaultText, callback, context)
13 open: function(defaultText, callback, context)
14 {
14 {
15 this.el = document.getElementById("g_gameTextInput");
15 this.el = document.getElementById("g_gameTextInput");
16 this.el.value = defaultText;
16 this.el.value = defaultText;
17 this.el.focus();
17 this.el.focus();
18
18
19 var thisContext = this;
19 var thisContext = this;
20
20
21 this.g_onChangeCallback = function()
21 this.g_onChangeCallback = function()
22 {
22 {
23 context = context || thisContext.el;
23 context = context || thisContext.el;
24 callback && callback.call(context, thisContext.g_text);
24 callback && callback.call(context, thisContext.g_text);
25 }
25 }
26 },
26 },
27
27
28 close: function()
28 close: function()
29 {
29 {
30 this.g_onChangeCallback = function(){};
30 this.g_onChangeCallback = function(){};
31 },
31 },
32
32
33 g_update: function()
33 g_update: function()
34 {
34 {
35 if(this.el != null)
35 if(this.el != null)
36 {
36 {
37 if(this.g_text !== this.el.value)
37 if(this.g_text !== this.el.value)
38 {
38 {
39 this.g_text = this.el.value;
39 this.g_text = this.el.value;
40 this.g_onChangeCallback();
40 this.g_onChangeCallback();
41 }
41 }
42 }
42 }
43 }
43 }
44}
44}
framework/timingUtil.js framework/util/timingUtil.js renamed +0 −0
framework/urlParams.js framework/util/urlParams.js renamed +19 −19
@@ -1,20 +1,20 @@
1 var UrlParams =
2 {
3 get: function(key)
4 {
5 var url_string = window.location.href
6 var url = new URL(url_string);
7 var c = url.searchParams.get(key);
8
9 return c;
10 },
11
12 set: function(key, value)
13 {
14 var url_string = window.location.href
15 var url = new URL(url_string);
16 url.searchParams.set(key, value);
17
18 window.history.pushState(null, {}, url);
19 }
1 var UrlParams =
2 {
3 get: function(key)
4 {
5 var url_string = window.location.href
6 var url = new URL(url_string);
7 var c = url.searchParams.get(key);
8
9 return c;
10 },
11
12 set: function(key, value)
13 {
14 var url_string = window.location.href
15 var url = new URL(url_string);
16 url.searchParams.set(key, value);
17
18 window.history.pushState(null, {}, url);
19 }
20 20 }
@@ -1,20 +1,20 @@
1var UrlParams =
1var UrlParams =
2{
2{
3 get: function(key)
3 get: function(key)
4 {
4 {
5 var url_string = window.location.href
5 var url_string = window.location.href
6 var url = new URL(url_string);
6 var url = new URL(url_string);
7 var c = url.searchParams.get(key);
7 var c = url.searchParams.get(key);
8
8
9 return c;
9 return c;
10 },
10 },
11
11
12 set: function(key, value)
12 set: function(key, value)
13 {
13 {
14 var url_string = window.location.href
14 var url_string = window.location.href
15 var url = new URL(url_string);
15 var url = new URL(url_string);
16 url.searchParams.set(key, value);
16 url.searchParams.set(key, value);
17
17
18 window.history.pushState(null, {}, url);
18 window.history.pushState(null, {}, url);
19 }
19 }
20}
20}
framework/vector.js framework/util/vector.js renamed +0 −0