canvasengine 1.3.0 → 2.0.0-beta.10
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.
- package/dist/index.d.ts +1137 -0
- package/dist/index.js +3222 -0
- package/dist/index.js.map +1 -0
- package/index.d.ts +4 -0
- package/package.json +43 -17
- package/src/components/Canvas.ts +134 -0
- package/src/components/Container.ts +46 -0
- package/src/components/DisplayObject.ts +458 -0
- package/src/components/Graphic.ts +147 -0
- package/src/components/NineSliceSprite.ts +46 -0
- package/src/components/ParticleEmitter.ts +39 -0
- package/src/components/Scene.ts +6 -0
- package/src/components/Sprite.ts +514 -0
- package/src/components/Text.ts +145 -0
- package/src/components/TilingSprite.ts +39 -0
- package/src/components/Video.ts +110 -0
- package/src/components/Viewport.ts +159 -0
- package/src/components/index.ts +12 -0
- package/src/components/types/DisplayObject.ts +70 -0
- package/src/components/types/MouseEvent.ts +3 -0
- package/src/components/types/Spritesheet.ts +389 -0
- package/src/components/types/index.ts +4 -0
- package/src/directives/Drag.ts +84 -0
- package/src/directives/KeyboardControls.ts +922 -0
- package/src/directives/Scheduler.ts +101 -0
- package/src/directives/Sound.ts +91 -0
- package/src/directives/Transition.ts +45 -0
- package/src/directives/ViewportCull.ts +40 -0
- package/src/directives/ViewportFollow.ts +26 -0
- package/src/directives/index.ts +7 -0
- package/src/engine/animation.ts +149 -0
- package/src/engine/bootstrap.ts +19 -0
- package/src/engine/directive.ts +23 -0
- package/src/engine/reactive.ts +480 -0
- package/src/engine/signal.ts +138 -0
- package/src/engine/trigger.ts +96 -0
- package/src/engine/utils.ts +211 -0
- package/src/hooks/addContext.ts +6 -0
- package/src/hooks/useProps.ts +155 -0
- package/src/hooks/useRef.ts +21 -0
- package/src/index.ts +15 -0
- package/src/utils/Ease.ts +33 -0
- package/src/utils/RadialGradient.ts +115 -0
- package/testing/index.ts +11 -0
- package/.gitattributes +0 -22
- package/.npmignore +0 -163
- package/canvasengine-1.3.0.all.min.js +0 -21
- package/canvasengine.js +0 -5802
- package/core/DB.js +0 -24
- package/core/ModelServer.js +0 -348
- package/core/Users.js +0 -190
- package/core/engine-common.js +0 -952
- package/doc/cocoonjs.md +0 -36
- package/doc/doc-lang.yml +0 -43
- package/doc/doc-router.yml +0 -14
- package/doc/doc-tuto.yml +0 -9
- package/doc/doc.yml +0 -39
- package/doc/element.md +0 -37
- package/doc/entity.md +0 -90
- package/doc/extend.md +0 -47
- package/doc/get_started.md +0 -19
- package/doc/images/entity.png +0 -0
- package/doc/multitouch.md +0 -58
- package/doc/nodejs.md +0 -142
- package/doc/scene.md +0 -44
- package/doc/text.md +0 -156
- package/examples/server/client.html +0 -31
- package/examples/server/server.js +0 -16
- package/examples/tiled_server/client.html +0 -52
- package/examples/tiled_server/images/tiles_spritesheet.png +0 -0
- package/examples/tiled_server/server/map.json +0 -50
- package/examples/tiled_server/server/map.tmx +0 -16
- package/examples/tiled_server/server/server.js +0 -16
- package/extends/Animation.js +0 -910
- package/extends/Effect.js +0 -252
- package/extends/Gleed2d.js +0 -252
- package/extends/Hit.js +0 -1509
- package/extends/Input.js +0 -699
- package/extends/Marshal.js +0 -716
- package/extends/Scrolling.js +0 -388
- package/extends/Soundmanager2.js +0 -5466
- package/extends/Spritesheet.js +0 -196
- package/extends/Text.js +0 -366
- package/extends/Tiled.js +0 -403
- package/extends/Window.js +0 -575
- package/extends/gamepad.js +0 -397
- package/extends/socket.io.min.js +0 -2
- package/extends/swf/soundmanager2.swf +0 -0
- package/extends/swf/soundmanager2_debug.swf +0 -0
- package/extends/swf/soundmanager2_flash9.swf +0 -0
- package/extends/swf/soundmanager2_flash9_debug.swf +0 -0
- package/extends/swf/soundmanager2_flash_xdomain.zip +0 -0
- package/extends/workers/transition.js +0 -43
- package/index.js +0 -46
- package/license.txt +0 -19
- package/readme.md +0 -483
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Texture } from "pixi.js";
|
|
2
|
+
import { h, mount } from "../engine/signal";
|
|
3
|
+
import { useDefineProps } from "../hooks/useProps";
|
|
4
|
+
import { Sprite } from "./Sprite";
|
|
5
|
+
import { effect, Signal, signal } from "@signe/reactive";
|
|
6
|
+
|
|
7
|
+
interface VideoProps {
|
|
8
|
+
src: string;
|
|
9
|
+
paused?: boolean;
|
|
10
|
+
loop?: boolean;
|
|
11
|
+
muted?: boolean;
|
|
12
|
+
loader?: {
|
|
13
|
+
onComplete?: (texture: Texture) => void;
|
|
14
|
+
onProgress?: (progress: number) => void;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function Video(props: VideoProps) {
|
|
19
|
+
const eventsMap = {
|
|
20
|
+
audioprocess: null,
|
|
21
|
+
canplay: null,
|
|
22
|
+
canplaythrough: null,
|
|
23
|
+
complete: null,
|
|
24
|
+
durationchange: null,
|
|
25
|
+
emptied: null,
|
|
26
|
+
ended: null,
|
|
27
|
+
loadeddata: null,
|
|
28
|
+
loadedmetadata: null,
|
|
29
|
+
pause: null,
|
|
30
|
+
play: null,
|
|
31
|
+
playing: null,
|
|
32
|
+
progress: null,
|
|
33
|
+
ratechange: null,
|
|
34
|
+
seeked: null,
|
|
35
|
+
seeking: null,
|
|
36
|
+
stalled: null,
|
|
37
|
+
suspend: null,
|
|
38
|
+
timeupdate: null,
|
|
39
|
+
volumechange: null,
|
|
40
|
+
waiting: null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const video: Signal<HTMLVideoElement | null> = signal(null)
|
|
44
|
+
const defineProps = useDefineProps(props)
|
|
45
|
+
const { play, loop, muted } = defineProps({
|
|
46
|
+
play: {
|
|
47
|
+
type: Boolean,
|
|
48
|
+
default: true
|
|
49
|
+
},
|
|
50
|
+
loop: {
|
|
51
|
+
type: Boolean,
|
|
52
|
+
default: false
|
|
53
|
+
},
|
|
54
|
+
muted: {
|
|
55
|
+
type: Boolean,
|
|
56
|
+
default: false
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
effect(() => {
|
|
61
|
+
const _video = video()
|
|
62
|
+
const state = play()
|
|
63
|
+
if (_video && state !== undefined) {
|
|
64
|
+
if (state) {
|
|
65
|
+
_video.play()
|
|
66
|
+
} else {
|
|
67
|
+
_video.pause()
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (_video && loop()) {
|
|
71
|
+
_video.loop = loop()
|
|
72
|
+
}
|
|
73
|
+
if (_video && muted()) {
|
|
74
|
+
_video.muted = muted()
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
mount(() => {
|
|
79
|
+
return () => {
|
|
80
|
+
for (let event in eventsMap) {
|
|
81
|
+
if (eventsMap[event]) {
|
|
82
|
+
video().removeEventListener(event, eventsMap[event])
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
return h(Sprite, {
|
|
89
|
+
...props,
|
|
90
|
+
image: props.src,
|
|
91
|
+
loader: {
|
|
92
|
+
onComplete: (texture) => {
|
|
93
|
+
const source = texture.source.resource
|
|
94
|
+
video.set(source)
|
|
95
|
+
if (props?.loader?.onComplete) {
|
|
96
|
+
props.loader.onComplete(texture)
|
|
97
|
+
}
|
|
98
|
+
for (let event in eventsMap) {
|
|
99
|
+
if (props[event]) {
|
|
100
|
+
const cb = (ev) => {
|
|
101
|
+
props[event](ev)
|
|
102
|
+
}
|
|
103
|
+
eventsMap[event] = cb
|
|
104
|
+
source.addEventListener(event, cb)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { Viewport as PixiViewport } from 'pixi-viewport';
|
|
2
|
+
import { Subscription } from 'rxjs';
|
|
3
|
+
import { createComponent, registerComponent } from '../engine/reactive';
|
|
4
|
+
import { DisplayObject } from './DisplayObject';
|
|
5
|
+
import { effect } from '@signe/reactive';
|
|
6
|
+
|
|
7
|
+
const EVENTS = [
|
|
8
|
+
'bounce-x-end',
|
|
9
|
+
'bounce-x-start',
|
|
10
|
+
'bounce-y-end',
|
|
11
|
+
'bounce-y-start',
|
|
12
|
+
'clicked',
|
|
13
|
+
'drag-end',
|
|
14
|
+
'drag-start',
|
|
15
|
+
'frame-end',
|
|
16
|
+
'mouse-edge-end',
|
|
17
|
+
'mouse-edge-start',
|
|
18
|
+
'moved',
|
|
19
|
+
'moved-end',
|
|
20
|
+
'pinch-end',
|
|
21
|
+
'pinch-start',
|
|
22
|
+
'snap-end',
|
|
23
|
+
'snap-start',
|
|
24
|
+
'snap-zoom-end',
|
|
25
|
+
'snap-zoom-start',
|
|
26
|
+
'wheel-scroll',
|
|
27
|
+
'zoomed',
|
|
28
|
+
'zoomed-end'
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
export class CanvasViewport extends DisplayObject(PixiViewport) {
|
|
32
|
+
private tickSubscription: Subscription
|
|
33
|
+
overrideProps = ['wheel']
|
|
34
|
+
|
|
35
|
+
constructor() {
|
|
36
|
+
const defaultOptions = {
|
|
37
|
+
noTicker: true,
|
|
38
|
+
events: {
|
|
39
|
+
domElement: {
|
|
40
|
+
addEventListener: () => {}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
super(defaultOptions)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
onInit(props) {
|
|
49
|
+
super.onInit(props)
|
|
50
|
+
for (let event of EVENTS) {
|
|
51
|
+
const camelCaseEvent = event.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
|
|
52
|
+
if (props[camelCaseEvent]) {
|
|
53
|
+
this.on(event, props[camelCaseEvent])
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
onMount(element) {
|
|
59
|
+
super.onMount(element)
|
|
60
|
+
const { tick, renderer, canvasSize } = element.props.context
|
|
61
|
+
let isDragging = false
|
|
62
|
+
|
|
63
|
+
effect(() => {
|
|
64
|
+
this.screenWidth = canvasSize().width
|
|
65
|
+
this.screenHeight = canvasSize().height
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
renderer.events.domElement.addEventListener(
|
|
69
|
+
'wheel',
|
|
70
|
+
this.input.wheelFunction
|
|
71
|
+
);
|
|
72
|
+
this.options.events = renderer.events
|
|
73
|
+
|
|
74
|
+
this.tickSubscription = tick.observable.subscribe(({ value }) => {
|
|
75
|
+
this.update(value.timestamp)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
element.props.context.viewport = this
|
|
79
|
+
this.updateViewportSettings(element.props)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
onUpdate(props) {
|
|
83
|
+
super.onUpdate(props)
|
|
84
|
+
this.updateViewportSettings(props)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private updateViewportSettings(props) {
|
|
88
|
+
if (props.screenWidth !== undefined) {
|
|
89
|
+
this.screenWidth = props.screenWidth
|
|
90
|
+
}
|
|
91
|
+
if (props.screenHeight !== undefined) {
|
|
92
|
+
this.screenHeight = props.screenHeight
|
|
93
|
+
}
|
|
94
|
+
if (props.worldWidth !== undefined) {
|
|
95
|
+
this.worldWidth = props.worldWidth
|
|
96
|
+
}
|
|
97
|
+
if (props.worldHeight !== undefined) {
|
|
98
|
+
this.worldHeight = props.worldHeight
|
|
99
|
+
}
|
|
100
|
+
// if (props.drag) {
|
|
101
|
+
// if (props.drag === true) {
|
|
102
|
+
|
|
103
|
+
// } else {
|
|
104
|
+
// this.drag(props.drag)
|
|
105
|
+
// }
|
|
106
|
+
// }
|
|
107
|
+
if (props.clamp) {
|
|
108
|
+
this.clamp(props.clamp)
|
|
109
|
+
}
|
|
110
|
+
if (props.wheel) {
|
|
111
|
+
if (props.wheel === true) {
|
|
112
|
+
this.wheel()
|
|
113
|
+
} else {
|
|
114
|
+
this.wheel(props.wheel)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (props.decelerate) {
|
|
118
|
+
if (props.decelerate === true) {
|
|
119
|
+
this.decelerate()
|
|
120
|
+
} else {
|
|
121
|
+
this.decelerate(props.decelerate)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (props.pinch) {
|
|
125
|
+
if (props.pinch === true) {
|
|
126
|
+
this.pinch()
|
|
127
|
+
} else {
|
|
128
|
+
this.pinch(props.pinch)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
onDestroy(): void {
|
|
134
|
+
super.onDestroy()
|
|
135
|
+
this.tickSubscription.unsubscribe()
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface CanvasViewport extends PixiViewport { }
|
|
140
|
+
|
|
141
|
+
registerComponent('Viewport', CanvasViewport)
|
|
142
|
+
|
|
143
|
+
export interface ViewportProps {
|
|
144
|
+
screenWidth?: number;
|
|
145
|
+
screenHeight?: number;
|
|
146
|
+
worldWidth?: number;
|
|
147
|
+
worldHeight?: number;
|
|
148
|
+
clamp?: boolean | {
|
|
149
|
+
left?: number;
|
|
150
|
+
right?: number;
|
|
151
|
+
top?: number;
|
|
152
|
+
bottom?: number;
|
|
153
|
+
};
|
|
154
|
+
[key: string]: any;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function Viewport(props: ViewportProps) {
|
|
158
|
+
return createComponent('Viewport', props);
|
|
159
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { Canvas } from './Canvas'
|
|
2
|
+
export { Container } from './Container'
|
|
3
|
+
export { Graphics, Rect, Circle, Ellipse, Triangle, Svg as svg } from './Graphic'
|
|
4
|
+
export { Scene } from './Scene'
|
|
5
|
+
export { ParticlesEmitter } from './ParticleEmitter'
|
|
6
|
+
export { Sprite } from './Sprite'
|
|
7
|
+
export { Video } from './Video'
|
|
8
|
+
export { Text } from './Text'
|
|
9
|
+
export { TilingSprite } from './TilingSprite'
|
|
10
|
+
export { Viewport } from './Viewport'
|
|
11
|
+
export { NineSliceSprite } from './NineSliceSprite'
|
|
12
|
+
export { type ComponentInstance } from './DisplayObject'
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as PIXI from "pixi.js";
|
|
2
|
+
import { SignalOrPrimitive } from ".";
|
|
3
|
+
|
|
4
|
+
export type FlexDirection = 'row' | 'column' | 'row-reverse' | 'column-reverse';
|
|
5
|
+
export type JustifyContent = 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around';
|
|
6
|
+
export type AlignContent = 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around';
|
|
7
|
+
export type Size = number | `${number}%`
|
|
8
|
+
export type EdgeSize = SignalOrPrimitive<Size | [Size, Size] | [Size, Size, Size, Size]>
|
|
9
|
+
|
|
10
|
+
export interface DisplayObjectProps {
|
|
11
|
+
attach?: any;
|
|
12
|
+
ref?: string;
|
|
13
|
+
x?: SignalOrPrimitive<number>;
|
|
14
|
+
y?: SignalOrPrimitive<number>;
|
|
15
|
+
width?: SignalOrPrimitive<Size>;
|
|
16
|
+
height?: SignalOrPrimitive<Size>;
|
|
17
|
+
children?: any[];
|
|
18
|
+
flexDirection?: FlexDirection;
|
|
19
|
+
justifyContent?: JustifyContent;
|
|
20
|
+
alpha?: SignalOrPrimitive<number>;
|
|
21
|
+
margin?: EdgeSize;
|
|
22
|
+
padding?: EdgeSize;
|
|
23
|
+
border?: EdgeSize;
|
|
24
|
+
absolute?: SignalOrPrimitive<boolean>;
|
|
25
|
+
scale?: SignalOrPrimitive<{ x: number, y: number } | number>;
|
|
26
|
+
anchor?: SignalOrPrimitive<{ x: number, y: number }>;
|
|
27
|
+
skew?: SignalOrPrimitive<{ x: number, y: number }>;
|
|
28
|
+
tint?: SignalOrPrimitive<number>;
|
|
29
|
+
rotation?: SignalOrPrimitive<number>;
|
|
30
|
+
angle?: SignalOrPrimitive<number>;
|
|
31
|
+
zIndex?: SignalOrPrimitive<number>;
|
|
32
|
+
roundPixels?: SignalOrPrimitive<boolean>;
|
|
33
|
+
cursor?: SignalOrPrimitive<string>;
|
|
34
|
+
visible?: SignalOrPrimitive<boolean>;
|
|
35
|
+
pivot?: SignalOrPrimitive<{ x: number, y: number }>;
|
|
36
|
+
filters?: any[];
|
|
37
|
+
blendMode?: SignalOrPrimitive<PIXI.BLEND_MODES>;
|
|
38
|
+
blur?: SignalOrPrimitive<number>;
|
|
39
|
+
|
|
40
|
+
click?: PIXI.FederatedEventHandler;
|
|
41
|
+
mousedown?: PIXI.FederatedEventHandler;
|
|
42
|
+
mouseenter?: PIXI.FederatedEventHandler;
|
|
43
|
+
mouseleave?: PIXI.FederatedEventHandler;
|
|
44
|
+
mousemove?: PIXI.FederatedEventHandler;
|
|
45
|
+
mouseout?: PIXI.FederatedEventHandler;
|
|
46
|
+
mouseover?: PIXI.FederatedEventHandler;
|
|
47
|
+
mouseup?: PIXI.FederatedEventHandler;
|
|
48
|
+
mouseupoutside?: PIXI.FederatedEventHandler;
|
|
49
|
+
pointercancel?: PIXI.FederatedEventHandler;
|
|
50
|
+
pointerdown?: PIXI.FederatedEventHandler;
|
|
51
|
+
pointerenter?: PIXI.FederatedEventHandler;
|
|
52
|
+
pointerleave?: PIXI.FederatedEventHandler;
|
|
53
|
+
pointermove?: PIXI.FederatedEventHandler;
|
|
54
|
+
pointerout?: PIXI.FederatedEventHandler;
|
|
55
|
+
pointerover?: PIXI.FederatedEventHandler;
|
|
56
|
+
pointertap?: PIXI.FederatedEventHandler;
|
|
57
|
+
pointerup?: PIXI.FederatedEventHandler;
|
|
58
|
+
pointerupoutside?: PIXI.FederatedEventHandler;
|
|
59
|
+
rightclick?: PIXI.FederatedEventHandler;
|
|
60
|
+
rightdown?: PIXI.FederatedEventHandler;
|
|
61
|
+
rightup?: PIXI.FederatedEventHandler;
|
|
62
|
+
rightupoutside?: PIXI.FederatedEventHandler;
|
|
63
|
+
tap?: PIXI.FederatedEventHandler;
|
|
64
|
+
touchcancel?: PIXI.FederatedEventHandler;
|
|
65
|
+
touchend?: PIXI.FederatedEventHandler;
|
|
66
|
+
touchendoutside?: PIXI.FederatedEventHandler;
|
|
67
|
+
touchmove?: PIXI.FederatedEventHandler;
|
|
68
|
+
touchstart?: PIXI.FederatedEventHandler;
|
|
69
|
+
wheel?: PIXI.FederatedEventHandler<PIXI.FederatedWheelEvent>;
|
|
70
|
+
}
|