# Class: LabelJson<T> (/jsdoc/pixi-vn-json/index/classes/LabelJson)



Defined in: [src/interpreter/LabelJson.ts:53](https://github.com/DRincs-Productions/pixi-vn-json/blob/f2528001a05fe854a897e0c1d03c7e311fe08af2/src/interpreter/LabelJson.ts#L53)

A label whose steps are defined by a plain JSON structure ([PixiVNJsonLabelStep](/jsdoc/pixi-vn-json/index/type-aliases/PixiVNJsonLabelStep)\[]).

`LabelJson` bridges pixi-vn's label system and the JSON script format: each step is
lazily converted to a StepLabelType closure that resolves dialogues, choices,
operations, and conditional overrides at runtime via [JsonUnifier](/jsdoc/pixi-vn-json/core/classes/JsonUnifier).

## Extends [#extends]

* `LabelAbstract`\<`LabelJson`\<`T`>, `T`>

## Type Parameters [#type-parameters]

### T [#t]

`T` *extends* `object` = `object`

The type of the props object passed between steps.

## Constructors [#constructors]

### Constructor [#constructor]

\> **new LabelJson**\<`T`>(`id`, `steps`, `props?`, `options?`): `LabelJson`\<`T`>

Defined in: [src/interpreter/LabelJson.ts:59](https://github.com/DRincs-Productions/pixi-vn-json/blob/f2528001a05fe854a897e0c1d03c7e311fe08af2/src/interpreter/LabelJson.ts#L59)

#### Parameters [#parameters]

##### id [#id]

`string`

is the id of the label

##### steps [#steps]

([`PixiVNJsonLabelStep`](/jsdoc/pixi-vn-json/index/type-aliases/PixiVNJsonLabelStep) | (() => [`PixiVNJsonLabelStep`](/jsdoc/pixi-vn-json/index/type-aliases/PixiVNJsonLabelStep)))\[]

is the list of steps that the label will perform

##### props? [#props]

`LabelProps`\<`LabelJson`\<`T`>, `number`>

is the properties of the label

##### options? [#options]

`LabelJsonOptions` = `{}`

#### Returns [#returns]

`LabelJson`\<`T`>

#### Overrides [#overrides]

`LabelAbstract<LabelJson<T>, T>.constructor`

## Properties [#properties]

### id [#id-1]

\> `readonly` **id**: `string`

Defined in: node\_modules/@drincs/pixi-vn/dist/narration.d.ts:519

Get the id of the label. This variable is used in the system to get the label by id, RegisteredLabels.get

#### Inherited from [#inherited-from]

`LabelAbstract.id`

## Accessors [#accessors]

### onLoadingLabel [#onloadinglabel]

#### Get Signature [#get-signature]

\> **get** **onLoadingLabel**(): ((`stepId`, `label`) => `void` | `Promise`\<`void`>) | `undefined`

Defined in: node\_modules/@drincs/pixi-vn/dist/narration.d.ts:539

Is a function that will be executed in [onStepStart](#onstepstart) if the id of the step is 0
and when the user laods a save file.
When you load a save file, will be executed all onLoadingLabel functions of the narration.openedLabels.
It is useful for example to make sure all images used have been cached

##### Example [#example]

```ts title="content/labels/start.label.ts"
newLabel("start", [], {
    onLoadingLabel: async (stepId, label) => {
        await Assets.load('path/to/image1.png')
        await Assets.load('path/to/image2.png')
    }
})
```

##### Returns [#returns-1]

((`stepId`, `label`) => `void` | `Promise`\<`void`>) | `undefined`

#### Inherited from [#inherited-from-1]

`LabelAbstract.onLoadingLabel`

***

### onStepEnd [#onstepend]

#### Get Signature [#get-signature-1]

\> **get** **onStepEnd**(): ((`stepId`, `label`) => `void` | `Promise`\<`void`>) | `undefined`

Defined in: node\_modules/@drincs/pixi-vn/dist/narration.d.ts:541

A function executed after each `step`. See more \<DynamicLink href="/start/labels-advanced#onstepend">here</DynamicLink>.

##### Example [#example-1]

```ts
const startLabel = newLabel("start", [
    async () => {
        await showImage("image1", "path/to/image1.png")
        await showImage("image2", "path/to/image2.png")
    }
], {
    onLoadingLabel: async (stepIndex, label) => {
        await Assets.load("path/to/image1.png")
        await Assets.load("path/to/image2.png")
    }
})
```

##### Returns [#returns-2]

((`stepId`, `label`) => `void` | `Promise`\<`void`>) | `undefined`

#### Inherited from [#inherited-from-2]

`LabelAbstract.onStepEnd`

***

### onStepStart [#onstepstart]

#### Get Signature [#get-signature-2]

\> **get** **onStepStart**(): ((`stepId`, `label`) => `void` | `Promise`\<`void`>) | `undefined`

Defined in: node\_modules/@drincs/pixi-vn/dist/narration.d.ts:537

A function executed before each `step`.

##### Example [#example-2]

```ts
const startLabel = newLabel("start", [
    () => {
        narration.dialogue = "Step 1"
    },
    () => {
        narration.dialogue = "Step 2"
    }
], {
    onStepStart: (stepIndex, label) => {
        console.log(`Step ${stepIndex} started`)
    }
})
```

##### Returns [#returns-3]

((`stepId`, `label`) => `void` | `Promise`\<`void`>) | `undefined`

#### Inherited from [#inherited-from-3]

`LabelAbstract.onStepStart`

***

### stepCount [#stepcount]

#### Get Signature [#get-signature-3]

\> **get** **stepCount**(): `number`

Defined in: [src/interpreter/LabelJson.ts:106](https://github.com/DRincs-Productions/pixi-vn-json/blob/f2528001a05fe854a897e0c1d03c7e311fe08af2/src/interpreter/LabelJson.ts#L106)

Get the number of steps in the label. This variable is used in the system to get the number of steps in the label.

##### Returns [#returns-4]

`number`

The number of steps in the label

#### Overrides [#overrides-1]

`LabelAbstract.stepCount`

***

### steps [#steps-1]

#### Get Signature [#get-signature-4]

\> **get** **steps**(): `StepLabelType`\<`T`>\[]

Defined in: [src/interpreter/LabelJson.ts:101](https://github.com/DRincs-Productions/pixi-vn-json/blob/f2528001a05fe854a897e0c1d03c7e311fe08af2/src/interpreter/LabelJson.ts#L101)

##### Returns [#returns-5]

`StepLabelType`\<`T`>\[]

## Methods [#methods]

### getStepById() [#getstepbyid]

\> **getStepById**(`stepId`): `StepLabelType`\<`T`> | `undefined`

Defined in: [src/interpreter/LabelJson.ts:109](https://github.com/DRincs-Productions/pixi-vn-json/blob/f2528001a05fe854a897e0c1d03c7e311fe08af2/src/interpreter/LabelJson.ts#L109)

Get the step by id

#### Parameters [#parameters-1]

##### stepId [#stepid]

`number`

Id of the step

#### Returns [#returns-6]

`StepLabelType`\<`T`> | `undefined`

The step or undefined if it does not exist

#### Overrides [#overrides-2]

`LabelAbstract.getStepById`

***

### getStepSha() [#getstepsha]

\> **getStepSha**(`index`): `string` | `undefined`

Defined in: [src/interpreter/LabelJson.ts:131](https://github.com/DRincs-Productions/pixi-vn-json/blob/f2528001a05fe854a897e0c1d03c7e311fe08af2/src/interpreter/LabelJson.ts#L131)

Returns the SHA-1 hash of the raw step at the given index.
Can be used to detect step changes across label reloads.

#### Parameters [#parameters-2]

##### index [#index]

`number`

Zero-based index of the step.

#### Returns [#returns-7]

`string` | `undefined`

The hex SHA-1 string, or `undefined` if the index is out of range.

#### Overrides [#overrides-3]

`LabelAbstract.getStepSha`
