diff --git a/api/comments.js b/api/comments.js index e9bc42e..0569a2f 100644 --- a/api/comments.js +++ b/api/comments.js @@ -1,4 +1,4 @@ -const colors = require('../misc/icons/colors.json'); +const Player = require('../classes/Player.js') module.exports = async (app, req, res) => { @@ -54,22 +54,15 @@ module.exports = async (app, req, res) => { } if (req.query.type != "profile") { - comment.username = y[1] || "-" + let commentUser = new Player(y) + Object.keys(commentUser).forEach(k => { + comment[k] = commentUser[k] + }) comment.levelID = x[1] || req.params.id comment.playerID = x[3] || 0 - comment.accountID = y[16] || 0 comment.color = (comment.playerID == "16" ? "50,255,255" : x[12] || "255,255,255") if (x[10] > 0) comment.percent = +x[10] comment.moderator = +x[11] || 0 - comment.icon = { - form: ['icon', 'ship', 'ball', 'ufo', 'wave', 'robot', 'spider'][+y[14]], - icon: +y[9] || 1, - col1: +y[10], - col2: +y[11], - glow: +y[15] > 1, - col1RGB: colors[y[10]] || colors["0"], - col2RGB: colors[y[11]] || colors["3"] - } app.userCache(req.id, comment.accountID, comment.playerID, comment.username) } diff --git a/api/icon.js b/api/icon.js index 0ce5cde..8e26f2f 100644 --- a/api/icon.js +++ b/api/icon.js @@ -117,6 +117,7 @@ async function buildIcon(account=[], userCode) { let partName = getPartName(part, leg) let offsetData = icons[partName.slice(mainPath.length)] + if (!offsetData) return let { spriteSize, spriteOffset } = offsetData let builtPart = sharp(partName.slice(1)) // slice 1 from filename since sharp also reads paths differently diff --git a/api/icon_old.js b/api/icon_old.js index 35cd142..1b8ca1e 100644 --- a/api/icon_old.js +++ b/api/icon_old.js @@ -7,10 +7,10 @@ const Jimp = require('jimp'); const fs = require('fs'); -const icons = require('../icons/gameSheet.json'); -const colors = require('../icons/colors.json'); -const forms = require('../icons/forms.json') -const offsets = require('../icons/offsets.json'); +const icons = require('../misc/icons/gameSheet.json'); +const colors = require('../misc/icons/colors.json'); +const forms = require('../misc/icons/forms.json') +const offsets = require('../misc/icons/offsets.json'); let hexRegex = /^[A-Fa-f0-9]{6}$/ function hexConvert(hex) { hex = hex.replace('#', ''); return {r: '0x' + hex[0] + hex[1] | 0, g: '0x' + hex[2] + hex[3] | 0, b: '0x' + hex[4] + hex[5] | 0}; } diff --git a/api/leaderboards/scores.js b/api/leaderboards/scores.js index 15dcab3..3656b8e 100644 --- a/api/leaderboards/scores.js +++ b/api/leaderboards/scores.js @@ -1,4 +1,4 @@ -const colors = require('../../misc/icons/colors.json'); +const Player = require('../../classes/Player.js') module.exports = async (app, req, res) => { @@ -15,6 +15,10 @@ module.exports = async (app, req, res) => { if (["creators", "creator", "cp"].some(x => req.query.hasOwnProperty(x) || req.query.type == x)) params.type = "creators" else if (["week", "weekly"].some(x => req.query.hasOwnProperty(x) || req.query.type == x)) params.type = "week" + else if (["global", "relative"].some(x => req.query.hasOwnProperty(x) || req.query.type == x)) { + params.type = "relative" + params.accountID = req.query.accountID + } req.gdRequest('getGJScores20', params, function(err, resp, body) { @@ -22,30 +26,8 @@ module.exports = async (app, req, res) => { scores = body.split('|').map(x => app.parseResponse(x)).filter(x => x[1]) if (!scores.length) return res.sendError() - scores.forEach(x => { - let keys = Object.keys(x) - x.rank = +x[6] - x.username = x[1] - x.playerID = x[2] - x.accountID = x[16] - x.stars = +x[3] - x.demons = +x[4] - x.cp = +x[8] - x.coins = +x[13] - x.usercoins = +x[17] - x.diamonds = +x[46] - x.icon = { - form: ['icon', 'ship', 'ball', 'ufo', 'wave', 'robot', 'spider'][+x[14]], - icon: +x[9] || 1, - col1: +x[10], - col2: +x[11], - glow: +x[15] > 1, - col1RGB: colors[x[10]] || colors["0"], - col2RGB: colors[x[11]] || colors["3"] - } - keys.forEach(k => delete x[k]) - app.userCache(req.id, x.accountID, x.playerID, x.username) - }) - return res.status(200).send(scores) - }) + scores = scores.map(x => new Player(x)) + scores.forEach(x => app.userCache(req.id, x.accountID, x.playerID, x.username)) + return res.status(200).send(scores.slice(0, amount)) + }) } \ No newline at end of file diff --git a/api/profile.js b/api/profile.js index 0ad1fe1..2291217 100644 --- a/api/profile.js +++ b/api/profile.js @@ -1,5 +1,5 @@ const fs = require('fs') -const colors = require('../misc/icons/colors.json'); +const Player = require('../classes/Player.js') module.exports = async (app, req, res, api, getLevels) => { @@ -48,38 +48,7 @@ module.exports = async (app, req, res, api, getLevels) => { if (!foundID) app.userCache(req.id, account[16], account[2], account[1]) - let userData = { - username: account[1] || "[MISSINGNO.]", - playerID: account[2], - accountID: account[16], - rank: +account[30], - stars: +account[3], - diamonds: +account[46], - coins: +account[13], - userCoins: +account[17], - demons: +account[4], - cp: +account[8], - friendRequests: account[19] == "0", - messages: account[18] == "0" ? "all" : account[18] == "1" ? "friends" : "off", - commentHistory: account[50] == "0" ? "all" : account[50] == "1" ? "friends" : "off", - moderator: +account[49], - youtube: account[20] || null, - twitter: account[44] || null, - twitch: account[45] || null, - icon: +account[21], - ship: +account[22], - ball: +account[23], - ufo: +account[24], - wave: +account[25], - robot: +account[26], - spider: +account[43], - col1: +account[10], - col2: +account[11], - deathEffect: +account[48] || 1, - glow: account[28] == "1", - col1RGB: colors[account[10]] || colors["0"], - col2RGB: colors[account[11]] || colors["3"] - } + let userData = new Player(account) if (api) return res.status(200).send(userData) diff --git a/assets/unmagnify.png b/assets/unmagnify.png new file mode 100644 index 0000000..6277c5b Binary files /dev/null and b/assets/unmagnify.png differ diff --git a/classes/Player.js b/classes/Player.js new file mode 100644 index 0000000..4c8a15c --- /dev/null +++ b/classes/Player.js @@ -0,0 +1,53 @@ +const colors = require('../misc/icons/colors.json'); + +class Level { + constructor(account) { + this.username = account[1] || "-", + this.playerID = account[2], + this.accountID = account[16], + this.rank = +account[6] || +account[30], + this.stars = +account[3], + this.diamonds = +account[46], + this.coins = +account[13], + this.userCoins = +account[17], + this.demons = +account[4], + this.cp = +account[8], + this.icon = +account[21] + + if (!+account[22]) { // partial profile, used for leaderboards and stuff + this.icon = { + form: ['icon', 'ship', 'ball', 'ufo', 'wave', 'robot', 'spider'][+account[14]], + icon: +account[9] || 1, + col1: +account[10], + col2: +account[11], + glow: +account[15] > 1 || account[28] == "1" + } + delete this.col1; delete this.col2; delete this.glow; delete this.col1RGB; delete this.col2RGB + } + + else { + this.friendRequests = account[19] == "0", + this.messages = account[18] == "0" ? "all" : account[18] == "1" ? "friends" : "off", + this.commentHistory = account[50] == "0" ? "all" : account[50] == "1" ? "friends" : "off", + this.moderator = +account[49], + this.youtube = account[20] || null, + this.twitter = account[44] || null, + this.twitch = account[45] || null, + this.ship = +account[22], + this.ball = +account[23], + this.ufo = +account[24], + this.wave = +account[25], + this.robot = +account[26], + this.spider = +account[43], + this.col1 = +account[10], + this.col2 = +account[11], + this.deathEffect = +account[48] || 1, + this.glow = account[15] > 1 || account[28] == "1" + } + + this.col1RGB = colors[account[10]] || colors["0"], + this.col2RGB = colors[account[11]] || colors["3"] + } +} + +module.exports = Level; \ No newline at end of file diff --git a/html/api.html b/html/api.html index 1f7ad44..9493ca6 100644 --- a/html/api.html +++ b/html/api.html @@ -357,7 +357,7 @@
demons: Number of completed demons
cp: Number of creator points
coins: Number of secret coins
-usercoins: Number of user coins
+userCoins: Number of user coins
diamonds: Number of diamonds
icon: The icon preview showed next to the player's name
diff --git a/html/leaderboard.html b/html/leaderboard.html index 6752089..ab00eac 100644 --- a/html/leaderboard.html +++ b/html/leaderboard.html @@ -51,11 +51,15 @@