Skip to content

Commit

Permalink
Merge pull request #54 from vinceau/next
Browse files Browse the repository at this point in the history
3.1.0
  • Loading branch information
vinceau authored Dec 10, 2020
2 parents 62debf0 + 9790752 commit 15611d3
Show file tree
Hide file tree
Showing 20 changed files with 88 additions and 260 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@vinceau/slp-realtime",
"description": "Realtime slp parsing",
"license": "MIT",
"version": "3.0.4",
"version": "3.1.0",
"repository": "vinceau/slp-realtime",
"engines": {
"node": ">=10"
Expand All @@ -27,7 +27,6 @@
"minor": "npm version minor && npm publish",
"major": "npm version major && npm publish",
"prepublishOnly": "yarn run lint && yarn run test && yarn run build",
"postpublish": "git push origin master --follow-tags",
"docs": "yarn typedoc --excludePrivate --excludeNotExported --exclude \"**/*+(.spec).ts\"",
"postdocs": "touch docs/.nojekyll"
},
Expand All @@ -37,7 +36,7 @@
"realtime"
],
"dependencies": {
"@slippi/slippi-js": "^5.0.5",
"@slippi/slippi-js": "^5.1.1",
"chokidar": "^3.3.1",
"fs-extra": "^8.1.0",
"lodash": "^4.17.19",
Expand Down
5 changes: 0 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { SlpRealTime } from "./realtime";

export * from "./manager";
export * from "./operators";
export * from "./realtime";
export * from "./stream";
export * from "./utils";

export * from "./types";

export default SlpRealTime;
8 changes: 1 addition & 7 deletions src/stream/rxSlpStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
GameEndType,
SlpFileWriter,
SlpFileWriterOptions,
SlpStreamSettings,
} from "@slippi/slippi-js";
import { Subject, fromEvent } from "rxjs";
import { share } from "rxjs/operators";
Expand Down Expand Up @@ -41,17 +40,12 @@ export class RxSlpStream extends SlpFileWriter {
* @param {WritableOptions} [opts]
* @memberof SlpStream
*/
public constructor(
options?: Partial<SlpFileWriterOptions>,
slpOptions?: Partial<SlpStreamSettings>,
opts?: WritableOptions,
) {
public constructor(options?: Partial<SlpFileWriterOptions>, opts?: WritableOptions) {
super(
{
...options,
outputFiles: options && options.outputFiles === true, // Don't write out files unless manually specified
},
slpOptions,
opts,
);

Expand Down
10 changes: 3 additions & 7 deletions src/stream/slpFolderStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from "path";
import chokidar from "chokidar";
import tailstream, { TailStream } from "tailstream";
import { RxSlpStream } from "./rxSlpStream";
import { SlpFileWriterOptions, SlpStreamSettings, SlpStreamMode } from "@slippi/slippi-js";
import { SlpFileWriterOptions, SlpStreamMode } from "@slippi/slippi-js";
import { WritableOptions } from "stream";
import { Subject, fromEvent, BehaviorSubject } from "rxjs";
import { map, switchMap, share, takeUntil } from "rxjs/operators";
Expand All @@ -30,12 +30,8 @@ export class SlpFolderStream extends RxSlpStream {
private newFile$ = new BehaviorSubject<string | null>(null);
private readStream: TailStream | null = null;

public constructor(
options?: Partial<SlpFileWriterOptions>,
slpOptions?: Partial<SlpStreamSettings>,
opts?: WritableOptions,
) {
super(options, { ...slpOptions, mode: SlpStreamMode.MANUAL }, opts);
public constructor(options?: Partial<SlpFileWriterOptions>, opts?: WritableOptions) {
super({ ...options, mode: SlpStreamMode.MANUAL }, opts);
this._setupSubjects();
}

Expand Down
15 changes: 10 additions & 5 deletions src/stream/slpLiveStream.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { RxSlpStream } from "./rxSlpStream";
import { ConsoleConnection, ConnectionStatus, ConnectionEvent } from "@slippi/slippi-js";
import { Connection, ConsoleConnection, DolphinConnection, ConnectionStatus, ConnectionEvent } from "@slippi/slippi-js";

// Re-export these for ease-of-use
export { ConsoleConnection, ConnectionStatus } from "@slippi/slippi-js";
export { ConnectionEvent, ConsoleConnection, ConnectionStatus } from "@slippi/slippi-js";

const SLIPPI_CONNECTION_TIMEOUT_MS = 5000;

Expand All @@ -20,10 +20,15 @@ export class SlpLiveStream extends RxSlpStream {
*
* @memberof SlpLiveStream
*/
public connection = new ConsoleConnection();
public connection: Connection;

constructor() {
constructor(connectionType?: "dolphin" | "console") {
super();
if (connectionType === "dolphin") {
this.connection = new DolphinConnection();
} else {
this.connection = new ConsoleConnection();
}
this.connection.on(ConnectionEvent.HANDSHAKE, (data) => {
this.updateSettings({ consoleNickname: data.consoleNickname });
});
Expand Down Expand Up @@ -64,7 +69,7 @@ export class SlpLiveStream extends RxSlpStream {

try {
// Actually try to connect
this.connection.connect(address, port, SLIPPI_CONNECTION_TIMEOUT_MS);
this.connection.connect(address, port);
} catch (err) {
reject(err);
}
Expand Down
4 changes: 4 additions & 0 deletions src/utils/dolphin/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const defaultDolphinLauncherOptions = {
meleeIsoPath: "", // Path to Melee iso
batch: false, // Quit Dolphin when playback queue ends
disableSeekBar: false, // Disable the Dolphin seek bar
readEvents: true, // Track the Dolphin playback events over stdout
startBuffer: 1, // Sometimes Dolphin misses the start frame so start from the following frame
endBuffer: 1, // Match the start frame because why not
};
Expand Down Expand Up @@ -62,6 +63,9 @@ export class DolphinLauncher {
if (this.options.meleeIsoPath) {
params.push("-e", this.options.meleeIsoPath);
}
if (this.options.readEvents) {
params.push("-co");
}
if (this.options.batch) {
params.push("-b");
}
Expand Down
33 changes: 4 additions & 29 deletions src/utils/melee/characters.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,8 @@
export type CharacterColor = string;
import { Character } from "@slippi/slippi-js";

export enum Character {
CAPTAIN_FALCON = 0,
DONKEY_KONG = 1,
FOX = 2,
GAME_AND_WATCH = 3,
KIRBY = 4,
BOWSER = 5,
LINK = 6,
LUIGI = 7,
MARIO = 8,
MARTH = 9,
MEWTWO = 10,
NESS = 11,
PEACH = 12,
PIKACHU = 13,
ICE_CLIMBERS = 14,
JIGGLYPUFF = 15,
SAMUS = 16,
YOSHI = 17,
ZELDA = 18,
SHEIK = 19,
FALCO = 20,
YOUNG_LINK = 21,
DR_MARIO = 22,
ROY = 23,
PICHU = 24,
GANONDORF = 25,
}
export { Character } from "@slippi/slippi-js";

export type CharacterColor = string;

export interface CharacterInfo {
id: number;
Expand Down
177 changes: 16 additions & 161 deletions src/utils/melee/stages.ts
Original file line number Diff line number Diff line change
@@ -1,176 +1,31 @@
export enum Stage {
FOUNTAIN_OF_DREAMS = 2,
POKEMON_STADIUM = 3,
PEACHS_CASTLE = 4,
KONGO_JUNGLE = 5,
BRINSTAR = 6,
CORNERIA = 7,
YOSHIS_STORY = 8,
ONETT = 9,
MUTE_CITY = 10,
RAINBOW_CRUISE = 11,
JUNGLE_JAPES = 12,
GREAT_BAY = 13,
HYRULE_TEMPLE = 14,
BRINSTAR_DEPTHS = 15,
YOSHIS_ISLAND = 16,
GREEN_GREENS = 17,
FOURSIDE = 18,
MUSHROOM_KINGDOM = 19,
MUSHROOM_KINGDOM_2 = 20,
VENOM = 22,
POKE_FLOATS = 23,
BIG_BLUE = 24,
ICICLE_MOUNTAIN = 25,
ICETOP = 26,
FLAT_ZONE = 27,
DREAMLAND = 28,
YOSHIS_ISLAND_N64 = 29,
KONGO_JUNGLE_N64 = 30,
BATTLEFIELD = 31,
FINAL_DESTINATION = 32,
}
import { Stage, stages as stageUtils } from "@slippi/slippi-js";

export { Stage } from "@slippi/slippi-js";

export interface StageInfo {
id: Stage;
name: string;
shortName?: string;
}

const stagesMap = new Map<Stage, StageInfo>()
.set(Stage.FOUNTAIN_OF_DREAMS, {
id: Stage.FOUNTAIN_OF_DREAMS,
name: "Fountain of Dreams",
shortName: "FoD",
})
.set(Stage.POKEMON_STADIUM, {
id: Stage.POKEMON_STADIUM,
name: "Pokémon Stadium",
shortName: "PS",
})
.set(Stage.PEACHS_CASTLE, {
id: Stage.PEACHS_CASTLE,
name: "Princess Peach's Castle",
})
.set(Stage.KONGO_JUNGLE, {
id: Stage.KONGO_JUNGLE,
name: "Kongo Jungle",
})
.set(Stage.BRINSTAR, {
id: Stage.BRINSTAR,
name: "Brinstar",
})
.set(Stage.CORNERIA, {
id: Stage.CORNERIA,
name: "Corneria",
})
.set(Stage.YOSHIS_STORY, {
id: Stage.YOSHIS_STORY,
name: "Yoshi's Story",
shortName: "YS",
})
.set(Stage.ONETT, {
id: Stage.ONETT,
name: "Onett",
})
.set(Stage.MUTE_CITY, {
id: Stage.MUTE_CITY,
name: "Mute City",
})
.set(Stage.RAINBOW_CRUISE, {
id: Stage.RAINBOW_CRUISE,
name: "Rainbow Cruise",
})
.set(Stage.JUNGLE_JAPES, {
id: Stage.JUNGLE_JAPES,
name: "Jungle Japes",
})
.set(Stage.GREAT_BAY, {
id: Stage.GREAT_BAY,
name: "Great Bay",
})
.set(Stage.HYRULE_TEMPLE, {
id: Stage.HYRULE_TEMPLE,
name: "Hyrule Temple",
})
.set(Stage.BRINSTAR_DEPTHS, {
id: Stage.BRINSTAR_DEPTHS,
name: "Brinstar Depths",
})
.set(Stage.YOSHIS_ISLAND, {
id: Stage.YOSHIS_ISLAND,
name: "Yoshi's Island",
})
.set(Stage.GREEN_GREENS, {
id: Stage.GREEN_GREENS,
name: "Green Greens",
})
.set(Stage.FOURSIDE, {
id: Stage.FOURSIDE,
name: "Fourside",
})
.set(Stage.MUSHROOM_KINGDOM, {
id: Stage.MUSHROOM_KINGDOM,
name: "Mushroom Kingdom I",
})
.set(Stage.MUSHROOM_KINGDOM_2, {
id: Stage.MUSHROOM_KINGDOM_2,
name: "Mushroom Kingdom II",
})
.set(Stage.VENOM, {
id: Stage.VENOM,
name: "Venom",
})
.set(Stage.POKE_FLOATS, {
id: Stage.POKE_FLOATS,
name: "Poké Floats",
})
.set(Stage.BIG_BLUE, {
id: Stage.BIG_BLUE,
name: "Big Blue",
})
.set(Stage.ICICLE_MOUNTAIN, {
id: Stage.ICICLE_MOUNTAIN,
name: "Icicle Mountain",
})
.set(Stage.ICETOP, {
id: Stage.ICETOP,
name: "Icetop",
})
.set(Stage.FLAT_ZONE, {
id: Stage.FLAT_ZONE,
name: "Flat Zone",
})
.set(Stage.DREAMLAND, {
id: Stage.DREAMLAND,
name: "Dream Land N64",
shortName: "DL",
})
.set(Stage.YOSHIS_ISLAND_N64, {
id: Stage.YOSHIS_ISLAND_N64,
name: "Yoshi's Island N64",
})
.set(Stage.KONGO_JUNGLE_N64, {
id: Stage.KONGO_JUNGLE_N64,
name: "Kongo Jungle N64",
})
.set(Stage.BATTLEFIELD, {
id: Stage.BATTLEFIELD,
name: "Battlefield",
shortName: "BF",
})
.set(Stage.FINAL_DESTINATION, {
id: Stage.FINAL_DESTINATION,
name: "Final Destination",
shortName: "FD",
});
const shortNames = new Map<Stage, string>()
.set(Stage.FOUNTAIN_OF_DREAMS, "FoD")
.set(Stage.POKEMON_STADIUM, "PS")
.set(Stage.YOSHIS_STORY, "YS")
.set(Stage.DREAMLAND, "DL")
.set(Stage.BATTLEFIELD, "BF")
.set(Stage.FINAL_DESTINATION, "FD");

export function getStageInfo(stageId: number): StageInfo {
const s = stagesMap.get(stageId);
const s = stageUtils.getStageInfo(stageId);
if (!s) {
throw new Error(`Invalid stage with id ${stageId}`);
}
return s;
const shortName = shortNames.get(stageId);
return {
...s,
shortName,
};
}

export function getStageName(stageId: number): string {
Expand Down
4 changes: 2 additions & 2 deletions test/buttonPress.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sinon from "sinon";

import { pipeFileContents, SlpRealTime, RxSlpStream, ComboFilter, throttleInputButtons } from "../src";
import { pipeFileContents, SlpRealTime, RxSlpStream, ComboFilter, throttleInputButtons, SlpStreamMode } from "../src";
import { Subscription } from "rxjs";

describe("combo calculation", () => {
Expand All @@ -23,7 +23,7 @@ describe("combo calculation", () => {
it("correctly finds button combinations", async () => {
const comboSpy = sinon.spy();

const slpStream = new RxSlpStream();
const slpStream = new RxSlpStream({ mode: SlpStreamMode.MANUAL });
const realtime = new SlpRealTime();
realtime.setStream(slpStream);

Expand Down
Loading

0 comments on commit 15611d3

Please sign in to comment.