Skip to content

Commit

Permalink
refactor: reorganize structure in code structure of ProjectionRendere…
Browse files Browse the repository at this point in the history
…r has been reorganized for better readability and maintenance. The 'patch function been refored usedefPatch' the 'vue3-pixi' package, and the 'patchCamera function been removed. The 'setter' file has been moved to a new 'internal' folder for better organization or behavior.
  • Loading branch information
hairyf committed Jun 9, 2023
1 parent 27b0305 commit 33809e3
Show file tree
Hide file tree
Showing 27 changed files with 223 additions and 141 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ jobs:
- name: Install
run: pnpm install

# - name: Build
# run: pnpm -r build
- name: Build
run: pnpm -r build

- name: Test
run: pnpm run test
2 changes: 1 addition & 1 deletion packages/vue3-pixi-projection/src/elements/camera3d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
DefineComponent,
VNodeProps,
} from 'vue-demi'
import type { AllowedPixiProps, PixiEvents } from '@vue-pixi/renderer'
import type { AllowedPixiProps, PixiEvents } from 'vue3-pixi'
import type { Camera3d } from 'pixi-projection'

export interface Camera3dProps {
Expand Down
2 changes: 1 addition & 1 deletion packages/vue3-pixi-projection/src/elements/container2d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AllowedPixiProps, PixiEvents } from '@vue-pixi/renderer'
import type { AllowedPixiProps, PixiEvents } from 'vue3-pixi'
import type { ComponentOptionsMixin, DefineComponent, VNodeProps } from 'vue-demi'
import type { Container2d } from 'pixi-projection'
import type { Allowed2dPixiProps } from './props'
Expand Down
2 changes: 1 addition & 1 deletion packages/vue3-pixi-projection/src/elements/container3d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AllowedPixiProps, PixiEvents } from '@vue-pixi/renderer'
import type { AllowedPixiProps, PixiEvents } from 'vue3-pixi'
import type { ComponentOptionsMixin, DefineComponent, VNodeProps } from 'vue-demi'
import type { Container3d } from 'pixi-projection'
import type { Allowed3dPixiProps } from './props'
Expand Down
2 changes: 1 addition & 1 deletion packages/vue3-pixi-projection/src/elements/mesh2d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AllowedPixiProps, MeshProps, PixiEvents } from '@vue-pixi/renderer'
import type { AllowedPixiProps, MeshProps, PixiEvents } from 'vue3-pixi'
import type { ComponentOptionsMixin, DefineComponent, VNodeProps } from 'vue-demi'
import type { Mesh2d } from 'pixi-projection'
import type { Allowed2dPixiProps } from './props'
Expand Down
2 changes: 1 addition & 1 deletion packages/vue3-pixi-projection/src/elements/mesh3d2d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AllowedPixiProps, MeshProps, PixiEvents } from '@vue-pixi/renderer'
import type { AllowedPixiProps, MeshProps, PixiEvents } from 'vue3-pixi'
import type { ComponentOptionsMixin, DefineComponent, VNodeProps } from 'vue-demi'
import type { Mesh3d2d } from 'pixi-projection'
import type { Allowed3dPixiProps } from './props'
Expand Down
2 changes: 1 addition & 1 deletion packages/vue3-pixi-projection/src/elements/simpleMesh2d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AllowedPixiProps, MeshProps, PixiEvents } from '@vue-pixi/renderer'
import type { AllowedPixiProps, MeshProps, PixiEvents } from 'vue3-pixi'
import type { ComponentOptionsMixin, DefineComponent, VNodeProps } from 'vue-demi'
import type { SimpleMesh2d } from 'pixi-projection'
import type { Allowed2dPixiProps } from './props'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AllowedPixiProps, MeshProps, PixiEvents } from '@vue-pixi/renderer'
import type { AllowedPixiProps, MeshProps, PixiEvents } from 'vue3-pixi'
import type { ComponentOptionsMixin, DefineComponent, VNodeProps } from 'vue-demi'
import type { SimpleMesh3d2d } from 'pixi-projection'
import type { Allowed3dPixiProps } from './props'
Expand Down
2 changes: 1 addition & 1 deletion packages/vue3-pixi-projection/src/elements/sprite2d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AllowedPixiProps, PixiEvents, SpriteProps } from '@vue-pixi/renderer'
import type { AllowedPixiProps, PixiEvents, SpriteProps } from 'vue3-pixi'
import type { ComponentOptionsMixin, DefineComponent, VNodeProps } from 'vue-demi'
import type { Sprite2d } from 'pixi-projection'
import type { Allowed2dPixiProps } from './props'
Expand Down
2 changes: 1 addition & 1 deletion packages/vue3-pixi-projection/src/elements/sprite2s.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AllowedPixiProps, PixiEvents, SpriteProps } from '@vue-pixi/renderer'
import type { AllowedPixiProps, PixiEvents, SpriteProps } from 'vue3-pixi'
import type { ComponentOptionsMixin, DefineComponent, VNodeProps } from 'vue-demi'
import type { Sprite2s } from 'pixi-projection'
import type { Allowed2sPixiProps } from './props'
Expand Down
2 changes: 1 addition & 1 deletion packages/vue3-pixi-projection/src/elements/sprite3d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AllowedPixiProps, PixiEvents, SpriteProps } from '@vue-pixi/renderer'
import type { AllowedPixiProps, PixiEvents, SpriteProps } from 'vue3-pixi'
import type { ComponentOptionsMixin, DefineComponent, VNodeProps } from 'vue-demi'
import type { Sprite3d } from 'pixi-projection'
import type { Allowed3dPixiProps } from './props'
Expand Down
2 changes: 1 addition & 1 deletion packages/vue3-pixi-projection/src/elements/text2d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AllowedPixiProps, PixiEvents, TextProps } from '@vue-pixi/renderer'
import type { AllowedPixiProps, PixiEvents, TextProps } from 'vue3-pixi'
import type { ComponentOptionsMixin, DefineComponent, VNodeProps } from 'vue-demi'
import type { Text2d } from 'pixi-projection'
import type { Allowed2dPixiProps } from './props'
Expand Down
2 changes: 1 addition & 1 deletion packages/vue3-pixi-projection/src/elements/text2s.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AllowedPixiProps, PixiEvents, TextProps } from '@vue-pixi/renderer'
import type { AllowedPixiProps, PixiEvents, TextProps } from 'vue3-pixi'
import type { ComponentOptionsMixin, DefineComponent, VNodeProps } from 'vue-demi'
import type { Text2s } from 'pixi-projection'
import type { Allowed2sPixiProps } from './props'
Expand Down
2 changes: 1 addition & 1 deletion packages/vue3-pixi-projection/src/elements/text3d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AllowedPixiProps, PixiEvents, TextProps } from '@vue-pixi/renderer'
import type { AllowedPixiProps, PixiEvents, TextProps } from 'vue3-pixi'
import type { ComponentOptionsMixin, DefineComponent, VNodeProps } from 'vue-demi'
import type { Text3d } from 'pixi-projection'
import type { Allowed3dPixiProps } from './props'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AllowedPixiProps, PixiEvents, TilingSpriteProps } from '@vue-pixi/renderer'
import type { AllowedPixiProps, PixiEvents, TilingSpriteProps } from 'vue3-pixi'
import type { ComponentOptionsMixin, DefineComponent, VNodeProps } from 'vue-demi'
import type { TilingSprite2d } from 'pixi-projection'
import type { Allowed2dPixiProps } from './props'
Expand Down
5 changes: 2 additions & 3 deletions packages/vue3-pixi-projection/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Renderer } from '@vue-pixi/renderer'
import { elements, pathProp } from './renderer'
import { ProjectionRenderer } from './renderer'

