Skip to content

Commit 5e7f417

Browse files
authored
Merge pull request #13 from Moderrek/dev-1.0.8
User Input, "Camera", isTouching update 1.0.8
2 parents a3a8410 + 0cf4fb4 commit 5e7f417

66 files changed

Lines changed: 2917 additions & 2323 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.github
2+
.idea
3+
dev
4+
dist
5+
doc
6+
docs
7+
examples
8+
node_modules
9+
.eslintrc.js

.eslintrc.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es2021: true,
5+
},
6+
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
7+
overrides: [],
8+
parser: '@typescript-eslint/parser',
9+
parserOptions: {
10+
ecmaVersion: 'latest',
11+
sourceType: 'module',
12+
},
13+
plugins: ['@typescript-eslint'],
14+
rules: {
15+
'func-call-spacing': 'error',
16+
'func-name-matching': 'error',
17+
'func-style': ['error', 'declaration', { allowArrowFunctions: true }],
18+
'key-spacing': 'error',
19+
'keyword-spacing': 'error',
20+
'linebreak-style': 'error',
21+
'max-len': ['error', {
22+
code: 120,
23+
ignorePattern: '^// Flags:',
24+
ignoreRegExpLiterals: true,
25+
ignoreTemplateLiterals: true,
26+
ignoreUrls: true,
27+
tabWidth: 2,
28+
}],
29+
'no-confusing-arrow': 'error',
30+
'no-constructor-return': 'error',
31+
'no-duplicate-imports': 'error',
32+
'no-return-await': 'error',
33+
'no-self-compare': 'error',
34+
'no-tabs': 'error',
35+
'no-template-curly-in-string': 'error',
36+
'no-throw-literal': 'error',
37+
'no-trailing-spaces': 'error',
38+
'no-undef': ['error', { typeof: true }],
39+
'no-undef-init': 'error',
40+
'no-unused-expressions': ['error', { allowShortCircuit: true }],
41+
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
42+
'no-unused-vars': 'off',
43+
'@typescript-eslint/no-unused-vars': 'error',
44+
'no-use-before-define': ['error', {
45+
classes: true,
46+
functions: false,
47+
variables: false,
48+
}],
49+
'no-useless-call': 'error',
50+
'no-useless-concat': 'error',
51+
'no-useless-constructor': 'error',
52+
'no-useless-return': 'error',
53+
'no-var': 'error',
54+
'no-void': 'error',
55+
'no-whitespace-before-property': 'error',
56+
'object-curly-newline': 'error',
57+
'object-curly-spacing': ['error', 'always'],
58+
'one-var': ['error', { initialized: 'never' }],
59+
'one-var-declaration-per-line': 'error',
60+
'operator-linebreak': ['error', 'after'],
61+
'padding-line-between-statements': [
62+
'error',
63+
{ blankLine: 'always', prev: 'function', next: 'function' },
64+
],
65+
'prefer-const': ['error', { ignoreReadBeforeAssign: true }],
66+
'prefer-object-has-own': 'error',
67+
'quotes': ['error', 'single', { avoidEscape: true }],
68+
'quote-props': ['error', 'consistent'],
69+
'rest-spread-spacing': 'error',
70+
'semi': 'error',
71+
'semi-spacing': 'error',
72+
'strict': ['error', 'global'],
73+
'jsdoc/require-jsdoc': 'off',
74+
'jsdoc/require-param-description': 'off',
75+
'jsdoc/newline-after-description': 'off',
76+
'jsdoc/require-returns-description': 'off',
77+
'jsdoc/valid-types': 'off',
78+
'jsdoc/no-undefined-types': 'off',
79+
'jsdoc/require-param': 'off',
80+
'jsdoc/check-tag-names': 'off',
81+
'jsdoc/require-returns': 'off',
82+
},
83+
};

.npmignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/doc
12
/docs
23
/dev
34
/examples
@@ -6,4 +7,7 @@
67
.gitattributes
78
.gitignore
89
tsconfig.json
9-
webpack.config.js
10+
webpack.config.js
11+
.prettierrc
12+
.eslintignore
13+
.eslintrc.js

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"arrowParens": "avoid"
5+
}

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# JSGL Changelog
2+
Select a JSGL version below to view the changelog history:
3+
* [JSGL v1.0.8](https://github.com/Moderrek/JSGL/blob/release/doc/changelogs/CHANGELOG-1.0.8.md) **Current**
4+
* [JSGL v1.0.7](https://github.com/Moderrek/JSGL/blob/release/doc/changelogs/CHANGELOG-1.0.7.md) **Long Term Support**

CONTRIBUTION.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Contributions
2+
3+
Tymon Woźniak <tymon.wozniak@my.com>

doc/changelogs/CHANGELOG-1.0.7.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# JSGL - Stable version update 1.0.7
2+
From now the JSGL library will not undergo major changes. (i.e. renaming a function, etc.)
3+
## New
4+
* Added DOM detection and possibility to manually assign the document.
5+
* Added `OnMouseHoverStart` `OnMouseHoverEnd` `OnMouseDown` `OnMouseUp` event function in ClickableGameObject.
6+
* Reworked Vector2.
7+
* Reworked Transform.
8+
* Reworked Game start.
9+
* New function `Renderer.fill(color | draw settings | image)`.
10+
## Changes
11+
* By default `Game.Update()` is invoked every frame. To change this set `drawAlways=true` in GameSettings
12+
* Removed JSGL.version constant.
13+
* Corrected documentation. https://jsglreference.pl
14+
* GameObject
15+
* * `GameObject.OnStart(event)` -> `GameObject.Start(event)`
16+
* * `GameObject.OnDestroy(event)` -> `GameObject.Destroy(event)`
17+
## Fixes
18+
* None.
19+
# Presentation of news
20+
### GameObject Update
21+
From
22+
```js
23+
class Object extends JSGL.GameObject {
24+
OnStart(event){}
25+
OnDestroy(event){}
26+
}
27+
```
28+
To
29+
```js
30+
class Object extends JSGL.GameObject {
31+
Start(event){}
32+
Destroy(event){}
33+
}
34+
```
35+
### TickEvent Update
36+
* New property `Game.timeScale`. Represents scale of time.
37+
* Now `deltaTime` is scaled by `Game.timeScale`.
38+
* New event value `unscaledDeltaTime` is deltaTime without `Game.timeScale` multiplication.
39+
* New event value `unscaledTime`. This value represents time from game start in seconds.
40+
### Vector2 ReWork
41+
* New static method `Lerp(Vector2, Vector2, decimal midpoint)`
42+
* New static method `Max(Vector2, Vector2)`
43+
* New static method `Min(Vector2, Vector2)`
44+
* New static property `Vector2.zero` = `(0, 0)`
45+
* New static property `Vector2.one` = `(1, 1)`
46+
* New static property `Vector2.up` = `(0, 1)`
47+
* New static property `Vector2.down` = `(0, -1)`
48+
* New static property `Vector2.right` = `(1, 0)`
49+
* New static property `Vector2.left` = `(-1, 0)`
50+
* New method `set(Vector2)` | `set(x, y)`
51+
* New method `add(Vector2)` | `add(x, y)`
52+
* New method `subtract(Vector2)` | `subtract(x, y)`
53+
* New method `multiply(Vector2)` | `multiply(scalar)`
54+
* New method `divide(Vector2)` | `divide(scalar)`
55+
* New method `distance(Vector2)` | `distance(x, y)`
56+
* New method `floor()`
57+
### Transform ReWork
58+
* New property `angles`. Gets/sets rotation in radians.
59+
* New property `eulerAngles`. Gets/sets rotation in degrees.
60+
* New property `positionCenter`.
61+
* New property `forward`. Gets Vector2 value in direction.
62+
* New property `backward`. Gets Vector2 value opposite to direction.
63+
* New method `ifOnEdgeBounce(grid)`
64+
* New method `set(Vector2)` | `set(x, y)`
65+
* New method `setX(Vector2)` | `setX(x)`
66+
* New method `setY(Vector2)` | `setY(y)`
67+
* New method `translate(Vector2)` | `translate(x, y)`
68+
* New method `translateX(Vector2)` | `translateX(x)`
69+
* New method `translateY(Vector2)` | `translateY(x)`
70+
### Better Game Starting
71+
```js
72+
game.LoadGameAndStart().then((gameStartEvent) => {
73+
console.log("Game sucessfully loaded!");
74+
}).catch((error) => {
75+
console.error("Encountered error @ game loading/after loading!", error);
76+
}).finally(() => {
77+
console.log("After success/error");
78+
});
79+
```
80+
### ClickableGameObject Update
81+
* New property `ignoreRaycast` set to `true` if you want to ignore mouse events.
82+
```js
83+
class MouseTest extends JSGL.ClickableGameObject {
84+
OnMouseClick = (e) => console.log('mouse click');
85+
OnMouseDown = (e) => console.log('mouse down');
86+
OnMouseUp = (e) => console.log('mouse up');
87+
OnMouseHoverStart = (e) => console.log('mouse hover start');
88+
OnMouseHoverEnd = (e) => console.log('mouse hover end');
89+
}
90+
```

doc/changelogs/CHANGELOG-1.0.8.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# JSGL - User Input, "Camera", isTouching update 1.0.8
2+
## New
3+
* Added changelogs
4+
* Game Events
5+
* * `mouseScroll` - emits GameMouseEvent
6+
* * `keyDown` - emits GameKeyEvent
7+
* * `keyUp` - emits GameKeyEvent
8+
* "Camera" is more like to view offset. You can find it in `game.canvasViewOffset`. This property is a Vector2.
9+
* Added `DrawableGameObject.IsTouching(drawGameObj, drawGameObj2)` static method and `drawableGameObject.isTouching(drawGameObj)`
10+
* Added `JSGL.log(content)`, `JSGL.warn(content)`, `JSGL.error(content)`. Prints message to dev console with format `[DATE] [LEVEL] content`
11+
## Changes
12+
* Deprecated
13+
* * `game.mousePos` - Instead use `game.input.mouseWorldPosition`
14+
* * `game.mouseClientPos` - Instead use `game.input.mouseClientPosition`
15+
* * `game.mousePrecisePos` - Instead use `game.input.mousePreciseWorldPosition`
16+
* * `game.isMousePrimaryButtonDown()` - Instead use `game.input.isMousePrimaryButtonDown`
17+
* Now GameMouseEvent has properties from `game.input`. (Only about mouse)
18+
## Fixes
19+
* None.
20+
# Presentation of news
21+
### Mouse wheel handling
22+
In GameObject
23+
```js
24+
...
25+
Update(event){
26+
event.game.input.mouseScrollDelta.y; // x is ignored
27+
}
28+
...
29+
```
30+
Without GameObject
31+
```js
32+
game.on('mouseScroll', (event) => {
33+
event.mouseScrollDelta.y; // x is ignored
34+
});
35+
```
36+
### How to work with input
37+
In GameObject
38+
```js
39+
...
40+
Update(event){
41+
event.game.input.isKeyDown('w'); // <-- returns is 'w' pressed down
42+
event.game.input.isKeyUp('s'); // <-- returns is 's' clicked
43+
}
44+
...
45+
```
46+
Without GameObject
47+
```js
48+
...
49+
game.on('keyUp' (event) => {
50+
event.input.isKeyUp('s'); // <-- returns is 's' clicked
51+
});
52+
game.on('keyDown' (event) => {
53+
event.input.isKeyDown('w'); // <-- returns is 'w' pressed down
54+
});
55+
...
56+
```

examples/boucing_rect/game.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
/*
22
https://jsglreference.pl/
33
*/
4-
const game = JSGL.DefaultGame.Create({ grid: new JSGL.Vector2(25, 25)}, { backgroundColor: 'black' });
4+
const game = JSGL.DefaultGame.Create({ grid: new JSGL.Vector2(15, 15)}, { backgroundColor: 'black' });
55

66
game.on('draw', (event) => {
77
event.renderer.fillFrame({ color: 'white' });
88
});
99

1010
class BouncingRect extends JSGL.Shape {
11-
Start(event){
12-
console.log("Spawned");
11+
Start(){
1312
this.transform.set(game.GetRandomPosition());
1413
this.showHitbox = true;
1514
this.properties.color = 'black';
@@ -25,7 +24,7 @@ class BouncingRect extends JSGL.Shape {
2524
game.LoadGameAndStart().then(() => {
2625
// Delayed for
2726
const delay = 1000;
28-
const count = 5;
27+
const count = 8;
2928
//
3029
let i = 0;
3130
let taskId = setInterval(() => {

examples/boucing_rect/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<title>JSGL - Bouncing Rect</title>
88
</head>
99
<body>
10-
<script src="https://unpkg.com/@moderrkowo/jsgl@1.0.7/dist/JSGL.js"></script>
10+
<script src="https://unpkg.com/@moderrkowo/jsgl@1.0.8/dist/JSGL.js"></script>
1111
<script src="game.js"></script>
1212
</body>
1313
</html>

0 commit comments

Comments
 (0)