jsplanet
Version:
A controller for Trackmania 2020 dedicated server.
88 lines (87 loc) • 3.31 kB
JavaScript
import { Map } from "../structures/index.js";
class MapsManager {
remote;
constructor(remote) {
this.remote = remote;
}
async addMap(filename) {
const [isSuccess] = await this.remote.callMethod("AddMap", filename);
return isSuccess;
}
async addMaps(filenames) {
const [added] = await this.remote.callMethod("AddMapList", filenames);
return added;
}
async getCurrentIndex() {
const [index] = await this.remote.callMethod("GetCurrentMapIndex");
return index;
}
async getCurrentMapInfo() {
const [mapInfo] = await this.remote.callMethod("GetCurrentMapInfo");
return new Map(mapInfo.Name, mapInfo.UId, mapInfo.FileName, mapInfo.Author, mapInfo.AuthorNickname);
}
async getList(size, offset) {
const [list] = await this.remote.callMethod("GetMapList", size, offset);
return list.map((map) => new Map(map.Name, map.UId, map.FileName, map.Author, map.AuthorNickname));
}
async getMapInfo(filename) {
const [mapInfo] = await this.remote.callMethod("GetMapInfo", filename);
return new Map(mapInfo.Name, mapInfo.UId, mapInfo.FileName, mapInfo.Author, mapInfo.AuthorNickname);
}
async getNextIndex() {
const [index] = await this.remote.callMethod("GetNextMapIndex");
return index;
}
async getNextMapInfo() {
const [mapInfo] = await this.remote.callMethod("GetNextMapInfo");
return new Map(mapInfo.Name, mapInfo.UId, mapInfo.FileName, mapInfo.Author, mapInfo.AuthorNickname);
}
async insertMap(filename) {
const [isSuccess] = await this.remote.callMethod("InsertMap", filename);
return isSuccess;
}
async insertMaps(filenames) {
const [inserted] = await this.remote.callMethod("InsertMapList", filenames);
return inserted;
}
async jumpToIndex(index) {
const [isSuccess] = await this.remote.callMethod("JumpToMapIndex", index);
return isSuccess;
}
async jumpToUid(uid) {
const [isSuccess] = await this.remote.callMethod("JumpToMapIdent", uid);
return isSuccess;
}
async next() {
const [isSuccess] = await this.remote.callMethod("NextMap");
return isSuccess;
}
async removeMap(filename) {
const [isSuccess] = await this.remote.callMethod("RemoveMap", filename);
return isSuccess;
}
async removeMaps(filenames) {
const [removed] = await this.remote.callMethod("RemoveMapList", filenames);
return removed;
}
async restart() {
const [isSuccess] = await this.remote.callMethod("RestartMap");
return isSuccess;
}
async setNextIndex(index) {
const [isSuccess] = await this.remote.callMethod("SetNextMapIndex", index);
return isSuccess;
}
async setNextUid(uid) {
const [isSuccess] = await this.remote.callMethod("SetNextMapIdent", uid);
return isSuccess;
}
async write(filename, content) {
const formattedFilename = filename.endsWith(".Map.Gbx")
? filename
: `${filename}.Map.Gbx`;
const [isSuccess] = await this.remote.callMethod("WriteFile", formattedFilename, content);
return isSuccess;
}
}
export default MapsManager;