Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
dist/
node_modules/
node_modules/

# munger.py typescript file output
demo/typescript-embeddable.py
13 changes: 11 additions & 2 deletions munger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
dict.append(f"\"{row['id']}\":\"{text}\"")

output = ",".join(dict)
opener = "const stringTable: { [key: string]: string } = {";
opener = "export const stringTable: { [key: string]: string } = {";
ender = "};"

# create a TS file that exports expected values
tsCompiledOutput = open('typescript-embeddable.ts', 'w+')
tsCompiledOutput.write(f'{opener}{output}{ender}')
tsCompiledOutput.write('\n\n')
print(f'{opener}{output}{ender}')

hex = []
Expand All @@ -20,6 +25,10 @@
hex.append("0x" + byte.hex())

output = ",".join(hex)
opener = "const data = Uint8Array.from([";
opener = " export const data = Uint8Array.from([";
ender = "]);";
tsCompiledOutput.write(f'{opener}{output}{ender}')
print(f'{opener}{output}{ender}')

# close written typescript file
tsCompiledOutput.close()
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ If you wanted to replace the story you would need to do the following:

1. Using ysc compile your yarn into a yarnc and csv file: `ysc compile your_yarn.yarn`
2. Using `munger.py` create a TypeScript text embeddable version of your compiled story: `python munger.py`
3. Replace the `stringTable` and `data` variables inside `index.ts` with those created by `munger.py`
3. Replace the `stringTable` and `data` variables inside `index.ts` with those created by `munger.py`. This step can alternatively be skipped as the `munger.py` output is generated in a file `demo/typescript-embeddable.ts` which is imported into `src/index.ts` by default.
5. Compile the TypeScript and run webpack to munge everything up into a single js file we can use: `npm run build`
6. Open `index.html` in your browser and "enjoy"

Expand Down
18 changes: 17 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { YarnVM, OptionItem } from "./yarnvm";
import { Program } from "./yarn_spinner";

import { stringTable as mungedStringTable, data as mungedProgramData } from "../demo/typescript-embeddable";

import "./yarnspinner.scss";
import 'bootstrap';

import { Settings, LineDeliveryMode } from "./settings";
import { stringTable } from "./data";

let currentSettings: Settings = {
lineDelivery: LineDeliveryMode.OneAtATime,
Expand Down Expand Up @@ -211,9 +214,23 @@ declare global {
startDialogue: () => void;
setup: () => void;
addButton: (text: string, classes: string[], handler: () => void) => void;
yarnData: {programData: Uint8Array, stringTable: StringTable};
}
}

/**
* These values may either be replaced with the output value from munger.py
* or they will simply be imported from the `demo/typescript-embeddable.ts`
* file that munger.py generates.
*
* if replacing:
* `mungedProgramData` is replaced with "data" value from munger.py output
* `mungedStringTable` is replaced with "stringTable" value from munger.py
*/
window.yarnData = {
programData: mungedProgramData,
stringTable: mungedStringTable
}
window.loadProgram = loadProgram;
window.startDialogue = startDialogue;

Expand Down Expand Up @@ -312,7 +329,6 @@ function loadProgram(programData: Uint8Array, stringTable: StringTable): void {
}
}


function updateSettings(newSettings: Settings) {
currentSettings = { ...currentSettings, ...newSettings };
updateLineDeliveryUI();
Expand Down