Skip to content

Commit

Permalink
Merge pull request #282 from DRincs-Productions/281-imagecontainer-lo…
Browse files Browse the repository at this point in the history
…ading

281 imagecontainer loading
  • Loading branch information
BlackRam-oss authored Dec 5, 2024
2 parents 170ba4a + 3a0d5b9 commit eeb8ad2
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 19 deletions.
14 changes: 9 additions & 5 deletions src/classes/canvas/ImageContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,21 @@ export default class ImageContainer extends Container<ImageSprite> {
}

/**
* The texture of the first child or the first child with the empty texture.
* The texture of the first child.
* If there is no child, it returns a new {@link Texture}.
*/
get texture() {
if (this.children.length > 0) {
let childrenEmpty = this.children.find(child => child.texture._source.label === "EMPTY")
if (childrenEmpty) {
return childrenEmpty.texture
}
return this.children[0].texture
}
return new Texture()
}

/**
* Check if there is a child with the empty texture.
* @returns A boolean that is true if there is a child with the empty texture.
*/
get haveEmptyTexture() {
return this.children.some(child => child.texture._source.label === "EMPTY")
}
}
8 changes: 8 additions & 0 deletions src/classes/canvas/ImageSprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,12 @@ export default class ImageSprite<Memory extends ImageSpriteMemory = ImageSpriteM
console.error("[Pixi’VN] Error into ImageSprite.load()", e)
})
}

