Skip to content

Commit 30751f5

Browse files
authored
implementing styles (that works) + Text + some fixes (#9)
* implement first version of docs with mkdocs (only the content will be to update and the ci script if there's a problem now) * setup build project that will be published on npmjs + the updates needed on the build for that * update docs for the new graphic drawing api * fix types * add content on all index.md for documentation * fix typos + remove useless comas + put imports in alphabetical order * fix pb in tests servers + add doc link in both package.json + rename setShortcutHandler in setKeyboardHandler * improve styles system + implement Text * improve api signatures (graphics + keyboard events) * edit docs content to fit with the current version of cazan + improve some api signatures (styles) * edit docs + jsdoc + add 2022-2024 for licenses
1 parent bebe294 commit 30751f5

Some content is hidden

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

56 files changed

+953
-325
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 AeliaDev & cazan contributors
3+
Copyright (c) 2022-2024 AeliaDev & cazan contributors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

dist/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 AeliaDev & cazan contributors
3+
Copyright (c) 2022-2024 AeliaDev & cazan contributors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

dist/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
"bugs": {
2020
"url": "https://github.com/AeliaDev/cazan.js/issues"
2121
},
22-
"homepage": "https://github.com/AeliaDev/cazan.js"
22+
"homepage": "https://aeliadev.github.io/cazan.js"
2323
}

docs/community/licence.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
````
44
MIT License
55
6-
Copyright (c) 2023 AeliaDev & cazan contributors
6+
Copyright (c) 2024 AeliaDev & cazan contributors
77
88
Permission is hereby granted, free of charge, to any person obtaining a copy
99
of this software and associated documentation files (the "Software"), to deal

docs/events/keyboard.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ In this page we'll use the ``cazan.events.keyboard`` namespace.
77
!!!example
88
There's a little example:
99
````js
10-
keyboard.setShortcutHandler({
10+
keyboard.setKeyboardHandler({
1111
on: 'keydown', //(1)!
1212
shortcutCallback: (event) => event.key === 'ArrowLeft', //(2)!
1313
callback: () => { //(3)!
@@ -19,25 +19,25 @@ In this page we'll use the ``cazan.events.keyboard`` namespace.
1919
})
2020
````
2121

22-
1. Define the type of the keyboard listener (`keydown` or `keyup`).
22+
1. Define the type of the keyboard listener (`keydown` or `keyup`). By default, it's 'keydown'.
2323
2. That's here that you define the keys to press, so this function must return a boolean.
2424
3. The function that will be called if the keys are pressed.
2525

2626
This example consists of moving of 10px on the left a rectangle when the left arrow is pressed.
2727

2828
!!! warning
29-
If you want to use a shortcut with ctrl, you should put ``(event.ctrlKey || event.metaKey)`` for multiplatform compatibility.
29+
If you want to use a shortcut with ``ctrl``, you should put ``(event.ctrlKey || event.metaKey)`` for multiplatform compatibility.
3030

3131

3232
## Reference
3333

34-
``SetKeyboardShortcutInterface`` is used for typing ``keyboard.setShortcutHandler()`` params.
34+
``SetKeyboardHandlerInterface`` is used for typing ``keyboard.setKeyboardHandler()`` params.
3535

3636
````ts
37-
interface SetKeyboardShortcutInterface {
38-
on: string & ('keyup' | 'keydown')
37+
interface SetKeyboardHandlerInterface {
38+
on?: string & ('keyup' | 'keydown')
3939
/**
40-
* Define the key combination of the shortcut here.
40+
* Define the key combination of the event here.
4141
* More information on how to set custom keyboard shortcuts : https://stackoverflow.com/a/60279187/21402860
4242
*
4343
* ------------------------------------------------------------------------------------------

docs/events/popups.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ You can use the cazan I/O API to use popups. We are using the ``cazan.events.io`
88

99
### ``io.showMsg()``
1010

11-
Use it when you want to tell to the user an important message, such an announcement or an error, for example.
11+
Use it when you want to tell to the user an important message, such as an announcement or an error, for example.
1212

1313
````js
1414
await io.showMsg({title: "myGame", msg: 'Unknown error', btnText: "Ok"})
@@ -80,12 +80,12 @@ By default, cazan applies a default style on popups;
8080
In fact, it appends a `<style id="cazan-popup-style" text="text/css">` in the end of the `<head>` of your HTML document.
8181

8282
!!!tip
83-
But if you define manually this HTML tag and putting in custom CSS to customize the popups, cazan won't override it.
83+
But if you define manually this HTML tag and putting in custom CSS to customize the popups, Cazan won't override it, and your popup will be customized.
8484

8585
!!! warning
8686
Attention: you can customize everything you want but if you want that it keeps working, don't customize `display`, `position` or `z-index`, these properties are needed because they will be used by cazan.
8787

88-
## References
88+
## Reference
8989

9090
- I/O API: ``IOEventInterface`` is used for typing ``io.showMsg()``, ``io.getUserConfirm()`` and ``io.getUserInput()`` params.
9191
````ts

docs/graphics/circle.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ We'll use the ``cazan.graphics`` namespace here.
66

77
Little example:
88
````js
9-
let myCircle = new graphics.Circle(
10-
game,
11-
{x: 540, y: 100}, //(1)!
12-
25 //(2)!
13-
)
9+
let myCircle = new graphics.Circle({
10+
game: game,
11+
position: {x: 540, y: 100}, //(1)!
12+
radius: 25 //(2)!
13+
})
1414
````
1515

1616
1. The center of the circle.
@@ -30,19 +30,25 @@ class Circle extends Graphic implements CurveInterface, ImageHandlingInterface {
3030
private image?: CanvasImageSource
3131
private drawingOptions: CurveDrawingOptionsInterface
3232

33-
constructor(
34-
game: Game,
35-
position: Position,
36-
private radius: number,
37-
srcImage?: string,
38-
toDisplay?: boolean,
39-
drawingOptions?: CurveDrawingOptionsInterface
40-
) {
41-
}
33+
constructor(options: CircleConstructorInterface) {}
4234

4335
setRadius(radius: number): void {}
4436

4537
getRadius(): number {}
4638
}
4739
````
4840

41+
Information about the constructor:
42+
43+
````ts
44+
interface CircleConstructorInterface {
45+
game: Game,
46+
position: Position,
47+
radius: number,
48+
styles?: GenericGraphicStylesInterface,
49+
srcImage?: string,
50+
toDisplay?: boolean,
51+
drawingOptions?: CurveDrawingOptionsInterface
52+
}
53+
````
54+

docs/graphics/ellipse.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ We'll use the ``cazan.graphics`` namespace here.
66

77
Little example:
88
````js
9-
let myEllispe = new graphics.Ellipse(
10-
game,
11-
{x: 540, y: 100}, //(1)!
12-
25, //(2)!
13-
15, //(3)!
14-
)
9+
let myEllispe = new graphics.Ellipse({
10+
game: game,
11+
position: {x: 540, y: 100}, //(1)!
12+
radiusX: 25, //(2)!
13+
radiusY: 15, //(3)!
14+
})
1515
````
1616

1717
1. The center of the ellipse.
@@ -27,21 +27,14 @@ rad and an end circle different from 2pi rad (the circle is not complete).
2727
For other further information, see the page about ``Graphic``, ``CurveInterface`` and ``CurveDrawingOptionsInterface``.
2828

2929
````ts
30-
export class Ellipse extends Graphic implements CurveInterface {
30+
class Ellipse extends Graphic implements CurveInterface {
3131
private drawingOptions: CurveDrawingOptionsInterface = {
3232
startAngle: 0,
3333
endAngle: Math.PI * 2,
3434
rotation: Math.PI / 4
3535
}
3636

37-
constructor(
38-
game: Game,
39-
position: Position,
40-
protected radiusX: number,
41-
protected radiusY: number,
42-
toDisplay?: boolean,
43-
drawingOptions?: CurveDrawingOptionsInterface
44-
) {}
37+
constructor(options: EllipseConstructorInterface) {}
4538

4639

4740
setRadius(options: {x?: number, y?: number}): void {}
@@ -50,3 +43,17 @@ export class Ellipse extends Graphic implements CurveInterface {
5043
}
5144
````
5245

46+
Information about the constructor:
47+
48+
````ts
49+
interface EllipseConstructorInterface {
50+
game: Game,
51+
position: Position,
52+
radiusX: number,
53+
radiusY: number,
54+
styles?: GenericGraphicStylesInterface,
55+
toDisplay?: boolean,
56+
drawingOptions?: CurveDrawingOptionsInterface
57+
}
58+
````
59+

docs/graphics/index.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ This is the parent class of each shape that you can draw with Cazan. Don't hesit
1010
class Graphic {
1111
readonly id!: number
1212

13-
constructor(
14-
protected game: Game,
15-
protected position: Position,
16-
protected dimensions: Dimensions,
17-
protected toDisplay = true
18-
) {}
13+
constructor(options: GraphicConstructorInterface) {}
1914

2015
draw(): void {}
2116

2217
hide(): void {}
18+
19+
setupStylesForDrawing(): void {}
20+
21+
private setDefaultStyles(): void {}
22+
23+
setStyles(styles: GenericGraphicStylesInterface): void {}
24+
25+
getStyles(): GenericGraphicStylesInterface | undefined {}
2326

2427
getId(): number {}
2528

@@ -44,6 +47,18 @@ class Graphic {
4447
}
4548
````
4649

50+
By the way, there's ``GraphicContstructorInterface``.
51+
52+
````ts
53+
interface GraphicConstructorInterface {
54+
game: Game,
55+
position: Position,
56+
dimensions: Dimensions,
57+
styles?: GenericGraphicStylesInterface,
58+
toDisplay?: boolean
59+
}
60+
````
61+
4762
Some shapes can handle images on them. If they do, they implement ``ImageHandlingInterface``.
4863

4964
````ts

docs/graphics/line.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ We'll use the ``cazan.graphics`` namespace here.
66

77
There's how to create a line with Cazan.
88
````js
9-
let myLine = new graphics.Line(
10-
game,
11-
{x: 10, y: 10}, //(1)!
12-
{x: 50, y: 150} //(2)!
13-
)
9+
let myLine = new graphics.Line({
10+
game: game,
11+
firstPoint: {x: 10, y: 10}, //(1)!
12+
secondPoint: {x: 50, y: 150} //(2)!
13+
})
1414
````
1515

1616
1. Position of the first point.
@@ -21,12 +21,19 @@ let myLine = new graphics.Line(
2121
For other further information, see the page about ``Graphic``, the parent of ``Line``.
2222

2323
````ts
24-
export class Line extends Graphic {
25-
constructor(
26-
game: Game,
27-
firstPoint: Position,
28-
secondPoint: Position,
29-
toDisplay?: boolean
30-
) {}
24+
class Line extends Graphic {
25+
constructor(options: LineConstructorInterface) {}
3126
}
3227
````
28+
29+
Information about the constructor:
30+
31+
`````ts
32+
interface LineConstructorInterface {
33+
game: Game,
34+
firstPoint: Position,
35+
secondPoint: Position,
36+
styles?: GenericGraphicStylesInterface,
37+
toDisplay?: boolean
38+
}
39+
`````

docs/graphics/rectangle.md

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ We'll use the ``cazan.graphics`` namespace here.
66

77
Little example:
88
````js
9-
let myRect = new graphics.Rectangle(
10-
game,
11-
{x: 10, y: 10},
12-
{x: 50, y: 50}
13-
)
9+
let myRect = new graphics.Rectangle({
10+
game: game,
11+
position: {x: 10, y: 10},
12+
dimensions: {width: 50, height: 50},
13+
})
1414
````
1515

16-
You can add an image if you want and decide to not display it now.
17-
````js hl_lines="4-6 11"
18-
let myRect = new graphics.Rectangle(
19-
game,
20-
{x: 10, y: 10},
21-
{x: 50, y: 50},
22-
'img.png',
23-
false
24-
)
16+
You can add an image if you want and decide to not display the element right now.
17+
````js hl_lines="5-6 11"
18+
let myRect = new graphics.Rectangle({
19+
game: game,
20+
position: {x: 10, y: 10},
21+
dimensions: {width: 50, height: 50},
22+
srcImage: 'img.png',
23+
toDisplay: false
24+
})
2525

2626
// ...
2727

@@ -38,13 +38,20 @@ For other further information, see the page about ``Graphic`` and ``ImageHandlin
3838
class Rectangle extends Graphic implements ImageHandlingInterface {
3939
private image?: CanvasImageSource
4040

41-
constructor(
42-
game: Game,
43-
position: Position,
44-
dimensions: Dimensions,
45-
srcImage?: string,
46-
toDisplay?: boolean
47-
) {}
41+
constructor(options: RectangleConstructorInterface) {}
42+
}
43+
````
44+
45+
Information about the constructor:
46+
47+
````ts
48+
interface RectangleConstructorInterface {
49+
game: Game,
50+
position: Position,
51+
dimensions: Dimensions,
52+
styles?: GenericGraphicStylesInterface,
53+
srcImage?: string,
54+
toDisplay?: boolean
4855
}
4956
````
5057

0 commit comments

Comments
 (0)