wgge 0.1.27 → 0.1.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,10 @@ import IntValue from "./IntValue";
2
2
 
3
3
  export default class FloatValue extends IntValue {
4
4
 
5
+ /**
6
+ *
7
+ * @return Number
8
+ */
5
9
  round() {
6
10
  return Math.round(this.get());
7
11
  }
@@ -2,6 +2,14 @@ import DirtyValue from "./DirtyValue";
2
2
 
3
3
  export default class IntValue extends DirtyValue {
4
4
 
5
+ /**
6
+ *
7
+ * @return Number
8
+ */
9
+ get() {
10
+ return super.get();
11
+ }
12
+
5
13
  set(value) {
6
14
  if (value === null || value === undefined || value === '') {
7
15
  super.set(Number.NaN);
@@ -17,4 +25,8 @@ export default class IntValue extends DirtyValue {
17
25
  increase(num) {
18
26
  this.set(this.get() + num);
19
27
  }
28
+
29
+ multiply(num) {
30
+ this.set(this.get() * num);
31
+ }
20
32
  }
@@ -19,14 +19,26 @@ export default class CanvasRenderer extends RendererBase {
19
19
 
20
20
  }
21
21
 
22
- activateInternal() {
22
+ activate() {
23
23
  this.context2d = this.canvas.getContext('2d');
24
+
25
+ super.activate();
24
26
  }
25
27
 
26
- deactivateInternal() {
28
+ deactivate() {
29
+ super.deactivate();
30
+
27
31
  this.context2d = null;
28
32
  }
29
33
 
34
+ checkContext() {
35
+ const ok = (this.context2d !== null);
36
+ if (!ok) {
37
+ console.error('No context to draw!');
38
+ }
39
+ return ok;
40
+ }
41
+
30
42
  /**
31
43
  *
32
44
  * @param {Vector2} start
@@ -34,6 +46,7 @@ export default class CanvasRenderer extends RendererBase {
34
46
  * @param {CanvasGradient|string} fill
35
47
  */
36
48
  drawRect(start, size, fill = 'black') {
49
+ if (!this.checkContext()) return;
37
50
  const end = start.add(size);
38
51
  this.context2d.fillStyle = fill;
39
52
  this.context2d.fillRect(start.x, start.y, end.x, end.y);
@@ -48,6 +61,7 @@ export default class CanvasRenderer extends RendererBase {
48
61
  * @param {[[Number, string|color]]} stops
49
62
  */
50
63
  drawGradient(start, size, gradientStart, gradientSize, stops) {
64
+ if (!this.checkContext()) return;
51
65
  const gradientEnd = gradientStart.add(gradientSize);
52
66
  const grd = this.context2d.createLinearGradient(gradientStart.x, gradientStart.y, gradientEnd.x, gradientEnd.y);
53
67
  stops.forEach((s) => {
@@ -73,6 +87,7 @@ export default class CanvasRenderer extends RendererBase {
73
87
  startAngle = 0,
74
88
  endAngle = 2 * Math.PI
75
89
  ) {
90
+ if (!this.checkContext()) return;
76
91
  this.context2d.beginPath();
77
92
  this.context2d.fillStyle = (fill) ? fill : 'transparent';
78
93
  this.context2d.strokeStyle = stroke ? stroke.color ? stroke.color : 'orange' : 'transparent';
@@ -94,9 +109,20 @@ export default class CanvasRenderer extends RendererBase {
94
109
  }
95
110
 
96
111
  drawImage(image, drawStart, drawEnd, imageStart, imageEnd, opacity = 1, clear = true) {
97
- if (!(image && this.context2d)) return;
112
+ if (!(image && this.checkContext())) return;
98
113
  if (clear) this.context2d.clearRect(drawStart.x, drawStart.y, drawEnd.x, drawEnd.y);
99
114
  this.context2d.globalAlpha = opacity;
115
+ console.log(
116
+ 'drawing to canvas',
117
+ imageStart.x,
118
+ imageStart.y,
119
+ imageEnd.x,
120
+ imageEnd.y,
121
+ drawStart.x,
122
+ drawStart.y,
123
+ drawEnd.x,
124
+ drawEnd.y
125
+ );
100
126
  this.context2d.drawImage(
101
127
  image,
102
128
  imageStart.x,
@@ -17,7 +17,7 @@ export default class ImageViewRenderer extends DomRenderer {
17
17
  }
18
18
 
19
19
  activateInternal() {
20
- this.canvas = DOMHelper.createElement(this.dom, 'canvas');
20
+ this.canvas = DOMHelper.createElement(this.dom, 'canvas', 'image-view-canvas');
21
21
  this.addChild(new ImageCanvasRenderer(this.game, this.model, this.canvas));
22
22
 
23
23
  this.updateSize();
@@ -73,6 +73,9 @@ export default class ImageViewModel extends ObjectModel {
73
73
  this.viewSize.addEventListener('change', () => this.updateCoordinates());
74
74
  this.actualZoom.addEventListener('change', () => this.updateCoordinates());
75
75
  this.image.size.addEventListener('change', () => this.updateCoordinates());
76
+
77
+ this.updateOpacity();
78
+ this.updateZoom();
76
79
  }
77
80
 
78
81
  updateOpacity() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wgge",
3
- "version": "0.1.27",
3
+ "version": "0.1.29",
4
4
  "description": "Web GL Game Engine",
5
5
  "main": "index.js",
6
6
  "dependencies": {