/**
* Check if the texture is empty.
* @returns A boolean that is true if the texture is empty.
*/
get haveEmptyTexture() {
return this.texture._source.label === "EMPTY"
}
}
8 changes: 6 additions & 2 deletions src/classes/ticker/FadeAlphaTicker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Container as PixiContainer, Sprite as PixiSprite } from "pixi.js";
import { Container as PixiContainer } from "pixi.js";
import { TickerValue } from "../..";
import { tickerDecorator } from "../../decorators";
import { checkIfTextureIsEmpty } from "../../functions/texture-utility";
import { canvas } from "../../managers";
import { FadeAlphaTickerProps } from "../../types/ticker/FadeAlphaTickerProps";
import TickerBase from "./TickerBase";
Expand Down Expand Up @@ -50,8 +51,11 @@ export default class FadeAlphaTicker extends TickerBase<FadeAlphaTickerProps> {
aliases
.filter((alias) => {
let element = canvas.find(alias)
if (!element) {
return false
}
if (args.startOnlyIfHaveTexture) {
if (element && element instanceof PixiSprite && element.texture?.label == "EMPTY") {
if (!checkIfTextureIsEmpty(element)) {
return false
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/classes/ticker/MoveTicker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Container as PixiContainer, Sprite as PixiSprite } from "pixi.js";
import { Container as PixiContainer } from "pixi.js";
import { TickerValue } from "../..";
import { tickerDecorator } from "../../decorators";
import { checkIfTextureIsEmpty } from "../../functions/texture-utility";
import { updateTickerProgression } from "../../functions/ticker-utility";
import { canvas } from "../../managers";
import { MoveTickerProps } from "../../types/ticker";
Expand Down Expand Up @@ -51,8 +52,11 @@ export default class MoveTicker extends TickerBase<MoveTickerProps> {
aliases
.filter((alias) => {
let element = canvas.find(alias)
if (!element) {
return false
}
if (args.startOnlyIfHaveTexture) {
if (element && element instanceof PixiSprite && element.texture?.label == "EMPTY") {
if (!checkIfTextureIsEmpty(element)) {
return false
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/classes/ticker/RotateTicker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Container as PixiContainer, Sprite as PixiSprite } from "pixi.js";
import { Container as PixiContainer } from "pixi.js";
import { TickerValue } from "../..";
import { tickerDecorator } from "../../decorators";
import { checkIfTextureIsEmpty } from "../../functions/texture-utility";
import { updateTickerProgression } from "../../functions/ticker-utility";
import { canvas } from "../../managers";
import { RotateTickerProps } from "../../types/ticker/RotateTickerProps";
Expand Down Expand Up @@ -42,8 +43,11 @@ export default class RotateTicker extends TickerBase<RotateTickerProps> {
aliases
.filter((alias) => {
let element = canvas.find(alias)
if (!element) {
return false
}
if (args.startOnlyIfHaveTexture) {
if (element && element instanceof PixiSprite && element.texture?.label == "EMPTY") {
if (!checkIfTextureIsEmpty(element)) {
return false
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/classes/ticker/ZoomTicker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Container as PixiContainer, Sprite as PixiSprite } from "pixi.js";
import { Container as PixiContainer } from "pixi.js";
import { TickerValue } from "../..";
import { tickerDecorator } from "../../decorators";
import { checkIfTextureIsEmpty } from "../../functions/texture-utility";
import { updateTickerProgression } from "../../functions/ticker-utility";
import { canvas } from "../../managers";
import { ZoomTickerProps } from "../../types/ticker";
Expand Down Expand Up @@ -55,8 +56,11 @@ export default class ZoomTicker extends TickerBase<ZoomTickerProps> {
alias
.filter((alias) => {
let element = canvas.find(alias)
if (!element) {
return false
}
if (args.startOnlyIfHaveTexture) {
if (element && element instanceof PixiSprite && element.texture?.label == "EMPTY") {
if (!checkIfTextureIsEmpty(element)) {
return false
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/functions/canvas/canvas-transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export async function showWithDissolveTransition<T extends CanvasBaseItem<any> |
if (id) {
mustBeCompletedBeforeNextStep && canvas.addTickerMustBeCompletedBeforeNextStep({ id: id })
}
if ((canvasElement instanceof ImageSprite || canvasElement instanceof ImageContainer) && canvasElement.texture?.label == "EMPTY") {
if ((canvasElement instanceof ImageSprite || canvasElement instanceof ImageContainer) && canvasElement.haveEmptyTexture) {
await canvasElement.load()
}
if (id) {
Expand Down Expand Up @@ -166,7 +166,7 @@ export async function showWithFadeTransition<T extends CanvasBaseItem<any> | str
res ? res.push(id2) : res = [id2]
mustBeCompletedBeforeNextStep && canvas.addTickerMustBeCompletedBeforeNextStep({ id: id2, alias: alias })
}
if ((canvasElement instanceof ImageSprite || canvasElement instanceof ImageContainer) && canvasElement.texture?.label == "EMPTY") {
if ((canvasElement instanceof ImageSprite || canvasElement instanceof ImageContainer) && canvasElement.haveEmptyTexture) {
await canvasElement.load()
}
return res
Expand Down Expand Up @@ -251,7 +251,7 @@ export async function moveIn<T extends CanvasBaseItem<any> | string = string>(
canvas.putOnPauseTicker(alias, id)
mustBeCompletedBeforeNextStep && canvas.addTickerMustBeCompletedBeforeNextStep({ id: id })
}
if ((canvasElement instanceof ImageSprite || canvasElement instanceof ImageContainer) && canvasElement.texture?.label == "EMPTY") {
if ((canvasElement instanceof ImageSprite || canvasElement instanceof ImageContainer) && canvasElement.haveEmptyTexture) {
await canvasElement.load()
}
if (id) {
Expand Down Expand Up @@ -394,7 +394,7 @@ export async function zoomIn<T extends CanvasBaseItem<any> | string = string>(
canvas.putOnPauseTicker(alias, id)
mustBeCompletedBeforeNextStep && canvas.addTickerMustBeCompletedBeforeNextStep({ id: id })
}
if ((canvasElement instanceof ImageSprite || canvasElement instanceof ImageContainer) && canvasElement.texture?.label == "EMPTY") {
if ((canvasElement instanceof ImageSprite || canvasElement instanceof ImageContainer) && canvasElement.haveEmptyTexture) {
await canvasElement.load()
}
if (id) {
Expand Down Expand Up @@ -549,7 +549,7 @@ export async function pushIn<T extends CanvasBaseItem<any> | string = string>(
canvas.putOnPauseTicker(alias, id)
mustBeCompletedBeforeNextStep && canvas.addTickerMustBeCompletedBeforeNextStep({ id: id })
}
if ((canvasElement instanceof ImageSprite || canvasElement instanceof ImageContainer) && canvasElement.texture?.label == "EMPTY") {
if ((canvasElement instanceof ImageSprite || canvasElement instanceof ImageContainer) && canvasElement.haveEmptyTexture) {
await canvasElement.load()
}
if (id) {
Expand Down
13 changes: 12 additions & 1 deletion src/functions/texture-utility.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Assets, ColorSource, FillGradient, FillPattern, StrokeStyle, TextStyle, TextStyleOptions, Texture } from 'pixi.js';
import { Assets, ColorSource, FillGradient, FillPattern, Sprite as PixiSprite, StrokeStyle, TextStyle, TextStyleOptions, Texture } from 'pixi.js';
import { CanvasBaseItem, Container, ImageContainer, ImageSprite } from '../classes';

/**
* Get a texture from a url.
Expand Down Expand Up @@ -71,3 +72,13 @@ export function getTextStyle(style: TextStyle): TextStyleOptions {
wordWrapWidth: style.wordWrapWidth,
}
}

export function checkIfTextureIsEmpty<T extends Container | CanvasBaseItem<any> = Container>(element: T) {
if ((element instanceof ImageSprite || element instanceof ImageContainer) && element.haveEmptyTexture) {
return false
}
else if (element instanceof PixiSprite && element.texture?.label == "EMPTY") {
return false
}
return true
}

0 comments on commit eeb8ad2

Please sign in to comment.