Skip to content

Commit

Permalink
string command support
Browse files Browse the repository at this point in the history
  • Loading branch information
SiriusAshling committed Apr 16, 2022
1 parent 4b5851d commit d5ea41a
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
5 changes: 4 additions & 1 deletion src/description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
39 changes: 38 additions & 1 deletion src/item/sysCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export enum SysCommandVariant {
ifSelfGreater = 26,
ifSelfLess = 27,
unequip = 28,
saveString = 29,
appendString = 30,
}

interface Autosave {
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 25 additions & 0 deletions src/parser/parseItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
18 changes: 17 additions & 1 deletion syntaxes/ori-wotw-header.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@
{ "include": "#destroyWarp" },
{ "include": "#ifbounds" },
{ "include": "#ifself" },
{ "include": "#unequip" }
{ "include": "#unequip" },
{ "include": "#saveString" }
]
},
"autosave": {
Expand Down Expand Up @@ -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"
Expand All @@ -240,6 +251,7 @@
{ "include": "#messageXml" },
{ "include": "#messageUberStatePointer" },
{ "include": "#messageItemWriter" },
{ "include": "#messageStoredStrings" },
{ "include": "#WHEREIS" },
{ "include": "#HOWMANY" },
{ "include": "#messageColoring" },
Expand Down Expand Up @@ -280,6 +292,10 @@
{ "include": "#item" }
]
},
"messageStoredStrings": {
"match": "\\$\\{\\d+\\}",
"name": "string.regexp"
},
"WHEREIS": {
"begin": "\\$WHEREIS\\(",
"end": "$|(?=//)|\\)",
Expand Down

0 comments on commit d5ea41a

Please sign in to comment.