pixi-fusion 2.0.4 → 2.2.1
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/src/assets-manager/AssetsManager.js +1 -1
- package/dist/src/assets-manager/index.d.ts +3 -3
- package/dist/src/assets-manager/index.js +3 -3
- package/dist/src/assets-manager/useAssetManager.d.ts +1 -1
- package/dist/src/assets-manager/useAssetManager.js +1 -1
- package/dist/src/camera/Camera.js +5 -4
- package/dist/src/camera/index.d.ts +2 -2
- package/dist/src/camera/index.js +2 -2
- package/dist/src/game-context/Game.context.d.ts +2 -1
- package/dist/src/game-context/Game.context.js +7 -3
- package/dist/src/game-context/index.d.ts +1 -1
- package/dist/src/game-context/index.js +1 -1
- package/dist/src/game-objects/index.d.ts +2 -2
- package/dist/src/game-objects/index.js +2 -2
- package/dist/src/game-objects/usePhysicalObject.d.ts +1 -1
- package/dist/src/game-objects/usePhysicalObject.js +1 -1
- package/dist/src/game-objects/usePhysicalObjectFromConfig.d.ts +2 -2
- package/dist/src/game-objects/usePhysicalObjectFromConfig.js +1 -1
- package/dist/src/game-objects/useWalls.js +1 -1
- package/dist/src/hooks/index.d.ts +12 -12
- package/dist/src/hooks/index.js +12 -12
- package/dist/src/hooks/useAnimatedSprite.js +2 -2
- package/dist/src/hooks/useCamera.d.ts +1 -1
- package/dist/src/hooks/useCamera.js +1 -1
- package/dist/src/hooks/useCollisionDetection.js +1 -1
- package/dist/src/hooks/useGame.d.ts +1 -1
- package/dist/src/hooks/useGame.js +1 -1
- package/dist/src/hooks/useLayerContext.d.ts +1 -1
- package/dist/src/hooks/useLayerContext.js +1 -1
- package/dist/src/hooks/useObject.js +1 -1
- package/dist/src/hooks/useSprite.js +2 -2
- package/dist/src/hooks/useStage.d.ts +1 -1
- package/dist/src/hooks/useStage.js +1 -1
- package/dist/src/hooks/useTexture.js +1 -1
- package/dist/src/hooks/useTickerCallback.js +1 -1
- package/dist/src/hooks/useTilingSprite.js +2 -2
- package/dist/src/hooks/useWorld.d.ts +1 -1
- package/dist/src/hooks/useWorld.js +1 -1
- package/dist/src/index.d.ts +9 -10
- package/dist/src/index.js +9 -10
- package/dist/src/layer/Layer.js +2 -2
- package/dist/src/layer/index.d.ts +1 -1
- package/dist/src/layer/index.js +1 -1
- package/dist/src/physics/MatterPhysics.context.d.ts +1 -1
- package/dist/src/physics/index.d.ts +4 -4
- package/dist/src/physics/index.js +4 -4
- package/dist/src/physics/useCollisionEventHandler.js +1 -1
- package/dist/src/physics/usePhysicsEngineEventHandler.js +1 -1
- package/dist/src/physics/usePhysicsTickerCallback.js +1 -1
- package/dist/src/stage/Stage.js +3 -3
- package/dist/src/stage/index.d.ts +1 -1
- package/dist/src/stage/index.js +1 -1
- package/dist/src/world/World.js +29 -33
- package/dist/src/world/index.d.ts +2 -2
- package/dist/src/world/index.js +2 -2
- package/package.json +27 -14
- package/src/assets-manager/AssetsManager.tsx +1 -1
- package/src/assets-manager/index.ts +3 -3
- package/src/assets-manager/useAssetManager.ts +1 -1
- package/src/camera/Camera.tsx +6 -5
- package/src/camera/index.ts +2 -2
- package/src/game-context/Game.context.tsx +8 -3
- package/src/game-context/index.ts +1 -1
- package/src/game-objects/index.ts +2 -2
- package/src/game-objects/usePhysicalObject.ts +2 -2
- package/src/game-objects/usePhysicalObjectFromConfig.ts +3 -3
- package/src/game-objects/useWalls.ts +1 -1
- package/src/hooks/index.ts +12 -12
- package/src/hooks/useAnimatedSprite.ts +2 -2
- package/src/hooks/useCamera.ts +1 -1
- package/src/hooks/useCollisionDetection.ts +1 -1
- package/src/hooks/useGame.ts +1 -1
- package/src/hooks/useLayerContext.ts +1 -1
- package/src/hooks/useObject.ts +1 -1
- package/src/hooks/useSprite.ts +2 -2
- package/src/hooks/useStage.ts +1 -1
- package/src/hooks/useTexture.ts +1 -1
- package/src/hooks/useTickerCallback.ts +1 -1
- package/src/hooks/useTilingSprite.ts +2 -2
- package/src/hooks/useWorld.ts +1 -1
- package/src/index.ts +9 -10
- package/src/layer/Layer.tsx +2 -2
- package/src/layer/index.ts +1 -1
- package/src/physics/MatterPhysics.context.tsx +1 -1
- package/src/physics/index.ts +4 -4
- package/src/physics/useCollisionEventHandler.ts +1 -1
- package/src/physics/usePhysicsEngineEventHandler.ts +1 -1
- package/src/physics/usePhysicsTickerCallback.ts +1 -1
- package/src/stage/Stage.tsx +3 -3
- package/src/stage/index.ts +1 -1
- package/src/world/World.tsx +35 -36
- package/src/world/index.ts +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
|
-
import { AssetsManagerContext } from "./AssetsManager.context";
|
|
3
2
|
import { Assets } from "pixi.js";
|
|
3
|
+
import { AssetsManagerContext } from "./AssetsManager.context.js";
|
|
4
4
|
export const AssetsManager = ({ children }) => {
|
|
5
5
|
const [isFetching, setIsFetching] = useState(false);
|
|
6
6
|
const [isFetched, setIsFetched] = useState(false);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./AssetsManager";
|
|
2
|
-
export * from "./AssetsManager.context";
|
|
3
|
-
export * from "./useAssetManager";
|
|
1
|
+
export * from "./AssetsManager.js";
|
|
2
|
+
export * from "./AssetsManager.context.js";
|
|
3
|
+
export * from "./useAssetManager.js";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./AssetsManager";
|
|
2
|
-
export * from "./AssetsManager.context";
|
|
3
|
-
export * from "./useAssetManager";
|
|
1
|
+
export * from "./AssetsManager.js";
|
|
2
|
+
export * from "./AssetsManager.context.js";
|
|
3
|
+
export * from "./useAssetManager.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useAssetManager: () => import("./AssetsManager.context").AssetsManagerContextValue;
|
|
1
|
+
export declare const useAssetManager: () => import("./AssetsManager.context.js").AssetsManagerContextValue;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
2
|
import { Viewport as ViewportContainer } from "pixi-viewport";
|
|
3
|
-
import { Layer } from "../layer";
|
|
4
|
-
import { useStage
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import { Layer } from "../layer/Layer.js";
|
|
4
|
+
import { useStage } from "../hooks/useStage.js";
|
|
5
|
+
import { useWorld } from "../hooks/useWorld.js";
|
|
6
|
+
import { LayerContext } from "../layer/Layer.context.js";
|
|
7
|
+
import { CameraContext } from "./Camera.context.js";
|
|
7
8
|
export const Camera = ({ children, clampZoom }) => {
|
|
8
9
|
const [isReady, setIsReady] = useState(false);
|
|
9
10
|
const [followContainer, setFollowContainer] = useState(null);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./Camera";
|
|
2
|
-
export * from "./Camera.context";
|
|
1
|
+
export * from "./Camera.js";
|
|
2
|
+
export * from "./Camera.context.js";
|
package/dist/src/camera/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./Camera";
|
|
2
|
-
export * from "./Camera.context";
|
|
1
|
+
export * from "./Camera.js";
|
|
2
|
+
export * from "./Camera.context.js";
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from "react";
|
|
2
|
-
import { GameStatus, GameStatusChangeEvent } from "../types";
|
|
2
|
+
import { GameStatus, GameStatusChangeEvent } from "../types.js";
|
|
3
3
|
export type GameContextValue = {
|
|
4
4
|
readonly reset: () => void;
|
|
5
5
|
readonly start: () => void;
|
|
6
6
|
readonly pause: () => void;
|
|
7
7
|
readonly stop: () => void;
|
|
8
8
|
readonly timeout: number;
|
|
9
|
+
readonly gameId: number;
|
|
9
10
|
readonly status: GameStatus;
|
|
10
11
|
readonly startTime: number | null;
|
|
11
12
|
readonly pauseTime: number;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React, { createContext, useCallback, useMemo, useRef, useState } from "react";
|
|
2
|
-
import { GameStatus } from "../types";
|
|
2
|
+
import { GameStatus } from "../types.js";
|
|
3
3
|
export const GameContext = createContext({
|
|
4
4
|
reset: () => { },
|
|
5
5
|
pause: () => { },
|
|
6
6
|
start: () => { },
|
|
7
7
|
stop: () => { },
|
|
8
8
|
timeout: 0,
|
|
9
|
+
gameId: 0,
|
|
9
10
|
status: GameStatus.READY,
|
|
10
11
|
startTime: null,
|
|
11
12
|
pauseTime: 0,
|
|
@@ -14,6 +15,7 @@ export const GameContext = createContext({
|
|
|
14
15
|
export const GameContextProvider = ({ children, timeout: inputTimeout = 0, events }) => {
|
|
15
16
|
const timerRef = useRef(null);
|
|
16
17
|
const timeout = Math.max(0, inputTimeout);
|
|
18
|
+
const [gameId, setGemaId] = useState(0);
|
|
17
19
|
const [status, setStatus] = useState(GameStatus.READY);
|
|
18
20
|
const [startTime, setStartTime] = useState(null);
|
|
19
21
|
const [endTime, setEndTime] = useState(null);
|
|
@@ -66,6 +68,7 @@ export const GameContextProvider = ({ children, timeout: inputTimeout = 0, event
|
|
|
66
68
|
setEndTime(newEndTime);
|
|
67
69
|
setPauseTime(newPauseTime);
|
|
68
70
|
setPausedAtTime(newPausedAtTime);
|
|
71
|
+
setGemaId((current) => current++);
|
|
69
72
|
if (timerRef.current) {
|
|
70
73
|
clearTimeout(timerRef.current);
|
|
71
74
|
}
|
|
@@ -118,7 +121,8 @@ export const GameContextProvider = ({ children, timeout: inputTimeout = 0, event
|
|
|
118
121
|
stop,
|
|
119
122
|
start,
|
|
120
123
|
reset,
|
|
121
|
-
pause
|
|
122
|
-
|
|
124
|
+
pause,
|
|
125
|
+
gameId
|
|
126
|
+
}), [timeout, status, startTime, endTime, pauseTime, pause, reset, start, stop, gameId]);
|
|
123
127
|
return React.createElement(GameContext.Provider, { value: contextValue }, children);
|
|
124
128
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./Game.context";
|
|
1
|
+
export * from "./Game.context.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./Game.context";
|
|
1
|
+
export * from "./Game.context.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./usePhysicalObject";
|
|
2
|
-
export * from "./useWalls";
|
|
1
|
+
export * from "./usePhysicalObject.js";
|
|
2
|
+
export * from "./useWalls.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./usePhysicalObject";
|
|
2
|
-
export * from "./useWalls";
|
|
1
|
+
export * from "./usePhysicalObject.js";
|
|
2
|
+
export * from "./useWalls.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useContext, useEffect } from "react";
|
|
2
|
-
import { MatterPhysicsContext } from "../physics";
|
|
2
|
+
import { MatterPhysicsContext } from "../physics/MatterPhysics.context.js";
|
|
3
3
|
export const usePhysicalObject = ({ physicalObject }) => {
|
|
4
4
|
const { addBody, removeBody } = useContext(MatterPhysicsContext);
|
|
5
5
|
useEffect(() => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Body } from "matter-js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { Nullable } from "../types.js";
|
|
3
|
+
import { GameObjectPhysicalObjectConfig } from "./GameObjectPhysicalObjectConfig.js";
|
|
4
4
|
export declare const usePhysicalObjectFromConfig: <PhysicalObjectType extends Nullable<Body> = Body>({ position, ...physicalObjectConfig }: GameObjectPhysicalObjectConfig) => {
|
|
5
5
|
physicalObject: PhysicalObjectType;
|
|
6
6
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Body } from "matter-js";
|
|
2
2
|
import { useMemo } from "react";
|
|
3
|
-
import { usePhysicalObject } from "./usePhysicalObject";
|
|
3
|
+
import { usePhysicalObject } from "./usePhysicalObject.js";
|
|
4
4
|
export const usePhysicalObjectFromConfig = ({ position = { x: 0, y: 0 }, ...physicalObjectConfig }) => {
|
|
5
5
|
const physicalObject = useMemo(() => {
|
|
6
6
|
if (physicalObjectConfig) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useContext, useEffect, useMemo } from "react";
|
|
2
2
|
import { Bodies, Composite } from "matter-js";
|
|
3
|
-
import { MatterPhysicsContext } from "../physics/MatterPhysics.context";
|
|
3
|
+
import { MatterPhysicsContext } from "../physics/MatterPhysics.context.js";
|
|
4
4
|
const DEFAULT_WALL_CONFIG = {
|
|
5
5
|
thikness: 10
|
|
6
6
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export * from "./useGlobalEventHandler";
|
|
2
|
-
export * from "./useStage";
|
|
3
|
-
export * from "./useTickerCallback";
|
|
4
|
-
export * from "./useWorld";
|
|
5
|
-
export * from "./useLayerContext";
|
|
6
|
-
export * from "./useSprite";
|
|
7
|
-
export * from "./useAnimatedSprite";
|
|
8
|
-
export * from "./useTexture";
|
|
9
|
-
export * from "./useGame";
|
|
10
|
-
export * from "./useTilingSprite";
|
|
11
|
-
export * from "./useCamera";
|
|
12
|
-
export * from "./useCollisionDetection";
|
|
1
|
+
export * from "./useGlobalEventHandler.js";
|
|
2
|
+
export * from "./useStage.js";
|
|
3
|
+
export * from "./useTickerCallback.js";
|
|
4
|
+
export * from "./useWorld.js";
|
|
5
|
+
export * from "./useLayerContext.js";
|
|
6
|
+
export * from "./useSprite.js";
|
|
7
|
+
export * from "./useAnimatedSprite.js";
|
|
8
|
+
export * from "./useTexture.js";
|
|
9
|
+
export * from "./useGame.js";
|
|
10
|
+
export * from "./useTilingSprite.js";
|
|
11
|
+
export * from "./useCamera.js";
|
|
12
|
+
export * from "./useCollisionDetection.js";
|
package/dist/src/hooks/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export * from "./useGlobalEventHandler";
|
|
2
|
-
export * from "./useStage";
|
|
3
|
-
export * from "./useTickerCallback";
|
|
4
|
-
export * from "./useWorld";
|
|
5
|
-
export * from "./useLayerContext";
|
|
6
|
-
export * from "./useSprite";
|
|
7
|
-
export * from "./useAnimatedSprite";
|
|
8
|
-
export * from "./useTexture";
|
|
9
|
-
export * from "./useGame";
|
|
10
|
-
export * from "./useTilingSprite";
|
|
11
|
-
export * from "./useCamera";
|
|
12
|
-
export * from "./useCollisionDetection";
|
|
1
|
+
export * from "./useGlobalEventHandler.js";
|
|
2
|
+
export * from "./useStage.js";
|
|
3
|
+
export * from "./useTickerCallback.js";
|
|
4
|
+
export * from "./useWorld.js";
|
|
5
|
+
export * from "./useLayerContext.js";
|
|
6
|
+
export * from "./useSprite.js";
|
|
7
|
+
export * from "./useAnimatedSprite.js";
|
|
8
|
+
export * from "./useTexture.js";
|
|
9
|
+
export * from "./useGame.js";
|
|
10
|
+
export * from "./useTilingSprite.js";
|
|
11
|
+
export * from "./useCamera.js";
|
|
12
|
+
export * from "./useCollisionDetection.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useMemo } from "react";
|
|
2
2
|
import { AnimatedSprite, Spritesheet } from "pixi.js";
|
|
3
|
-
import { useTextures } from "./useTexture";
|
|
4
|
-
import { useObject } from "./useObject";
|
|
3
|
+
import { useTextures } from "./useTexture.js";
|
|
4
|
+
import { useObject } from "./useObject.js";
|
|
5
5
|
export const useAnimatedSprite = ({ texture, spritesheet: spritesheetJSON, animation, animationSpeed = 1, isPlaying, ...options }) => {
|
|
6
6
|
const textureKeys = useMemo(() => {
|
|
7
7
|
return [...(texture ? [texture] : [])];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useCamera: () => import("
|
|
1
|
+
export declare const useCamera: () => import("../index.js").CameraContextValue;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useTickerCallback } from "./useTickerCallback";
|
|
2
1
|
import { useCallback } from "react";
|
|
2
|
+
import { useTickerCallback } from "./useTickerCallback.js";
|
|
3
3
|
export const useCollisionDetection = ({ objectA, objectB, onCollide, isEnabled }) => {
|
|
4
4
|
const testForAABB = useCallback(() => {
|
|
5
5
|
if (!objectA || !objectB) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useGame: () => import("
|
|
1
|
+
export declare const useGame: () => import("../index.js").GameContextValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useLayerContext: () => import("../layer/Layer.context").LayerContextValue;
|
|
1
|
+
export declare const useLayerContext: () => import("../layer/Layer.context.js").LayerContextValue;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useLayerContext } from "./useLayerContext";
|
|
2
1
|
import { useEffect } from "react";
|
|
2
|
+
import { useLayerContext } from "./useLayerContext.js";
|
|
3
3
|
export const useObject = ({ object, anchor, position, skew, scale, width, angle, alpha, visible = true }) => {
|
|
4
4
|
const { addObject, removeObject } = useLayerContext();
|
|
5
5
|
useEffect(() => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
2
|
import { Sprite } from "pixi.js";
|
|
3
|
-
import { useTextures } from "./useTexture";
|
|
4
|
-
import { useObject } from "./useObject";
|
|
3
|
+
import { useTextures } from "./useTexture.js";
|
|
4
|
+
import { useObject } from "./useObject.js";
|
|
5
5
|
export const useSprite = ({ texture = "", ...options }) => {
|
|
6
6
|
const textureKeys = useMemo(() => {
|
|
7
7
|
return [...(texture ? [texture] : [])];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useStage: () => import("../stage/Stage.context").StageContextValue;
|
|
1
|
+
export declare const useStage: () => import("../stage/Stage.context.js").StageContextValue;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
|
-
import { useAssetManager } from "../assets-manager";
|
|
2
|
+
import { useAssetManager } from "../assets-manager/useAssetManager.js";
|
|
3
3
|
export const useTextures = ({ keys = [] }) => {
|
|
4
4
|
const { getAsset, isFetched, isFetching, isError } = useAssetManager();
|
|
5
5
|
const textures = useMemo(() => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useMemo } from "react";
|
|
2
2
|
import { TilingSprite } from "pixi.js";
|
|
3
|
-
import { useTextures } from "./useTexture";
|
|
4
|
-
import { useObject } from "./useObject";
|
|
3
|
+
import { useTextures } from "./useTexture.js";
|
|
4
|
+
import { useObject } from "./useObject.js";
|
|
5
5
|
export const useTilingSprite = ({ texture = "", tilePosition, ...options }) => {
|
|
6
6
|
const textureKeys = useMemo(() => {
|
|
7
7
|
return [...(texture ? [texture] : [])];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useWorld: () => import("
|
|
1
|
+
export declare const useWorld: () => import("../index.js").WorldContextValue;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
export * from "./game-context";
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./
|
|
8
|
-
export * from "./
|
|
9
|
-
export * from "./
|
|
10
|
-
export * from "./hooks";
|
|
1
|
+
export * from "./game-context/index.js";
|
|
2
|
+
export * from "./world/index.js";
|
|
3
|
+
export * from "./camera/index.js";
|
|
4
|
+
export * from "./layer/index.js";
|
|
5
|
+
export * from "./assets-manager/index.js";
|
|
6
|
+
export * from "./game-objects/index.js";
|
|
7
|
+
export * from "./physics/index.js";
|
|
8
|
+
export * from "./types.js";
|
|
9
|
+
export * from "./hooks/index.js";
|
package/dist/src/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
export * from "./game-context";
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./
|
|
8
|
-
export * from "./
|
|
9
|
-
export * from "./
|
|
10
|
-
export * from "./hooks";
|
|
1
|
+
export * from "./game-context/index.js";
|
|
2
|
+
export * from "./world/index.js";
|
|
3
|
+
export * from "./camera/index.js";
|
|
4
|
+
export * from "./layer/index.js";
|
|
5
|
+
export * from "./assets-manager/index.js";
|
|
6
|
+
export * from "./game-objects/index.js";
|
|
7
|
+
export * from "./physics/index.js";
|
|
8
|
+
export * from "./types.js";
|
|
9
|
+
export * from "./hooks/index.js";
|
package/dist/src/layer/Layer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useCallback, useContext, useEffect, useMemo } from "react";
|
|
2
2
|
import { Container } from "pixi.js";
|
|
3
|
-
import { StageContext } from "../stage/Stage.context";
|
|
4
|
-
import { LayerContext } from "./Layer.context";
|
|
3
|
+
import { StageContext } from "../stage/Stage.context.js";
|
|
4
|
+
import { LayerContext } from "./Layer.context.js";
|
|
5
5
|
export const Layer = ({ options, children }) => {
|
|
6
6
|
const { addObject: addObjectIntoStage, removeObject: removeObjectFromStaeg } = useContext(StageContext);
|
|
7
7
|
const { addObject: addObjectIntoParent, removeObject: removeObjectFromParent } = useContext(LayerContext);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./Layer";
|
|
1
|
+
export * from "./Layer.js";
|
package/dist/src/layer/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./Layer";
|
|
1
|
+
export * from "./Layer.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from "react";
|
|
2
|
-
import { MatterPhysicsConfig, MatterPhysics } from "./types";
|
|
2
|
+
import { MatterPhysicsConfig, MatterPhysics } from "./types.js";
|
|
3
3
|
export type MatterPhysicsContextProviderOptions = {
|
|
4
4
|
isRunning?: boolean;
|
|
5
5
|
config: MatterPhysicsConfig;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./MatterPhysics.context";
|
|
2
|
-
export * from "./useCollisionEventHandler";
|
|
3
|
-
export * from "./usePhysicsTickerCallback";
|
|
4
|
-
export * from "./usePhysicsEngineEventHandler";
|
|
1
|
+
export * from "./MatterPhysics.context.js";
|
|
2
|
+
export * from "./useCollisionEventHandler.js";
|
|
3
|
+
export * from "./usePhysicsTickerCallback.js";
|
|
4
|
+
export * from "./usePhysicsEngineEventHandler.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./MatterPhysics.context";
|
|
2
|
-
export * from "./useCollisionEventHandler";
|
|
3
|
-
export * from "./usePhysicsTickerCallback";
|
|
4
|
-
export * from "./usePhysicsEngineEventHandler";
|
|
1
|
+
export * from "./MatterPhysics.context.js";
|
|
2
|
+
export * from "./useCollisionEventHandler.js";
|
|
3
|
+
export * from "./usePhysicsTickerCallback.js";
|
|
4
|
+
export * from "./usePhysicsEngineEventHandler.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useContext } from "react";
|
|
2
2
|
import { Events } from "matter-js";
|
|
3
|
-
import { MatterPhysicsContext } from "./MatterPhysics.context";
|
|
3
|
+
import { MatterPhysicsContext } from "./MatterPhysics.context.js";
|
|
4
4
|
export const useCollisionEventHandler = ({ isEnabled = true, event, callback }) => {
|
|
5
5
|
const { engine } = useContext(MatterPhysicsContext);
|
|
6
6
|
useEffect(() => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useContext } from "react";
|
|
2
2
|
import { Events } from "matter-js";
|
|
3
|
-
import { MatterPhysicsContext } from "./MatterPhysics.context";
|
|
3
|
+
import { MatterPhysicsContext } from "./MatterPhysics.context.js";
|
|
4
4
|
export const usePhysicsEngineEventHandler = ({ isEnabled = true, event, callback }) => {
|
|
5
5
|
const { engine } = useContext(MatterPhysicsContext);
|
|
6
6
|
useEffect(() => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useContext } from "react";
|
|
2
2
|
import { Events } from "matter-js";
|
|
3
|
-
import { MatterPhysicsContext } from "./MatterPhysics.context";
|
|
3
|
+
import { MatterPhysicsContext } from "./MatterPhysics.context.js";
|
|
4
4
|
export const usePhysicsTickerCallback = ({ isEnabled = true, callback }) => {
|
|
5
5
|
const { runner } = useContext(MatterPhysicsContext);
|
|
6
6
|
useEffect(() => {
|
package/dist/src/stage/Stage.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { useWorld } from "../hooks/useWorld.js";
|
|
3
|
+
import { Layer } from "../layer/Layer.js";
|
|
4
|
+
import { StageContext } from "./Stage.context.js";
|
|
5
5
|
export const Stage = ({ children }) => {
|
|
6
6
|
const { application } = useWorld();
|
|
7
7
|
const [things, setThings] = useState([]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./Stage";
|
|
1
|
+
export * from "./Stage.js";
|
package/dist/src/stage/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./Stage";
|
|
1
|
+
export * from "./Stage.js";
|
package/dist/src/world/World.js
CHANGED
|
@@ -1,21 +1,36 @@
|
|
|
1
|
-
import React, { createRef, useEffect, useMemo, useState } from "react";
|
|
1
|
+
import React, { createRef, useCallback, useEffect, useLayoutEffect, useMemo, useState } from "react";
|
|
2
2
|
import { Application } from "pixi.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { Stage } from "../stage/Stage.js";
|
|
4
|
+
import { AssetsManager } from "../assets-manager/AssetsManager.js";
|
|
5
|
+
import { WorldContext } from "./World.context.js";
|
|
6
6
|
export const World = ({ children, eventMode, size }) => {
|
|
7
7
|
const canvasRef = createRef();
|
|
8
8
|
const [applicationRef, setApplicationRef] = useState(null);
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
9
|
+
const [canvasSize, setCanvasSize] = useState(null);
|
|
10
|
+
const onCanvasRef = useCallback((ref) => {
|
|
11
|
+
const application = new Application();
|
|
12
|
+
application.init({ eventMode }).then(() => {
|
|
13
|
+
canvasRef.current = ref;
|
|
14
|
+
application.resizeTo = canvasRef.current;
|
|
15
|
+
application.resize();
|
|
16
|
+
setApplicationRef(application);
|
|
17
|
+
});
|
|
18
|
+
}, [canvasRef, eventMode]);
|
|
19
|
+
useLayoutEffect(() => {
|
|
13
20
|
if (canvasRef?.current) {
|
|
14
21
|
const { width, height } = canvasRef.current.getBoundingClientRect();
|
|
15
|
-
|
|
22
|
+
setCanvasSize({
|
|
16
23
|
width,
|
|
17
24
|
height
|
|
18
|
-
};
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}, [canvasRef]);
|
|
28
|
+
const worldSize = useMemo(() => {
|
|
29
|
+
if (size) {
|
|
30
|
+
return { ...size };
|
|
31
|
+
}
|
|
32
|
+
if (canvasSize) {
|
|
33
|
+
return canvasSize;
|
|
19
34
|
}
|
|
20
35
|
if (!applicationRef) {
|
|
21
36
|
return {
|
|
@@ -24,24 +39,10 @@ export const World = ({ children, eventMode, size }) => {
|
|
|
24
39
|
};
|
|
25
40
|
}
|
|
26
41
|
return {
|
|
27
|
-
width: applicationRef
|
|
28
|
-
height: applicationRef
|
|
42
|
+
width: applicationRef?.screen.width,
|
|
43
|
+
height: applicationRef?.screen.height
|
|
29
44
|
};
|
|
30
|
-
}, [size,
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
if (!applicationRef) {
|
|
33
|
-
const application = new Application();
|
|
34
|
-
application.init().then(() => {
|
|
35
|
-
setApplicationRef(application);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}, [applicationRef]);
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
if (applicationRef && canvasRef.current) {
|
|
41
|
-
applicationRef.resizeTo = canvasRef.current;
|
|
42
|
-
applicationRef.resize();
|
|
43
|
-
}
|
|
44
|
-
}, [canvasRef, applicationRef]);
|
|
45
|
+
}, [size, canvasSize, applicationRef]);
|
|
45
46
|
const conextValue = useMemo(() => ({
|
|
46
47
|
application: applicationRef,
|
|
47
48
|
size: worldSize
|
|
@@ -58,13 +59,8 @@ export const World = ({ children, eventMode, size }) => {
|
|
|
58
59
|
}
|
|
59
60
|
};
|
|
60
61
|
}, [canvasRef, applicationRef]);
|
|
61
|
-
useEffect(() => {
|
|
62
|
-
if (applicationRef) {
|
|
63
|
-
applicationRef.stage.eventMode = eventMode;
|
|
64
|
-
}
|
|
65
|
-
}, [eventMode, applicationRef]);
|
|
66
62
|
return (React.createElement(WorldContext.Provider, { value: conextValue },
|
|
67
63
|
React.createElement(AssetsManager, null,
|
|
68
64
|
React.createElement(Stage, null, children),
|
|
69
|
-
React.createElement("div", { style: { width: "100%", height: "100%" }, ref:
|
|
65
|
+
React.createElement("div", { style: { width: "100%", height: "100%" }, ref: onCanvasRef }))));
|
|
70
66
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./World.context";
|
|
2
|
-
export * from "./World";
|
|
1
|
+
export * from "./World.context.js";
|
|
2
|
+
export * from "./World.js";
|
package/dist/src/world/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./World.context";
|
|
2
|
-
export * from "./World";
|
|
1
|
+
export * from "./World.context.js";
|
|
2
|
+
export * from "./World.js";
|