-
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for filter components
- Loading branch information
Showing
19 changed files
with
200 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Filter } from 'pixi.js'; | ||
|
||
import type { ContainerElement } from '../typedefs/ContainerElement.ts'; | ||
import type { Instance } from '../typedefs/Instance.ts'; | ||
|
||
export function attach( | ||
parentInstance: Instance<ContainerElement>, | ||
childInstance: Instance, | ||
targetIndex?: number | ||
) | ||
{ | ||
if (childInstance instanceof Filter) | ||
{ | ||
childInstance.__pixireact.parent = parentInstance; | ||
|
||
if (typeof targetIndex === 'number') | ||
{ | ||
parentInstance.__pixireact.filters.splice(targetIndex, 0, childInstance); | ||
} | ||
else | ||
{ | ||
parentInstance.__pixireact.filters.push(childInstance); | ||
} | ||
|
||
parentInstance.filters = parentInstance.__pixireact.filters; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Filter } from 'pixi.js'; | ||
|
||
import type { ContainerElement } from 'typedefs/ContainerElement.ts'; | ||
import type { Instance } from '../typedefs/Instance.ts'; | ||
|
||
export function detach(childInstance: Instance) | ||
{ | ||
if (childInstance instanceof Filter) | ||
{ | ||
const parentInstance = childInstance.__pixireact.parent as Instance<ContainerElement>; | ||
|
||
if (parentInstance) | ||
{ | ||
const filterIndex = parentInstance.__pixireact.filters.indexOf(childInstance); | ||
|
||
parentInstance.__pixireact.filters.splice(filterIndex, 1); | ||
parentInstance.filters = parentInstance.__pixireact.filters; | ||
} | ||
|
||
childInstance.__pixireact.parent = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,22 @@ | ||
import { catalogue } from './catalogue.ts'; | ||
|
||
import type { ContainerElement } from '../typedefs/ContainerElement.ts'; | ||
import type { FilterElement } from '../typedefs/FilterElement.ts'; | ||
import type { Instance } from '../typedefs/Instance.ts'; | ||
|
||
export function hideInstance(instance: Instance) | ||
{ | ||
instance.visible = false; | ||
const { | ||
Container, | ||
Filter, | ||
} = catalogue; | ||
|
||
if (Container && instance instanceof Container) | ||
{ | ||
(instance as ContainerElement).visible = false; | ||
} | ||
else if (Filter && instance instanceof Filter) | ||
{ | ||
(instance as FilterElement).enabled = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,43 @@ | ||
import { | ||
Container, | ||
Filter, | ||
} from 'pixi.js'; | ||
import { attach } from './attach.ts'; | ||
import { detach } from './detach.ts'; | ||
import { invariant } from './invariant.ts'; | ||
import { log } from './log.ts'; | ||
|
||
import type { ContainerElement } from '../typedefs/ContainerElement.ts'; | ||
import type { FilterElement } from '../typedefs/FilterElement.ts'; | ||
import type { Instance } from '../typedefs/Instance.ts'; | ||
|
||
export function insertBefore(parentInstance: Instance, childInstance: Instance, beforeChildInstance: Instance) | ||
export function insertBefore(parentInstance: Instance<ContainerElement>, childInstance: Instance, beforeChildInstance: Instance) | ||
{ | ||
log('info', 'lifecycle::insertBefore'); | ||
|
||
invariant(childInstance !== beforeChildInstance, 'Cannot insert node before itself'); | ||
|
||
if (parentInstance.children.indexOf(childInstance) === -1) | ||
if (childInstance instanceof Container) | ||
{ | ||
parentInstance.removeChild(childInstance); | ||
const childContainerInstance = childInstance as Instance<ContainerElement>; | ||
|
||
if (childContainerInstance.parent === parentInstance) | ||
{ | ||
parentInstance.removeChild(childContainerInstance); | ||
} | ||
|
||
const index = parentInstance.getChildIndex(beforeChildInstance as Instance<ContainerElement>); | ||
|
||
parentInstance.addChildAt(childContainerInstance, index); | ||
} | ||
else if (childInstance instanceof Filter) | ||
{ | ||
const childFilterInstance = childInstance as Instance<FilterElement>; | ||
const instanceState = childFilterInstance.__pixireact; | ||
|
||
const index = parentInstance.getChildIndex(beforeChildInstance); | ||
const targetIndex = instanceState.filters.indexOf(beforeChildInstance as Instance<FilterElement>); | ||
|
||
parentInstance.addChildAt(childInstance, index); | ||
detach(childInstance); | ||
attach(parentInstance, childInstance, targetIndex); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,20 @@ | ||
import { | ||
Container, | ||
Filter, | ||
} from 'pixi.js'; | ||
|
||
import type { ContainerElement } from '../typedefs/ContainerElement.ts'; | ||
import type { FilterElement } from '../typedefs/FilterElement.ts'; | ||
import type { Instance } from '../typedefs/Instance.ts'; | ||
|
||
export function unhideInstance(instance: Instance) | ||
{ | ||
instance.visible = true; | ||
if (Container && instance instanceof Container) | ||
{ | ||
(instance as ContainerElement).visible = true; | ||
} | ||
else if (Filter && instance instanceof Filter) | ||
{ | ||
(instance as FilterElement).enabled = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import type { Filter } from 'pixi.js'; | ||
import type { ReactElement } from 'react'; | ||
|
||
export type FilterElement = Filter & ReactElement; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import type { Filter } from 'pixi.js'; | ||
import type { ContainerElement } from './ContainerElement.ts'; | ||
import type { Instance } from './Instance.ts'; | ||
|
||
export interface InstanceState | ||
{ | ||
autoRemovedBeforeAppend?: boolean; | ||
parent: null | Instance; | ||
filters: Filter[], | ||
parent: null | Instance<ContainerElement>; | ||
root: Instance; | ||
type: string; | ||
} |
Oops, something went wrong.