export default { elements, pathProp } as Renderer
export default ProjectionRenderer

export * from './global'
export * from './types'
72 changes: 0 additions & 72 deletions packages/vue3-pixi-projection/src/renderer/elements.ts

This file was deleted.

171 changes: 169 additions & 2 deletions packages/vue3-pixi-projection/src/renderer/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,169 @@
export * from './elements'
export * from './patchProp'
import {
Camera3d,
Container2d,
Container3d,
Mesh2d,
Mesh3d2d,
SimpleMesh2d,
SimpleMesh3d2d,
Sprite2d,
Sprite2s,
Sprite3d,
Text2d,
Text2s,
Text3d,
TilingSprite2d,
} from 'pixi-projection'
import type { Renderer, RendererOptions } from 'vue3-pixi'
import { normalizeTexture, setSkipFirstValue } from 'vue3-pixi'
import { isUndefined } from '@antfu/utils'
import { patchProp } from './patchProp'

const Container2dRenderer: RendererOptions = {
name: 'Container2d',
createElement: () => new Container2d(),
patchProp,
}
const Container3dRenderer: RendererOptions = {
name: 'Container3d',
createElement: () => new Container3d(),
patchProp,
}

const Sprite2dRenderer: RendererOptions = {
name: 'Sprite2d',
createElement: props => new Sprite2d(normalizeTexture(props.texture)),
patchProp,
}
const Sprite3dRenderer: RendererOptions = {
name: 'Sprite3d',
createElement: props => new Sprite3d(normalizeTexture(props.texture)),
patchProp,
}

