From d5ea41ab5eadbc5debec5fc75be25623e373b4b5 Mon Sep 17 00:00:00 2001 From: SiriusAshling <53594055+SiriusAshling@users.noreply.github.com> Date: Sat, 16 Apr 2022 13:18:29 +0200 Subject: [PATCH] string command support --- package.json | 2 +- src/description.ts | 5 ++- src/item/sysCommand.ts | 39 +++++++++++++++++++++++- src/parser/parseItem.ts | 25 +++++++++++++++ syntaxes/ori-wotw-header.tmLanguage.json | 18 ++++++++++- 5 files changed, 85 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index ecc1a97..cb74865 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "header-language", "displayName": "Ori WotW Header Language", "description": "Support for the .wotwrh language", - "version": "0.4.3", + "version": "0.4.4", "publisher": "orirando", "license": "MIT", "repository": { diff --git a/src/description.ts b/src/description.ts index 06aae21..a8a1bc7 100644 --- a/src/description.ts +++ b/src/description.ts @@ -118,7 +118,10 @@ function describeSysCommand(command: SysSubcommand): string { } case SysCommandVariant.ifSelfLess: { const itemDescription = describeItem(command.item); return `Grant this item if the location's value is less than ${command.value}:\n\n${itemDescription}`; - } + } case SysCommandVariant.saveString: + return `Stores the string "${command.string}" under the identifier ${command.stringId}`; + case SysCommandVariant.appendString: + return `Appends the string "${command.string}" to the current value stored under the identifier ${command.stringId}`; } } function describeIcon(icon: Icon): string { diff --git a/src/item/sysCommand.ts b/src/item/sysCommand.ts index 5448ece..7c2cf98 100644 --- a/src/item/sysCommand.ts +++ b/src/item/sysCommand.ts @@ -27,6 +27,8 @@ export enum SysCommandVariant { ifSelfGreater = 26, ifSelfLess = 27, unequip = 28, + saveString = 29, + appendString = 30, } interface Autosave { @@ -139,7 +141,42 @@ interface Unequip { id: SysCommandVariant.unequip, equipment: EquipmentVariants, } -export type SysSubcommand = Autosave | SetResource | Checkpoint | KwolokStatue | Warp | Applier | SetHealth | SetEnergy | SetSpiritLight | Equip | TriggerBind | IfEqual | IfGreater | IfLess | DisableSync | EnableSync | CreateWarpIcon | DestroyWarpIcon | IfBounds | IfSelfEqual | IfSelfGreater | IfSelfLess | Unequip; +interface SaveString { + id: SysCommandVariant.saveString, + stringId: number, + string: string, +} +interface AppendString { + id: SysCommandVariant.appendString, + stringId: number, + string: string, +} +export type SysSubcommand = +Autosave +| SetResource +| Checkpoint +| KwolokStatue +| Warp +| Applier +| SetHealth +| SetEnergy +| SetSpiritLight +| Equip +| TriggerBind +| IfEqual +| IfGreater +| IfLess +| DisableSync +| EnableSync +| CreateWarpIcon +| DestroyWarpIcon +| IfBounds +| IfSelfEqual +| IfSelfGreater +| IfSelfLess +| Unequip +| SaveString +| AppendString; export interface SysCommand { id: ItemVariant.sysCommand, diff --git a/src/parser/parseItem.ts b/src/parser/parseItem.ts index ee40fee..fc04168 100644 --- a/src/parser/parseItem.ts +++ b/src/parser/parseItem.ts @@ -363,6 +363,29 @@ function parseIfSelfGreater(status: ParseStatus): ParseCommandSuccess | ParseFai function parseIfSelfLess(status: ParseStatus): ParseCommandSuccess | ParseFailure { return parseIfSelf(status, SysCommandVariant.ifSelfLess); } +function parseStringCommand(status: ParseStatus, id: SysCommandVariant.saveString | SysCommandVariant.appendString): ParseCommandSuccess | ParseFailure { + const stringId = parseInteger(status); + if (stringId === null) { return fail(Token.integer, status, undefined); } + + if (!eat(status, "|")) { return fail("|", status, undefined); } + + const string = parseRemainingLine(status); + if (string === null) { return fail(Token.text, status, undefined); } + + const command: SysSubcommand = { + id, + stringId, + string, + }; + + return succeed(command); +} +function parseSaveString(status: ParseStatus) { + return parseStringCommand(status, SysCommandVariant.saveString); +} +function parseAppendString(status: ParseStatus) { + return parseStringCommand(status, SysCommandVariant.appendString); +} function parseSubcommand(status: ParseStatus, commandId: number): ParseCommandSuccess | ParseFailure { switch (commandId) { case SysCommandVariant.setResource: return parseSetResource(status); @@ -386,6 +409,8 @@ function parseSubcommand(status: ParseStatus, commandId: number): ParseCommandSu case SysCommandVariant.ifSelfGreater: return parseIfSelfGreater(status); case SysCommandVariant.ifSelfLess: return parseIfSelfLess(status); case SysCommandVariant.unequip: return parseUnequip(status); + case SysCommandVariant.saveString: return parseSaveString(status); + case SysCommandVariant.appendString: return parseAppendString(status); default: const errorStatus = status.clone(); errorStatus.offset -= 2; diff --git a/syntaxes/ori-wotw-header.tmLanguage.json b/syntaxes/ori-wotw-header.tmLanguage.json index 356d920..13f495e 100644 --- a/syntaxes/ori-wotw-header.tmLanguage.json +++ b/syntaxes/ori-wotw-header.tmLanguage.json @@ -103,7 +103,8 @@ { "include": "#destroyWarp" }, { "include": "#ifbounds" }, { "include": "#ifself" }, - { "include": "#unequip" } + { "include": "#unequip" }, + { "include": "#saveString" } ] }, "autosave": { @@ -219,6 +220,16 @@ "match": "\\G4\\|28\\|(?:100[0-5]|20[01]\\d|300[0-5]|400\\d)\\b", "name": "variable.other.enummember" }, + "saveString": { + "begin": "\\G4\\|(?:29|30)\\|\\d+\\|", + "end": "$|(?=//)", + "beginCaptures": { + "0": { "name": "variable.other.enummember" } + }, + "patterns": [ + { "include": "#messageString" } + ] + }, "teleporter": { "match": "\\G5\\|-?(?:\\d|1[0-7])\\b", "name": "variable.other.enummember" @@ -240,6 +251,7 @@ { "include": "#messageXml" }, { "include": "#messageUberStatePointer" }, { "include": "#messageItemWriter" }, + { "include": "#messageStoredStrings" }, { "include": "#WHEREIS" }, { "include": "#HOWMANY" }, { "include": "#messageColoring" }, @@ -280,6 +292,10 @@ { "include": "#item" } ] }, + "messageStoredStrings": { + "match": "\\$\\{\\d+\\}", + "name": "string.regexp" + }, "WHEREIS": { "begin": "\\$WHEREIS\\(", "end": "$|(?=//)|\\)",