Skip to content

Instantly share code, notes, and snippets.

@ycz
Created October 22, 2021 22:12
Show Gist options
  • Save ycz/e3b0d6a748d5b858c2661321e195b988 to your computer and use it in GitHub Desktop.
Save ycz/e3b0d6a748d5b858c2661321e195b988 to your computer and use it in GitHub Desktop.
6 Minutes of Down Smash 0-Deaths source code
const fs = require("fs");
const { SlippiGame } = require("@slippi/slippi-js");
const DSMASH_MOVE_ID = 12;
const SAMUS_ID = 16;
const BASE_DIR = "/mnt/c/Users/ycz/Documents/Slippi/Archive";
const RECORDS_FILE = "./dsmashStarts.json";
let loadedRecords;
try {
loadedRecords = fs.readFileSync(RECORDS_FILE);
} catch (e) {}
const records = loadedRecords
? JSON.parse(loadedRecords)
: {
dsmashes: {},
index: 0,
};
const writeRecords = () => {
console.log("writing");
fs.writeFileSync("./dsmashStarts.json", JSON.stringify(records));
};
const read = (filename, index) => {
const game = new SlippiGame(`${BASE_DIR}/${filename}`);
const settings = game.getSettings();
if (!settings) {
console.error("Phantom file found!");
return;
}
const samuses = settings.players.filter(
(player) => player.characterId === SAMUS_ID
);
if (samuses.length === 0) {
return;
}
const stats = game.getStats();
const firstConversion = stats.conversions[0];
if (
firstConversion &&
firstConversion.moves.length &&
samuses.some(
(player) => player.playerIndex === firstConversion.moves[0].playerIndex
) &&
firstConversion.moves[0].moveId === DSMASH_MOVE_ID
) {
console.log("Found!");
records.dsmashes[filename] = firstConversion;
}
records.index = index;
};
fs.readdir(BASE_DIR, async (err, files) => {
files.forEach((filename, index) => {
if (index < records.index) {
return;
}
if (!filename.endsWith(".slp")) {
return;
}
console.log(index, filename);
try {
read(filename, index);
} catch (e) {
writeRecords();
throw e;
}
if (index % 10 === 0) {
writeRecords();
}
});
});
const fs = require("fs");
const _ = require("lodash");
const RECORDS_FILE = "./dsmashStarts.json";
const BASE_JSON = {
mode: "queue",
replay: "",
isRealTimeMode: false,
outputOverlayFiles: true,
queue: [],
};
const BASE_PATH = "C:\\Users\\ycz\\Documents\\Slippi\\Archive";
const END_PADDING_FRAMES = 120;
fs.readFile(RECORDS_FILE, "utf8", (err, data) => {
// console.log("🚀 / fs.readFile / JSON.stringify(data)", JSON.parse(data));
const conversions = JSON.parse(data).dsmashes;
const conversionEntries = Object.entries(conversions);
const killsFirst = _.sortBy(conversionEntries, ([filename, conversion]) => {
return [!conversion.didKill, filename];
});
const comboJson = {
...BASE_JSON,
queue: killsFirst.map(([filename, conversion]) => ({
path: `${BASE_PATH}\\${filename}`,
startFrame: -120,
endFrame: conversion.endFrame + END_PADDING_FRAMES,
})),
};
fs.writeFile("./dsmashCombos.json", JSON.stringify(comboJson), () => {});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment