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
Expand Up @@ -10,14 +10,17 @@
# ---

/index.xhtml
/precache-manifest.*.js
/puzzlescript.js
/puzzlescript.js.map
/puzzlescript-webworker.js
/puzzlescript-webworker.js.map
/pwa-app.js
/pwa-app.js.map
/pwa-service-worker.js
/pwa-service-worker.js.map
/workbox-*.js
/workbox-*.js.map


/game-thumbnails/*.png
/game-thumbnails/*.svg
Expand Down
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.15.3
12.18.3
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sudo: false
language: node_js
node_js:
- "10.15"
- "12.18.3"

cache: yarn

Expand Down
128 changes: 67 additions & 61 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"compile": "npm run-script compile:grammar && npm run-script compile:thumbnail",
"precompile:thumbnail": "npm run-script compile:ts",
"compile:thumbnail": "node ./lib/cli/buildGameIcons.js",
"compile:grammar": "nearleyc --minify-rule-names ./src/parser/grammar.ne > ./src/parser/grammar.ts",
"compile:grammar": "nearleyc ./src/parser/grammar.ne > ./src/parser/grammar.ts",
"compile:ts": "tsc && cp ./src/sound/sfxr.js ./lib/sound/ && cp ./src/sound/sfxr-browser.js ./lib/sound/",
"ci": "npm run-script test",
"postci": "npm run-script docs && codecov",
Expand Down Expand Up @@ -42,69 +42,70 @@
"puzzlescript-demo": "./bin/puzzlescript-demo.js"
},
"dependencies": {
"@types/jest": "^24.0.17",
"ansi-escapes": "^4.0.0",
"ansi-styles": "^4.0.0",
"bitset": "^5.0.4",
"chalk": "^2.4.1",
"commander": "^3.0.0",
"eventemitter2": "^6.4.3",
"firstline": "^2.0.2",
"font-ascii": "^1.1.16",
"fs-extra": "^8.0.0",
"glob": "^7.1.3",
"inquirer": "7.0.0",
"inquirer-autocomplete-prompt": "^1.0.1",
"nearley": "github:philschatz/nearley#24685991e203fd6645a6f687198687aa42b7d6f2",
"pify": "^4.0.0",
"supports-color": "^7.0.0",
"update-notifier": "^3.0.1",
"web-audio-api": "^0.2.2"
"@types/fs-extra": ">=9",
"@types/jest": ">=24",
"ansi-escapes": ">=4",
"ansi-styles": ">=4",
"bitset": ">=5",
"chalk": ">=2",
"commander": ">=6",
"eventemitter2": ">=6",
"firstline": ">=2",
"font-ascii": ">=1",
"fs-extra": ">=8",
"glob": ">=7",
"inquirer": ">=7",
"inquirer-autocomplete-prompt": ">=1",
"nearley": ">=2",
"pify": ">=4",
"supports-color": ">=7",
"update-notifier": ">=3",
"web-audio-api": ">=0.2"
},
"devDependencies": {
"@babel/core": "^7.0.0-0",
"@babel/preset-env": "^7.2.0",
"@babel/preset-typescript": "^7.1.0",
"@types/ansi-escapes": "^4.0.0",
"@types/ansi-styles": "^3.2.1",
"@types/glob": "^7.1.1",
"@types/inquirer": "6.0.2",
"@types/nearley": "^2.11.0",
"@types/pify": "^3.0.2",
"@types/puppeteer": "^1.11.1",
"@types/supports-color": "^5.3.0",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"babel-loader": "^8.0.4",
"babel-polyfill": "^6.26.0",
"codecov": "^3.1.0",
"dialog-polyfill": "^0.5.0",
"html-webpack-plugin": "^3.2.0",
"javascript-time-ago": "^2.0.1",
"jest": "^23.6.0",
"jest-puppeteer": "^4.0.0",
"lighthouse": "^5.0.0",
"mkdirp": "^0.5.1",
"node-fetch": "^2.3.0",
"nyc": "^15.1.0",
"process-nextick-args": "^2.0.0",
"puppeteer": "^1.11.0",
"remap-istanbul": "^0.13.0",
"script-ext-html-webpack-plugin": "^2.1.3",
"serve": "^11.1.0",
"source-map-support": "^0.5.9",
"@babel/core": ">=7",
"@babel/polyfill": ">=7",
"@babel/plugin-transform-runtime": ">=7",
"@babel/preset-env": ">=7",
"@babel/preset-typescript": ">=7",
"@types/ansi-escapes": ">=4",
"@types/ansi-styles": ">=3",
"@types/glob": ">=7",
"@types/inquirer": ">=6",
"@types/nearley": ">=2",
"@types/pify": ">=3",
"@types/puppeteer": ">=1",
"@types/supports-color": ">=5",
"babel-jest": ">=26",
"babel-loader": ">=8",
"codecov": ">=3",
"dialog-polyfill": ">=0.5",
"html-webpack-plugin": ">=3",
"javascript-time-ago": ">=2",
"jest": ">=23",
"jest-puppeteer": ">=4",
"lighthouse": "5",
"mkdirp": ">=0.5",
"node-fetch": ">=2",
"nyc": ">=15",
"process-nextick-args": ">=2",
"puppeteer": ">=1",
"remap-istanbul": ">=0.13",
"script-ext-html-webpack-plugin": ">=2",
"serve": ">=11",
"source-map-support": ">=0.5",
"sourcemapped-stacktrace-node": "github:philschatz/sourcemapped-stacktrace-node#2a76787b5f9356b3798788942947e05a5bc8ecc2",
"svg-to-png": "^4.0.0",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.17.0",
"tslint-config-standard": "^9.0.0",
"typedoc": "^0.14.0",
"typescript": "^3.2.2",
"util-deprecate": "^1.0.2",
"weak": "^1.0.1",
"webpack": "^4.39.2",
"webpack-cli": "^3.1.2",
"workbox-webpack-plugin": "^4.3.1"
"svg-to-png": ">=4",
"tslint": ">=5",
"tslint-config-prettier": ">=1",
"tslint-config-standard": ">=9",
"typedoc": ">=0.14",
"typescript": ">=3",
"util-deprecate": ">=1",
"weak-napi": ">=2",
"webpack": ">=4",
"webpack-cli": ">=3",
"workbox-webpack-plugin": ">=4"
},
"optionalDependencies": {
"speaker": "github:philschatz/node-speaker#cac7c5b7c434b52619bfbbd9530ab0871156e815"
Expand All @@ -127,6 +128,11 @@
"testRegex": "(\\.|/)?spec\\.tsx?$"
},
"babel": {
"plugins": [
["@babel/transform-runtime", {
"regenerator": true
}]
],
"presets": [
"@babel/preset-env",
"@babel/preset-typescript"
Expand Down
2 changes: 1 addition & 1 deletion src/browser/InputWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class InputWatcher {
private readonly table: HTMLTableElement
private readonly controls: Control<{button: IButton, lastPressed: Optional<number>}>
private readonly stickControls: StickControl<{stick: IStick, lastPressed: Optional<number>}>
private readonly controlCheckers: Array<() => void>
private readonly controlCheckers: (() => void)[]
private readonly boundKeys: IKeyboardButton[]
private polledInput: Optional<INPUT_BUTTON>
private repeatIntervalInSeconds: Optional<number>
Expand Down
2 changes: 1 addition & 1 deletion src/browser/WebworkerTableEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export default class WebworkerTableEngine implements Engineish {
console.log(`BUG: Unhandled Event occurred. Ignoring "${data.type}"`, data) // tslint:disable-line:no-console
}
}
private convertToA11yMessages(a11yMessages: Array<A11Y_MESSAGE<CellishJson, string>>): Array<A11Y_MESSAGE<Cellish, GameSprite>> {
private convertToA11yMessages(a11yMessages: A11Y_MESSAGE<CellishJson, string>[]): A11Y_MESSAGE<Cellish, GameSprite>[] {
return a11yMessages.map((message) => {
switch (message.type) {
case A11Y_MESSAGE_TYPE.ADD:
Expand Down
1 change: 1 addition & 0 deletions src/browser/lighthouse.browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const checkLighthouse = async(urlPath: string) => {
writeFileSync(join(coveragePath, 'lighthouse-report.html'), html, { encoding: 'utf-8' })
}

expect(lhr.categories.seo.score).not.toBeNull() // The audit failed. Maybe XHTML parsing problem?
expect(lhr.categories.accessibility.score).toBeGreaterThanOrEqual(1)
expect(lhr.categories.seo.score).toBeGreaterThanOrEqual(1)
expect(lhr.categories.pwa.score).toBeGreaterThanOrEqual(0.73) // since it is not https
Expand Down
2 changes: 1 addition & 1 deletion src/browser/play.browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ describe('Browser', () => {
return -1
}
})
return ret as number
return ret
}

// The game shows a dialog immediately (uggh)
Expand Down
13 changes: 5 additions & 8 deletions src/cli/playGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum CLI_SPRITE_SIZE {
SMALL = 'small'
}
interface IGameInfo { id: string, title: string, filePath: string }
interface ISaveFile { version: number, solutions: Array<{ solution?: string, partial?: string, snapshot?: {tickNum: number, cellState: string[][][]} }> }
interface ISaveFile { version: number, solutions: { solution?: string, partial?: string, snapshot?: {tickNum: number, cellState: string[][][]} }[] }
interface ICliOptions {
version: string,
ui: boolean,
Expand Down Expand Up @@ -66,23 +66,20 @@ async function sleep(ms: number) {

function first2Lines(filePath: string) {

const opts = {
encoding: 'utf8',
lineEnding: '\n'
}
const lineEnding = '\n'
return new Promise<string>((resolve, reject) => {
const rs = createReadStream(filePath, { encoding: opts.encoding })
const rs = createReadStream(filePath, { encoding: 'utf8' })
let acc = ''
let pos = 0
let index
rs
.on('data', (chunk: string) => {
index = chunk.indexOf(opts.lineEnding)
index = chunk.indexOf(lineEnding)
acc += chunk
if (index === -1) {
pos += chunk.length
} else {
index = chunk.indexOf(opts.lineEnding, index + 1)
index = chunk.indexOf(lineEnding, index + 1)
if (index >= 0) {
pos += index
rs.close()
Expand Down
16 changes: 8 additions & 8 deletions src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface ITickResult {
wasAgainTick: boolean,
}

type Snapshot = Array<Array<Set<GameSprite>>>
type Snapshot = Set<GameSprite>[][]

class ArrayAndMap<K, V> {
private readonly comparator: Comparator<K>
Expand Down Expand Up @@ -326,8 +326,8 @@ export class Cell implements Cellish {

export class Level {
private cells: Optional<Cell[][]>
private rowCache: Array<Optional<SpriteBitSet>>
private colCache: Array<Optional<SpriteBitSet>>
private rowCache: Optional<SpriteBitSet>[]
private colCache: Optional<SpriteBitSet>[]
constructor() {
this.rowCache = []
this.colCache = []
Expand Down Expand Up @@ -458,7 +458,7 @@ export class LevelEngine extends EventEmitter2 {
}
}

public setMessageLevel(sprites: Array<Array<Set<GameSprite>>>) {
public setMessageLevel(sprites: Set<GameSprite>[][]) {
this.tempOldLevel = this.currentLevel
this._setLevel(sprites)
}
Expand Down Expand Up @@ -594,7 +594,7 @@ export class LevelEngine extends EventEmitter2 {

public /*only for unit tests*/ tickMoveSprites(changedCells: Set<Cell>) {
const movedCells: Set<Cell> = new Set()
const a11yMessages: Array<A11Y_MESSAGE<Cell, GameSprite>> = []
const a11yMessages: A11Y_MESSAGE<Cell, GameSprite>[] = []
// Loop over all the cells, see if a Rule matches, apply the transition, and notify that cells changed
let somethingChanged
do {
Expand Down Expand Up @@ -681,7 +681,7 @@ export class LevelEngine extends EventEmitter2 {
}
}

private _setLevel(levelSprites: Array<Array<Set<GameSprite>>>) {
private _setLevel(levelSprites: Set<GameSprite>[][]) {
const level = new Level()
this.currentLevel = level
const spriteCells = levelSprites.map((row, rowIndex) => {
Expand Down Expand Up @@ -757,7 +757,7 @@ export class LevelEngine extends EventEmitter2 {

private _tickUpdateCells(rules: Iterable<SimpleRuleGroup>) {
const changedMutations: Set<IMutation> = new Set()
const a11yMessages: Array<A11Y_MESSAGE<Cell, GameSprite>> = []
const a11yMessages: A11Y_MESSAGE<Cell, GameSprite>[] = []
const evaluatedRules: SimpleRuleGroup[] = []
if (!this.currentLevel) {
throw new Error(`BUG: Level Cells do not exist yet`)
Expand Down Expand Up @@ -859,7 +859,7 @@ export class LevelEngine extends EventEmitter2 {
}
}

private getRealA11yMessages(changedCells: Set<Cell>, a11yMessages: Array<A11Y_MESSAGE<Cell, GameSprite>>) {
private getRealA11yMessages(changedCells: Set<Cell>, a11yMessages: A11Y_MESSAGE<Cell, GameSprite>[]) {
return a11yMessages.filter((m) => {
switch (m.type) {
case A11Y_MESSAGE_TYPE.ADD:
Expand Down
2 changes: 1 addition & 1 deletion src/index-browser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'babel-polyfill' // tslint:disable-line:no-implicit-dependencies
import '@babel/polyfill' // tslint:disable-line:no-implicit-dependencies
import SyncTableEngine from './browser/SyncTableEngine'
import WebworkerTableEngine from './browser/WebworkerTableEngine'
import { closeSounds } from './sounds'
Expand Down
4 changes: 2 additions & 2 deletions src/index-webworker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'babel-polyfill' // tslint:disable-line:no-implicit-dependencies
import '@babel/polyfill' // tslint:disable-line:no-implicit-dependencies
import { Cell, CellSaveState, GameEngine } from './engine'
import { GameData } from './models/game'
import { A11Y_MESSAGE, A11Y_MESSAGE_TYPE } from './models/rule'
Expand Down Expand Up @@ -111,7 +111,7 @@ class Handler implements GameEngineHandler {
public async onSound(sound: Soundish) {
postMessage({ type: MESSAGE_TYPE.ON_SOUND, soundCode: sound.soundCode })
}
public onTick(changedCells: Set<Cellish>, checkpoint: Optional<CellSaveState>, hasAgain: boolean, a11yMessages: Array<A11Y_MESSAGE<Cell, GameSprite>>) {
public onTick(changedCells: Set<Cellish>, checkpoint: Optional<CellSaveState>, hasAgain: boolean, a11yMessages: A11Y_MESSAGE<Cell, GameSprite>[]) {
postMessage({ type: MESSAGE_TYPE.ON_TICK, changedCells: toCellsJson(changedCells), checkpoint, hasAgain, a11yMessages: a11yMessages.map(toA11yMessageJson) })
}
public onPause() {
Expand Down
8 changes: 4 additions & 4 deletions src/models/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export class GameData {
public readonly metadata: GameMetadata
public readonly objects: GameSprite[]
public readonly legends: IGameTile[]
public readonly sounds: Array<SoundItem<IGameTile>>
public readonly sounds: SoundItem<IGameTile>[]
public readonly collisionLayers: CollisionLayer[]
public readonly rules: SimpleRuleGroup[]
public readonly winConditions: WinConditionSimple[]
public readonly levels: Array<Level<IGameTile>>
public readonly levels: Level<IGameTile>[]
private readonly cacheSpriteSize: {spriteHeight: number, spriteWidth: number}
private cachedBackgroundSprite: Optional<GameSprite>
private readonly letterSprites: Map<string, GameSprite>
Expand All @@ -37,11 +37,11 @@ export class GameData {
metadata: GameMetadata,
objects: GameSprite[],
legends: IGameTile[],
sounds: Array<SoundItem<IGameTile>>,
sounds: SoundItem<IGameTile>[],
collisionLayers: CollisionLayer[],
rules: SimpleRuleGroup[],
winConditions: WinConditionSimple[],
levels: Array<Level<IGameTile>>
levels: Level<IGameTile>[]
) {
this.title = title
this.metadata = metadata
Expand Down
Loading