Skip to content

Commit

Permalink
Merge pull request #71 from EvoEsports/dev
Browse files Browse the repository at this point in the history
0.8.0
  • Loading branch information
Chris92de authored Dec 28, 2024
2 parents a9b2aae + 2bbbd5a commit b863a77
Show file tree
Hide file tree
Showing 83 changed files with 10,378 additions and 9,356 deletions.
2 changes: 0 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
root = true

[*]
end_of_line=lf
insert_final_newline=true
Expand Down
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ DEBUGLEVEL=1
FREEZONE_PASS=""
DEDIMANIA_PASS=""

# Use Celyans emotes in TMNF chat, for details: http://bit.ly/Celyans_emotes_sheet
CHAT_USE_EMOTES=false

# uncomment next line to force openplanet mode for tm2020:
# FORCE_OP_MODE="OFFICIAL"

Expand Down
10 changes: 0 additions & 10 deletions .eslintrc.yml

This file was deleted.

10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"npm.exclude": "",
"search.exclude": {
"**/node_modules/**": true
},
"files.exclude": {
"**/node_modules/**": true
},
"prettier.printWidth": 180
}
250 changes: 134 additions & 116 deletions core/commandmanager.ts

Large diffs are not rendered by default.

301 changes: 150 additions & 151 deletions core/mapmanager.ts
Original file line number Diff line number Diff line change
@@ -1,151 +1,150 @@
import { chunkArray, clone } from "./utils";

export interface Map {
UId: string;
Name: string;
Author: string;
AuthorNickname?: string;
AuthorTime: number;
GoldTime: number;
SilverTime: number;
BronzeTime: number;
CopperPrize: number;
FileName: string;
Environnement: string;
Mood: string;
LapRace: boolean;
NbLaps: number;
NbCheckpoints: number;
Vehicle?: string;
[key: string]: any;
}

/**
* MapManager class
*/
class MapManager {
private maps: { [key: string]: Map; };
previousMap?: Map;
currentMap?: Map;
nextMap?: Map;

/**
* @ignore
*/
constructor() {
this.maps = {};
}

/**
* Initialize the map manager
* @ignore
**/
async init() {
this.maps = {};
tmc.server.addListener("Trackmania.BeginMap", this.onBeginMap, this);
tmc.server.addListener("Trackmania.MapListModified", this.onMapListModified, this);
try {
this.currentMap = await tmc.server.call("GetCurrentMapInfo");
this.nextMap = await tmc.server.call("GetNextMapInfo");
} catch (e:any) {
tmc.cli("¤error¤" + e.message);
}
await this.syncMaplist();
}

/** @ignore */
private async onBeginMap(data: any) {
this.previousMap = clone(this.currentMap);
this.currentMap = data[0];
const index = Object.keys(this.maps).indexOf(data[0].UId);
const indexNext = (index + 1) % Object.keys(this.maps).length;
this.nextMap = Object.values(this.maps)[indexNext];
}

/** @ignore */
private async onMapListModified(data: any) {
if (data[2] === true) {
await this.syncMaplist();
}
}

/**
* Sync the maplist with the server
*/
async syncMaplist() {
this.maps = {};

const chunckedMaps: any = chunkArray(await tmc.server.call("GetMapList", -1, 0), 100);
let method = "GetMapInfo";
if (tmc.game.Name == "TmForever") method = "GetChallengeInfo";

for (const infos of chunckedMaps) {
let out:any[] = [];

for (const map of infos) {
out.push([method, map.FileName]);
}
const res:any = await tmc.server.multicall(out) || [];

for (const map of res) {
this.maps[map.UId] = map;
}
}
}
/**
* add map
* @param map
*/
addMap(map: Map) {
if (!this.maps[map.UId]) {
this.maps[map.UId] = map;
}
}

/**
* remove map
* @param mapUId
*/
removeMap(mapUId: string) {
if (this.maps[mapUId]) {
delete this.maps[mapUId];
}
}

/**
* get maps
* @returns {Map[]} Returns the current maplist
*/
get(): Map[] {
return Object.values(this.maps);
}

getMap(mapUid: string): Map | undefined {
return this.maps[mapUid];
}

/**
* get mapslist
* @returns {Map[]} Returns the current maplist
*/
getMaplist(): Map[] {
return this.get();
}

/**
* get map uids
* @returns {string[]} Returns the current map uids
*/
getUids(): string[] {
return Object.keys(this.maps);
}

/**
* @returns {number} Returns the total number of maps present at server
*/
getMapCount(): number {
return Object.values(this.maps).length;
}
}

