-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from DRincs-Productions/146-edit-all-label-ma…
…nagement 146 edit all label management
- Loading branch information
Showing
13 changed files
with
196 additions
and
137 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,3 +1,12 @@ | ||
import Label from "./Label" | ||
|
||
export default class CloseLabel extends Label { } | ||
export const CLOSE_LABEL_ID = "__close-label-id__" | ||
|
||
/** | ||
* CloseLabel is a label used for closing the menu. | ||
*/ | ||
export default class CloseLabel extends Label { | ||
constructor(choiseIndex?: number) { | ||
super(CLOSE_LABEL_ID, [], undefined, choiseIndex) | ||
} | ||
} |
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,68 +1,35 @@ | ||
import { Label } from "../classes" | ||
import { StepLabelType } from "../types" | ||
import { LabelIdType } from "../types/LabelIdType" | ||
|
||
export const registeredLabels: { [key: LabelIdType]: typeof Label } = {} | ||
/** | ||
* Is a decorator that register a label in the game. | ||
* Is a required decorator for use the label in the game. | ||
* Thanks to this decoration the game has the possibility of updating the labels to the latest modification and saving the game. | ||
* @param name is th identifier of the label, by default is the name of the class | ||
* @returns | ||
*/ | ||
export default function labelDecorator(name?: LabelIdType) { | ||
return function (target: typeof Label) { | ||
if (!name) { | ||
name = target.name | ||
} | ||
if (registeredLabels[name]) { | ||
console.warn(`[Pixi'VN] Label ${name} already exists, it will be overwritten`) | ||
} | ||
registeredLabels[name] = target | ||
} | ||
} | ||
export const registeredLabels: { [key: LabelIdType]: Label<any> } = {} | ||
|
||
/** | ||
* is a function that returns the type of the label | ||
* @param labelName is the name of the label | ||
* @returns the label type | ||
* Creates a new label and registers it in the system | ||
* @param id The id of the label, it must be unique | ||
* @param steps The steps of the label | ||
* @param onStepRun is a function that will be executed before any step is executed, is useful for example to make sure all images used have been cached | ||
* @returns The created label | ||
*/ | ||
export function getLabelTypeByClassName<T extends typeof Label>(labelName: LabelIdType): T | undefined { | ||
try { | ||
let labelType = registeredLabels[labelName] | ||
if (!labelType) { | ||
console.error(`[Pixi'VN] Label ${labelName} not found`) | ||
return | ||
} | ||
new labelType() | ||
return labelType as T | ||
} | ||
catch (e) { | ||
console.error(`[Pixi'VN] Error while getting Label ${labelName}`, e) | ||
return | ||
export function newLabel<T extends {} = {}>(id: LabelIdType, steps: StepLabelType<T>[], onStepRun?: () => void | Promise<void>): Label<T> { | ||
if (registeredLabels[id]) { | ||
console.warn(`[Pixi'VN] Label ${id} already exists, it will be overwritten`) | ||
} | ||
let label = new Label<T>(id, steps, onStepRun) | ||
registeredLabels[id] = label | ||
return label | ||
} | ||
|
||
/** | ||
* is a function that returns the instance of the label | ||
* @param labelName is the name of the label | ||
* @returns the label | ||
* Gets a label by its id | ||
* @param id The id of the label | ||
* @returns The label or undefined if it does not exist | ||
*/ | ||
export function getLabelInstanceByClassName<T extends Label>(labelName: LabelIdType): T | undefined { | ||
try { | ||
let labelType = registeredLabels[labelName] | ||
if (!labelType) { | ||
console.error(`[Pixi'VN] Label ${labelName} not found`) | ||
return | ||
} | ||
let label = new labelType() | ||
let step = label.steps | ||
if (step.length = 0) { | ||
console.warn(`[Pixi'VN] Label ${labelName} has no steps`) | ||
} | ||
return label as T | ||
} | ||
catch (e) { | ||
console.error(`[Pixi'VN] Error while getting Label ${labelName}`, e) | ||
export function getLabelById<T = Label<any>>(id: LabelIdType): T | undefined { | ||
let label = registeredLabels[id] | ||
if (!label) { | ||
console.error(`[Pixi'VN] Label ${id} not found`) | ||
return | ||
} | ||
return label as T | ||
} |
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,6 @@ | ||
export { default as canvasElementDecorator } from './CanvasElementDecorator'; | ||
export { getAllCharacters, getCharacterById, saveCharacter } from './CharacterDecorator'; | ||
export { default as eventDecorator } from './EventDecorator'; | ||
export { default as labelDecorator } from './LabelDecorator'; | ||
export { getLabelById, newLabel } from './LabelDecorator'; | ||
export { default as tickerDecorator } from './TickerDecorator'; | ||
|
Oops, something went wrong.