const Sprite2sRenderer: RendererOptions = {
name: 'Sprite2s',
createElement: props => new Sprite2s(normalizeTexture(props.texture)),
patchProp,
}

const Camera3dRenderer: RendererOptions = {
name: 'Camera3d',
createElement: (props) => {
const camera = new Camera3d()
if (!isUndefined(props.focus)) {
camera.setPlanes(
props.focus,
props.near,
props.far,
props.orthographic,
)
}
return camera
},
patchProp: (el, key, prevValue, nextValue) => {
const planeKeys = ['focus', 'near', 'far', 'orthographic']
function setPlanes(config: any) {
el.setPlanes(
config.focus || el._focus,
config.near || el.near,
config.far || el.far,
config.orthographic || el._orthographic,
)
}
if (planeKeys.includes(key))
return setSkipFirstValue(el, key, () => setPlanes({ [key]: nextValue }))
patchProp(el, key, prevValue, nextValue)
},
}

const Text2dRenderer: RendererOptions = {
name: 'Text2d',
createElement: props => new Text2d(
props.text,
props.style,
props.canvas,
),
patchProp,
}

const Text2sRenderer: RendererOptions = {
name: 'Text2s',
createElement: props => new Text2s(
props.text,
props.style,
props.canvas,
),
patchProp,
}

const Text3dRenderer: RendererOptions = {
name: 'Text3d',
createElement: props => new Text3d(
props.text,
props.style,
props.canvas,
),
patchProp,
}

const TilingSprite2dRenderer: RendererOptions = {
name: 'TilingSprite2d',
createElement: props => new TilingSprite2d(
normalizeTexture(props.texture),
props.width,
props.height,
),
patchProp,
}

const Mesh2dRenderer: RendererOptions = {
name: 'Mesh2d',
createElement: props => new Mesh2d(
props.geometry,
props.shader,
props.state,
props.drawMode,
),
patchProp,
}

const Mesh3d2dRenderer: RendererOptions = {
name: 'Mesh3d2d',
createElement: props => new Mesh3d2d(
props.geometry,
props.shader,
props.state,
props.drawMode,
),
patchProp,
}

const SimpleMesh2dRenderer: RendererOptions = {
name: 'SimpleMesh2d',
createElement: props => new SimpleMesh2d(normalizeTexture(props.texture)),
patchProp,
}

const SimpleMesh3d2dRenderer: RendererOptions = {
name: 'SimpleMesh3d2d',
createElement: props => new SimpleMesh3d2d(normalizeTexture(props.texture)),
patchProp,
}

export const ProjectionRenderer: Renderer = [
Container2dRenderer,
Container3dRenderer,
Sprite2dRenderer,
Sprite3dRenderer,
Sprite2sRenderer,
Camera3dRenderer,
Text2dRenderer,
Text2sRenderer,
Text3dRenderer,
TilingSprite2dRenderer,
Mesh2dRenderer,
Mesh3d2dRenderer,
SimpleMesh2dRenderer,
SimpleMesh3d2dRenderer,
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './setter'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setPointProperty as _setPointProperty, setPropertyValue } from '@vue-pixi/renderer'
import { setPointProperty as _setPointProperty, setPropertyValue } from 'vue3-pixi'

export function setPointProperty(inst: any, name: string, key: string, prevValue: any, nextValue: any) {
if (_setPointProperty(inst, name, key, prevValue, nextValue))
Expand Down
Loading

0 comments on commit 33809e3

Please sign in to comment.