mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 15:04:52 +09:00
Move all functions and classes currently available through lib/name and libName to be under a single flat namespace in lib. This make reorganising the lib namespace much simpler as the location of symbols can move without breaking the consumers of lib. The multi-entrypoint design was already problematic for the web plugin system which couldn't effectively use it due to how webpack's shared module system is awkward to set up with multiple entrypoints per package.
89 lines
1.8 KiB
JavaScript
89 lines
1.8 KiB
JavaScript
"use strict";
|
|
|
|
/**
|
|
* Stastics collected about a player.
|
|
* @alias module:lib.PlayerStats
|
|
*/
|
|
class PlayerStats {
|
|
/**
|
|
* Count of the number of times this player has been seen joining this server.
|
|
* @type {number}
|
|
*/
|
|
joinCount = 0;
|
|
|
|
/**
|
|
* Time in ms this player has been seen online on this instance.
|
|
* @type {number}
|
|
*/
|
|
onlineTimeMs = 0;
|
|
|
|
/**
|
|
* Timestamp the player was last seen joining.
|
|
* @type {Date=}
|
|
*/
|
|
lastJoinAt;
|
|
|
|
/**
|
|
* Timestamp the player was last seen leaving.
|
|
* @type {Date=}
|
|
*/
|
|
lastLeaveAt;
|
|
|
|
/**
|
|
* Reason the player was last seen leaving with.
|
|
* @type {string=}
|
|
*/
|
|
lastLeaveReason;
|
|
|
|
static jsonSchema = {
|
|
type: "object",
|
|
properties: {
|
|
"join_count": { type: "integer" },
|
|
"online_time_ms": { type: "number" },
|
|
"last_join_at": { type: "number" },
|
|
"last_leave_at": { type: "number" },
|
|
"last_leave_reason": { type: "string" },
|
|
},
|
|
};
|
|
|
|
constructor(json = {}) {
|
|
if (json["join_count"]) {
|
|
this.joinCount = json["join_count"];
|
|
}
|
|
if (json["online_time_ms"]) {
|
|
this.onlineTimeMs = json["online_time_ms"];
|
|
}
|
|
if (json["last_join_at"]) {
|
|
this.lastJoinAt = new Date(json["last_join_at"]);
|
|
}
|
|
if (json["last_leave_at"]) {
|
|
this.lastLeaveAt = new Date(json["last_leave_at"]);
|
|
this.lastLeaveReason = json["last_leave_reason"] || "quit";
|
|
}
|
|
}
|
|
|
|
static fromJSON(json) {
|
|
return new this(json);
|
|
}
|
|
|
|
toJSON() {
|
|
let json = {};
|
|
if (this.joinCount) {
|
|
json["join_count"] = this.joinCount;
|
|
}
|
|
if (this.onlineTimeMs) {
|
|
json["online_time_ms"] = this.onlineTimeMs;
|
|
}
|
|
if (this.lastJoinAt) {
|
|
json["last_join_at"] = this.lastJoinAt.getTime();
|
|
}
|
|
if (this.lastLeaveAt) {
|
|
json["last_leave_at"] = this.lastLeaveAt.getTime();
|
|
json["last_leave_reason"] = this.lastLeaveReason;
|
|
}
|
|
return json;
|
|
}
|
|
}
|
|
|
|
module.exports = PlayerStats;
|