slp-enforcer
Version:
Finds violations of the Melee Controller Ruleset by inspecting SLP files (WASM-powered)
91 lines (90 loc) • 3.26 kB
JavaScript
// slp-enforcer -- WASM-backed implementation (universal: Node.js + Browser)
// All business logic runs in Rust/WebAssembly via the peppi SLP parser.
//
// Usage:
// import init, { SlpGame } from 'slp-enforcer'
// await init()
// const game = new SlpGame(slpBytes)
// const result = game.analyzePlayer(playerIndex)
import wasmInit, { initSync, is_box_controller_from_coords, get_cstick_violations, average_travel_coord_hit_rate, has_goomwave_clamping, get_joystick_region, process_analog_stick, float_equals, is_equal, get_unique_coords, get_target_coords, SlpGame, } from '../pkg/web/libenforcer_wasm.js';
export var JoystickRegion;
(function (JoystickRegion) {
JoystickRegion[JoystickRegion["DZ"] = 0] = "DZ";
JoystickRegion[JoystickRegion["NE"] = 1] = "NE";
JoystickRegion[JoystickRegion["SE"] = 2] = "SE";
JoystickRegion[JoystickRegion["SW"] = 3] = "SW";
JoystickRegion[JoystickRegion["NW"] = 4] = "NW";
JoystickRegion[JoystickRegion["N"] = 5] = "N";
JoystickRegion[JoystickRegion["E"] = 6] = "E";
JoystickRegion[JoystickRegion["S"] = 7] = "S";
JoystickRegion[JoystickRegion["W"] = 8] = "W";
})(JoystickRegion || (JoystickRegion = {}));
// ---- Initialization ----
let initialized = false;
function ensureInitialized() {
if (!initialized) {
throw new Error('slp-enforcer: WASM not initialized. Call init() first.');
}
}
/**
* Initialize the WASM module. Must be called once before using any other function.
*
* Call with no arguments to load from the default URL (relative to the module),
* or pass a custom URL/path/Response to the .wasm file if your bundler requires it.
* You may also pass raw WASM bytes (ArrayBuffer/Uint8Array) for synchronous initialization.
*/
export default async function init(wasmSource) {
if (initialized)
return;
if (wasmSource instanceof ArrayBuffer || ArrayBuffer.isView(wasmSource)) {
initSync({ module: wasmSource });
}
else {
await wasmInit(wasmSource);
}
initialized = true;
}
export { init };
// ---- Primary API: SlpGame ----
export { SlpGame };
// ---- Utility Functions ----
export function isBoxControllerFromCoords(coords) {
ensureInitialized();
return is_box_controller_from_coords(coords);
}
export function getCStickViolations(coords) {
ensureInitialized();
return get_cstick_violations(coords);
}
export function averageTravelCoordHitRate(coords) {
ensureInitialized();
return average_travel_coord_hit_rate(coords);
}
export function hasGoomwaveClamping(coords) {
ensureInitialized();
return has_goomwave_clamping(coords);
}
export function getJoystickRegion(x, y) {
ensureInitialized();
return get_joystick_region(x, y);
}
export function processAnalogStick(x, y, deadzone) {
ensureInitialized();
return process_analog_stick(x, y, deadzone);
}
export function FloatEquals(a, b) {
ensureInitialized();
return float_equals(a, b);
}
export function isEqual(one, other) {
ensureInitialized();
return is_equal(one, other);
}
export function getUniqueCoords(coords) {
ensureInitialized();
return get_unique_coords(coords);
}
export function getTargetCoords(coords) {
ensureInitialized();
return get_target_coords(coords);
}