Skip to content

Commit

Permalink
Merge pull request #51 from vinceau/develop
Browse files Browse the repository at this point in the history
Fix inability to match in-game nametags
  • Loading branch information
vinceau authored Aug 25, 2020
2 parents 51e471f + cd4878f commit 623d14f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"realtime"
],
"dependencies": {
"@slippi/slippi-js": "^5.0.4",
"@slippi/slippi-js": "^5.0.5",
"chokidar": "^3.3.1",
"fs-extra": "^8.1.0",
"lodash": "^4.17.19",
Expand Down
Binary file added slp/nametag-combos.slp
Binary file not shown.
2 changes: 1 addition & 1 deletion src/stream/rxSlpStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export { SlpStreamMode, SlpStreamSettings, SlpStreamEvent } from "@slippi/slippi
* @extends {Writable}
*/
export class RxSlpStream extends SlpFileWriter {
protected parser = new SlpParser();
protected parser = new SlpParser({ strict: true }); // Strict mode will enable data validation
private messageSizeSource = new Subject<Map<Command, number>>();

// Observables
Expand Down
13 changes: 7 additions & 6 deletions src/stream/slpFolderStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { map, switchMap, share, takeUntil } from "rxjs/operators";
* @extends {RxSlpStream}
*/
export class SlpFolderStream extends RxSlpStream {
private startRequested$ = new Subject<string>();
private startRequested$ = new Subject<[string, boolean]>();
private stopRequested$ = new Subject<void>();
private newFile$: Observable<string>;
private readStream: TailStream | null = null;
Expand All @@ -37,12 +37,13 @@ export class SlpFolderStream extends RxSlpStream {
) {
super(options, { ...slpOptions, mode: SlpStreamMode.MANUAL }, opts);
this.newFile$ = this.startRequested$.pipe(
switchMap((slpFolder) => {
switchMap(([slpFolder, includeSubfolders]) => {
// End any existing read streams
this.endReadStream();

// Initialize watcher.
const slpGlob = path.join(slpFolder, "*.slp");
const subFolderGlob = includeSubfolders ? "**" : "";
const slpGlob = path.join(slpFolder, subFolderGlob, "*.slp");
const watcher = chokidar.watch(slpGlob, {
ignored: /(^|[\/\\])\../, // ignore dotfiles
persistent: true,
Expand Down Expand Up @@ -83,9 +84,9 @@ export class SlpFolderStream extends RxSlpStream {
* @param {string} slpFolder
* @memberof SlpFolderStream
*/
public start(slpFolder: string): void {
console.log(`Start monitoring: ${slpFolder}`);
this.startRequested$.next(slpFolder);
public start(slpFolder: string, includeSubfolders?: boolean): void {
console.log(`Start monitoring${includeSubfolders ? " with subfolders" : ""}: ${slpFolder}`);
this.startRequested$.next([slpFolder, Boolean(includeSubfolders)]);
}

public stop(): void {
Expand Down
12 changes: 5 additions & 7 deletions src/utils/combo/matchNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import { GameStartType } from "../../types";

export function extractPlayerNames(settings: GameStartType, metadata?: any, playerIndex?: number): string[] {
const nametags: string[] = [];
// If no playerIndex is provided, extract for all players
const indices: Array<string | number> =
playerIndex !== undefined
? [playerIndex]
: Boolean(metadata && metadata.players)
? Object.keys(metadata.players)
: [];
let indices: number[] = settings.players.map((p) => p.playerIndex);
// If playerIndex is provided use that
if (playerIndex !== undefined) {
indices = [playerIndex];
}

for (const index of indices) {
const player = settings.players.find((player) => player.playerIndex === index);
Expand Down
16 changes: 16 additions & 0 deletions test/filter.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { SlippiGame, extractPlayerNames, namesMatch } from "../src";

describe("when extracting player names", () => {
it("can correctly extract player names", () => {
const game = new SlippiGame("slp/nametag-combos.slp");
const settings = game.getSettings();
const metadata = game.getMetadata();
const matchableNames = extractPlayerNames(settings, metadata);
expect(matchableNames.length).toEqual(2);
expect(matchableNames.includes("PK")).toBeTruthy();
expect(matchableNames.includes("GOGO")).toBeTruthy();

const nameTagsToFind = ["PK"];
expect(namesMatch(nameTagsToFind, matchableNames)).toBeTruthy();
});
});
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,10 @@
resolved "https://registry.yarnpkg.com/@sinonjs/text-encoding/-/text-encoding-0.7.1.tgz#8da5c6530915653f3a1f38fd5f101d8c3f8079c5"
integrity sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==

"@slippi/slippi-js@^5.0.4":
version "5.0.4"
resolved "https://registry.yarnpkg.com/@slippi/slippi-js/-/slippi-js-5.0.4.tgz#417876c4d0739786fc153ab26c0017b5d38a476a"
integrity sha512-NZrACcYhBn8YnYxlfLumNg/ZuhcNxae4eB9N0fFbZtW9JJo9mdoN0cfqHz3ofBTgy5cYP1cWkWhjDhzSnJSAnQ==
"@slippi/slippi-js@^5.0.5":
version "5.0.5"
resolved "https://registry.yarnpkg.com/@slippi/slippi-js/-/slippi-js-5.0.5.tgz#abb86b598451d100519a8cb7cddc048e58e2f9e2"
integrity sha512-iVFhJz1njibZf55KCSk8egRpuc85EnkWQtARnNLzzE6nzffMbUwZip5dHwhuH2PI8BRnPmN2M0d9Ri5QdTaZ/g==
dependencies:
"@shelacek/ubjson" "^1.0.1"
iconv-lite "^0.6.2"
Expand Down

0 comments on commit 623d14f

Please sign in to comment.