export default MapManager;
import { chunkArray, clone } from "./utils";

export interface Map {
UId: string;
Name: string;
Author: string;
AuthorNickname?: string;
AuthorTime: number;
GoldTime: number;
SilverTime: number;
BronzeTime: number;
CopperPrize: number;
FileName: string;
Environnement: string;
Mood: string;
LapRace: boolean;
NbLaps: number;
NbCheckpoints: number;
Vehicle?: string;
[key: string]: any;
}

/**
* MapManager class
*/
class MapManager {
private maps: { [key: string]: Map; };
previousMap?: Map;
currentMap?: Map;
nextMap?: Map;

/**
* @ignore
*/
constructor() {
this.maps = {};
}

/**
* Initialize the map manager
* @ignore
**/
async init() {
this.maps = {};
tmc.server.addListener("Trackmania.BeginMap", this.onBeginMap, this);
tmc.server.addListener("Trackmania.MapListModified", this.onMapListModified, this);
try {
this.currentMap = await tmc.server.call("GetCurrentMapInfo");
this.nextMap = await tmc.server.call("GetNextMapInfo");
} catch (e:any) {
tmc.cli("¤error¤" + e.message);
}
await this.syncMaplist();
}

/** @ignore */
private async onBeginMap(data: any) {
this.previousMap = clone(this.currentMap);
this.currentMap = data[0];
const index = Object.keys(this.maps).indexOf(data[0].UId);
const indexNext = (index + 1) % Object.keys(this.maps).length;
this.nextMap = Object.values(this.maps)[indexNext];
}

/** @ignore */
private async onMapListModified(data: any) {
if (data[2] === true) {
await this.syncMaplist();
}
}

/**
* Sync the maplist with the server
*/
async syncMaplist() {
const chunckedMaps: any = chunkArray(await tmc.server.call("GetMapList", -1, 0), 100);
let method = "GetMapInfo";
if (tmc.game.Name == "TmForever") method = "GetChallengeInfo";
let newMaps = {};
for (const infos of chunckedMaps) {
let out:any[] = [];

for (const map of infos) {
out.push([method, map.FileName]);
}
const res:any = await tmc.server.multicall(out) || [];

for (const map of res) {
newMaps[map.UId] = map;
}
}
this.maps = newMaps;
}
/**
* add map
* @param map
*/
addMap(map: Map) {
if (!this.maps[map.UId]) {
this.maps[map.UId] = map;
}
}

/**
* remove map
* @param mapUId
*/
removeMap(mapUId: string) {
if (this.maps[mapUId]) {
delete this.maps[mapUId];
}
}

/**
* get maps
* @returns {Map[]} Returns the current maplist
*/
get(): Map[] {
return Object.values(this.maps);
}

getMap(mapUid: string): Map | undefined {
return this.maps[mapUid];
}

/**
* get mapslist
* @returns {Map[]} Returns the current maplist
*/
getMaplist(): Map[] {
return this.get();
}

/**
* get map uids
* @returns {string[]} Returns the current map uids
*/
getUids(): string[] {
return Object.keys(this.maps);
}

/**
* @returns {number} Returns the total number of maps present at server
*/
getMapCount(): number {
return Object.values(this.maps).length;
}
}

export default MapManager;
33 changes: 16 additions & 17 deletions core/migrations/00-create-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { DataTypes } from 'sequelize';
import type { Migration } from '../../migrate';

export const up: Migration = async ({ context: sequelize }) => {
await sequelize.getQueryInterface().createTable('maps', {
uuid: {
type: DataTypes.STRING,
allowNull: false,
primaryKey: true,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
await sequelize.getQueryInterface().createTable('maps', {
uuid: {
type: DataTypes.STRING,
allowNull: false,
primaryKey: true
},
name: {
type: DataTypes.STRING,
allowNull: false
},
author: {
type: DataTypes.STRING,
allowNull: false
Expand All @@ -21,21 +21,20 @@ export const up: Migration = async ({ context: sequelize }) => {
},
authorTime: {
type: DataTypes.INTEGER,
allowNull:false
allowNull: false
},
environment: {
type:DataTypes.STRING
type: DataTypes.STRING
},
updatedAt: {
type: DataTypes.DATE
},
createdAt:
{
createdAt: {
type: DataTypes.DATE
}
});
});
};

export const down: Migration = async ({ context: sequelize }) => {
await sequelize.getQueryInterface().dropTable('maps');
};
await sequelize.getQueryInterface().dropTable('maps');
};
Loading

0 comments on commit b863a77

Please sign in to comment.