Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.3.0 #1077

Merged
merged 34 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f3268bb
Remove deprecated TSLint dev dependency
maetl Apr 5, 2024
2d96541
Upgrade build toolchain to TypeScript 5
maetl Apr 6, 2024
1aa62ee
Make enum type more explicit when used in numeric expressions
maetl Apr 6, 2024
5d94165
Explicitly reference the object static properties are declared on
maetl Apr 6, 2024
46a8d0b
Enable TypeScript to recognise when superclass methods are being called
maetl Apr 6, 2024
05a3af6
Can’t set value to `0` if zeroth index doesn’t exist in the enum type
maetl Apr 6, 2024
ec73f77
TypeScript seems to want this to be explicitly declared
maetl Apr 6, 2024
f72fcca
Replace legacy Jasmine dependency in tests with Jest builtin
maetl Apr 6, 2024
7e9a208
Rebuilding package-lock.json to attempt to fix NPM bug in build
maetl Apr 6, 2024
a8f2b5c
Move Lint workflow step to end of job
maetl Apr 6, 2024
59d1cd5
Remove vestiges of deprecated TSLint
maetl Apr 6, 2024
a632f78
Add .prettierrc.json to set `trailingComma: es5`
maetl Apr 6, 2024
799d61e
tentative fix
smwhr Jul 31, 2024
ab4e463
Merge branch 'master' into jz/better-typings
smwhr Jul 31, 2024
151ab8f
seems to be working with all projects
smwhr Jul 31, 2024
bdfb828
cleanup
smwhr Jul 31, 2024
bf18ad0
some changes
smwhr Aug 2, 2024
c010453
Merge branch 'upgrade/ts-5.0' into typescript-upgrade
smwhr Aug 2, 2024
1c055a7
Merge pull request #1053 from maetl/typescript-upgrade
smwhr Aug 2, 2024
926a6ab
Looks like everything is now working fine
smwhr Aug 2, 2024
ad9c183
auto lint fix
smwhr Aug 3, 2024
7eaacc9
link InkParser.ts
smwhr Aug 3, 2024
16c2fbd
update eslintrules + obvious mistakes
smwhr Aug 3, 2024
d5eeb00
Add Latin1Supplement and Chinese character ranges
smwhr Aug 3, 2024
644c0f3
Allow optional newline right after a choice name + test
smwhr Aug 3, 2024
c2e7f61
Fix for errors when attempting to load a new version of story during …
smwhr Aug 3, 2024
69ce680
Fix for choices that were storing thread references in a non-safe way…
smwhr Aug 3, 2024
bc15c80
Fix for errors when attempting to load a new version of story during …
smwhr Aug 3, 2024
90d7a41
Slight API improvements to Ink Lists
smwhr Aug 3, 2024
caa804e
Fix for choice tags not being serialised
smwhr Aug 3, 2024
8e8301d
Fix to allow variable observers to run new ink more robustly by havin…
smwhr Aug 3, 2024
c4ad34f
test file for newline_after_choice
smwhr Aug 3, 2024
e34b5dd
lint:fix
smwhr Aug 3, 2024
755d48c
update compat table
smwhr Aug 3, 2024
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 .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = {
},
plugins: [
"@typescript-eslint",
"@typescript-eslint/tslint",
"import",
"jsdoc",
"prefer-arrow",
Expand All @@ -27,17 +26,21 @@ module.exports = {
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/restrict-plus-operands": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/no-base-to-string": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/no-this-alias": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-unnecessary-type-assertion": "off",
"@typescript-eslint/no-redundant-type-constituents": "off",
"@typescript-eslint/no-unsafe-enum-comparison": "off",
"prefer-const": "off",
"prefer-spread": "off",
"prefer-rest-params": "off",
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
run: npm install
- name: Install codecov
run: npm install codecov
- name: Lint
run: npm run lint
- name: Build
run: npm run build
- name: tests
run: npm run test
- name: Lint
run: npm run lint
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/engine/
/compiler/
dist/
bin/
test/stories/
/tests/specs/
/ink.js
/ink.js.map

# Logs
logs
Expand Down
3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"trailingComma": "es5"
}
67 changes: 42 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,18 @@ You can find some boilerplate code for node.js [here](https://github.com/y-lohse

### Loading inkjs

Require the module: `var Story = require('inkjs').Story;`.
#### require

You can require the module:
```javascript
var Story = require('inkjs').Story;
```

#### import
You can use import style:
```javascript
import { Story } from 'inkjs';
`

### Loading a json file

Expand Down Expand Up @@ -135,45 +146,28 @@ var result = EvaluateFunction('my_ink_function', ['arg1', 'arg2'], true);
// result.output is the text that was written to the output while the function was evaluated
```

## Using TypeScript

As this library is a port from C#, it requires a less standard way to assign the `Story` class, including all other classes, to a variable:

```ts
import { Story } from 'inkjs';
import { Compiler } from 'inkjs/full'; // Compiler is not provided in the default inkjs package

let story: InstanceType<typeof Story>;
let compiler: InstanceType<typeof Compiler>;
```

Further, to minimize the verbose assignment, you can also create aliases in your project:

```ts
import { Story, Compiler } from 'inkjs/full'; // Story is also provided in the "full" subpackage.

export type InkStory = InstanceType<typeof Story>;
export type InkCompiler= InstanceType<typeof Compiler>;
```

## Compiler

### inkjs-compiler.js

```shell
$ node inkjs-compiler.js -h

Usage: inkjs-compiler <options> <ink file>
Usage: inkjs-compiler <options> <ink or json file>
-o <filename>: Output file name
-c: Count all visits to knots, stitches and weave points, not
just those referenced by TURNS_SINCE and read counts.
-p: Play mode
-p: Play mode (automatic if a json file is passed as argument)

```

If you install the package globally it is available as the `inkjs-compiler` command.
Alternatively, you can call it using `npx inkjs`

### online compiler

```javascript
const inkjs = require("inkjs/full") //the `full` submodule contains the Compiler
const story = new inkjs.Compiler(`Hello World`).Compile();
// story is an inkjs.Story that can be played right away

Expand All @@ -187,6 +181,28 @@ You can use this in combination with [Webpack and TypeScript](docs/working-with-

See [Differences with the C# Compiler](docs/compiler-differences.md).

## Using TypeScript

Inkjs is also packaged to be usable with typescript imports, the main classes (`Story`, `InkList`, `Compiler`) are available under the `/types`submodule.

```ts
import { Story, Compiler } from 'inkjs/types'; // shortcut

let story: Story;
let compiler: Compiler;
```

It is also possible to import deeply nested classes if needed

```ts
import { Story } from 'inkjs/engine/Story';
import { Compiler } from 'inkjs/compiler/Compiler';

import { Choice } from 'inkjs/engine/Choice'
import { Identifier } from 'inkjs/compiler/Parser/ParsedHierarchy/Identifier';

```

## Compatibility table

| _inklecate_ version | _inkjs_ version | _json_ version |
Expand All @@ -207,4 +223,5 @@ See [Differences with the C# Compiler](docs/compiler-differences.md).
| 0.8.3 | 1.10.0 – 1.10.5 | |
| 0.9.0 | 1.11.0 | 19 |
| 1.0.0 | 2.0.0 - 2.1.0 | 20 |
| 1.1.1 | 2.2.0 | 21 |
| 1.1.1 | 2.2.* | 21 |
| 1.2.0 | 2.3.0 | |
4 changes: 2 additions & 2 deletions docs/compiler-differences.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ Inkjs provides 2 file handlers :
* A POSIX file handler : delivered as a separate `inkjs-full-posixhandler.js` file that must be included/required : similar to the one used in the C# compiler that will look for files in folders. Example when installing the package from npm :

```javascript
var Inkjs = require('inkjs');
var inkjs = require('inkjs/full');
var { PosixFileHandler } = require('inkjs/compiler/FileHandler/PosixFileHandler');

const inkFile = fs.readFileSync(`${PATH_TO_STORY_FOLDER}/main.ink`, 'UTF-8').replace(/^\uFEFF/, '');
const fileHandler = new PosixFileHandler(`${PATH_TO_STORY_FOLDER}/`);
const errorHandler = (message, errorType) => {
console.log(message + "\n");
}
const story = new Inkjs.Compiler(inkFile, {fileHandler, errorHandler}).Compile();
const story = new inkjs.Compiler(inkFile, {fileHandler, errorHandler}).Compile();
//story.Continue()
```

Expand Down
6 changes: 3 additions & 3 deletions docs/working-with-typescript-and-webpack.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ rules: [

We can then `import` (or `require`) the ink file and compile it.

```typescript
import * as Inkjs from 'inkjs';
```javascript
import { Compiler } from 'inkjs/full';
import data from '../assets/myStory.ink';

const inkStory = new Inkjs.Compiler(data).Compile();
const inkStory = new Compiler(data).Compile();
```

If you are working in JavaScript, then that is all you need.
Expand Down
45 changes: 4 additions & 41 deletions ink.d.mts
Original file line number Diff line number Diff line change
@@ -1,41 +1,4 @@
import { Story, InkList } from './engine/Story'
import { Compiler } from './compiler/Compiler'
import { CompilerOptions } from './compiler/CompilerOptions'
import { PosixFileHandler } from './compiler/FileHandler/PosixFileHandler'
import { JsonFileHandler } from './compiler/FileHandler/JsonFileHandler'

declare interface Inkjs {
/**
* A Story is the core class that represents a complete Ink narrative, and
* manages runtime evaluation and state.
*/
Story: typeof Story

/**
* The underlying type for a list item in Ink.
*/
InkList: typeof InkList

/**
* Compiles Ink stories from source.
*/
Compiler: typeof Compiler

/**
* Metadata options for a compiler pass.
*/
CompilerOptions: typeof CompilerOptions

/**
* Resolves and loads Ink sources from a POSIX filesystem.
*/
PosixFileHandler: typeof PosixFileHandler

/**
* Resolves and loads Ink sources from a JSON hierarchy.
*/
JsonFileHandler: typeof JsonFileHandler
}

declare let inkjs: Inkjs
export default inkjs
export { Story, InkList } from "./engine/Story";
export { Compiler, CompilerOptions } from "./compiler/Compiler";
export { PosixFileHandler } from "./compiler/FileHandler/PosixFileHandler";
export { JsonFileHandler } from "./compiler/FileHandler/JsonFileHandler";
45 changes: 4 additions & 41 deletions ink.d.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,4 @@
import { Story, InkList } from './engine/Story'
import { Compiler } from './compiler/Compiler'
import { CompilerOptions } from './compiler/CompilerOptions'
import { PosixFileHandler } from './compiler/FileHandler/PosixFileHandler'
import { JsonFileHandler } from './compiler/FileHandler/JsonFileHandler'

declare interface Inkjs {
/**
* A Story is the core class that represents a complete Ink narrative, and
* manages runtime evaluation and state.
*/
Story: typeof Story

/**
* The underlying type for a list item in Ink.
*/
InkList: typeof InkList

/**
* Compiles Ink stories from source.
*/
Compiler: typeof Compiler

/**
* Metadata options for a compiler pass.
*/
CompilerOptions: typeof CompilerOptions

/**
* Resolves and loads Ink sources from a POSIX filesystem.
*/
PosixFileHandler: typeof PosixFileHandler

/**
* Resolves and loads Ink sources from a JSON hierarchy.
*/
JsonFileHandler: typeof JsonFileHandler
}

declare let inkjs: Inkjs
export default inkjs
export { Story, InkList } from "./engine/Story";
export { Compiler, CompilerOptions } from "./compiler/Compiler";
export { PosixFileHandler } from "./compiler/FileHandler/PosixFileHandler";
export { JsonFileHandler } from "./compiler/FileHandler/JsonFileHandler";
Loading