Skip to content

Commit

Permalink
varius fix
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackRam-oss committed Aug 23, 2024
1 parent b7c72f9 commit 9fe1219
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/classes/LabelJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export default class LabelJson<T extends {} = {}> extends LabelAbstract<LabelJso
break
}
break
case "storage":
case "value":
setStorageJson(operation)
break
}
Expand Down
21 changes: 14 additions & 7 deletions src/functions/PixiVNJsonUtility.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PixiVNJsonConditions, PixiVNJsonStorageGet, PixiVNJsonStorageSet, PixiVNJsonUnionCondition } from "../interface";
import { PixiVNJsonConditions, PixiVNJsonLabelGet, PixiVNJsonStorageGet, PixiVNJsonUnionCondition, PixiVNJsonValueGet, PixiVNJsonValueSet } from "../interface";
import PixiVNJsonConditionalStatements from "../interface/PixiVNJsonConditionalStatements";
import { narration, storage } from "../managers";
import { StorageElementType } from "../types";
import { setFlag } from "./FlagsUtility";
import { getFlag, setFlag } from "./FlagsUtility";

/**
* Get the value from the conditional statements.
Expand Down Expand Up @@ -108,7 +108,7 @@ function getConditionResult(condition: PixiVNJsonConditions): boolean {
* @param value is the value to convert to string
* @returns the value to string
*/
function getValueToString(value: StorageElementType | PixiVNJsonStorageGet): string {
function getValueToString(value: StorageElementType | PixiVNJsonValueGet): string {
let newValue = getValue(value)
if (typeof newValue === "string") {
return newValue
Expand All @@ -124,11 +124,18 @@ function getValueToString(value: StorageElementType | PixiVNJsonStorageGet): str
* @param value is the value to get
* @returns the value from the storage or the value
*/
function getValue(value: StorageElementType | PixiVNJsonStorageGet): any {
function getValue(value: StorageElementType | PixiVNJsonValueGet): any {
if (value && typeof value === "object") {
if ("type" in value) {
if (value.storageOperationType === "get") {
return storage.getVariable((value as PixiVNJsonStorageGet).key)
if (value.type === "value" && value.storageOperationType === "get") {
switch (value.storageType) {
case "storage":
return storage.getVariable((value as PixiVNJsonStorageGet).key)
case "flagStorage":
return getFlag((value as PixiVNJsonStorageGet).key)
case "label":
return narration.getTimesLabelOpened((value as PixiVNJsonLabelGet).label)
}
}
}
}
Expand Down Expand Up @@ -160,7 +167,7 @@ function getUnionConditionResult(condition: PixiVNJsonUnionCondition): boolean {
return result
}

export function setStorageJson(value: PixiVNJsonStorageSet) {
export function setStorageJson(value: PixiVNJsonValueSet) {
if (value.storageType === "storage") {
storage.setVariable(value.key, getValue(value.value))
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/interface/PixiVNJson.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PixiVNJsonIfElse from "./PixiVNJsonIfElse"
import PixiVNJsonLabels from "./PixiVNJsonLabels"
import { PixiVNJsonStorageSet } from "./PixiVNJsonValue"
import { PixiVNJsonValueSet } from "./PixiVNJsonValue"

/**
* PixiVNJson It can be defined as a programming language to write a narrative written in json.
Expand All @@ -10,13 +10,13 @@ export default interface PixiVNJson {
* The initial variables are added to the system when this json is loaded.
* They will be set only if there are no variables with the same key already.
*/
initialVariables?: (PixiVNJsonStorageSet | PixiVNJsonIfElse<PixiVNJsonStorageSet>)[]
initialVariables?: (PixiVNJsonValueSet | PixiVNJsonIfElse<PixiVNJsonValueSet>)[]
/**
* The variables are added to the system when this json is loaded.
* if there are variables with the same key already, they will be overwritten.
* This solution corresponds to the **constants**.
*/
constants?: (PixiVNJsonStorageSet | PixiVNJsonIfElse<PixiVNJsonStorageSet>)[]
constants?: (PixiVNJsonValueSet | PixiVNJsonIfElse<PixiVNJsonValueSet>)[]
/**
* The labels to be used in the narrative. They will be added to the system
*/
Expand Down
4 changes: 2 additions & 2 deletions src/interface/PixiVNJsonOperations.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import PixiVNJsonIfElse from "./PixiVNJsonIfElse"
import { PixiVNJsonCanvas, PixiVNJsonSound } from "./PixiVNJsonMedia"
import { PixiVNJsonStorageSet } from "./PixiVNJsonValue"
import { PixiVNJsonValueSet } from "./PixiVNJsonValue"

export type PixiVNJsonOperation = PixiVNJsonStorageSet | PixiVNJsonCanvas | PixiVNJsonSound
export type PixiVNJsonOperation = PixiVNJsonValueSet | PixiVNJsonCanvas | PixiVNJsonSound

type PixiVNJsonOperations = (PixiVNJsonOperation | PixiVNJsonIfElse<PixiVNJsonOperation>)[]

Expand Down
6 changes: 3 additions & 3 deletions src/interface/PixiVNJsonValue.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getFlag } from "../functions"
import { StorageElementType } from "../types"

type PixiVNJsonStorageGet = {
export type PixiVNJsonStorageGet = {
type: "value"
storageOperationType: "get",
/**
Expand All @@ -15,7 +15,7 @@ type PixiVNJsonStorageGet = {
storageType: "storage" | "flagStorage",
}

type PixiVNJsonLabelGet = {
export type PixiVNJsonLabelGet = {
type: "value"
storageOperationType: "get",
/**
Expand Down Expand Up @@ -63,4 +63,4 @@ type PixiVNJsonFlagSet = {
storageType: "flagStorage",
}

export type PixiVNJsonStorageSet = (PixiVNJsonOnlyStorageSet | PixiVNJsonFlagSet)
export type PixiVNJsonValueSet = (PixiVNJsonOnlyStorageSet | PixiVNJsonFlagSet)
2 changes: 1 addition & 1 deletion src/interface/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type { PixiVNJsonCanvas, PixiVNJsonSound } from './PixiVNJsonMedia';
export type { PixiVNJsonOperation, default as PixiVNJsonOperations } from './PixiVNJsonOperations';
export type { default as PixiVNJsonStepSwitch } from './PixiVNJsonStepSwitch';
export type { default as PixiVNJsonUnionCondition } from './PixiVNJsonUnionCondition';
export type { PixiVNJsonValueGet as PixiVNJsonStorageGet, PixiVNJsonStorageSet } from './PixiVNJsonValue';
export type { PixiVNJsonLabelGet, PixiVNJsonStorageGet, PixiVNJsonValueGet, PixiVNJsonValueSet } from './PixiVNJsonValue';
export type { default as SoundOptions, SoundPlayOptions } from './SoundOptions';
export type { default as TickerHistory, TickerHistoryForExport } from './TickerHistory';
export type { TickerProgrationType } from './TickerProgrationType';
Expand Down

0 comments on commit 9fe1219

Please sign in to comment.