Skip to content
Permalink
Browse files
Add colours to /gang members
  • Loading branch information
RussellLVP committed Jun 26, 2020
1 parent 78e2a58 commit 2305529073d2324dd91f3cefac0ecfcb3ec3ea1e
Showing 5 changed files with 25 additions and 4 deletions.
@@ -415,6 +415,12 @@ class GangCommands {
ingame.add(otherPlayer.account.userId);
}

const kPositionColor = new Map([
[ 'Leader', '{FFFF00}' ],
[ 'Manager', '{FF8000}' ],
[ 'Member', '' ],
]);

// Display a dialog with all the relevant information about the member(s).
const dialog = new Menu('Gang members', [
'Position',
@@ -425,6 +431,8 @@ class GangCommands {

for (const member of members) {
const position = GangDatabase.toRoleString(member.role);
const positionColor = kPositionColor.get(position);
const color = member.color !== null ? `{${member.color.toHexRGB()}}` : '';
const nickname = member.nickname;

if (ingame.has(member.userId))
@@ -434,7 +442,7 @@ class GangCommands {
if (member.lastSeen && !Number.isNaN(member.lastSeen.getTime()))
lastSeen = fromNow({ date: member.lastSeen });

dialog.addItem(position, nickname, lastSeen);
dialog.addItem(positionColor + position, color + nickname, lastSeen);
}

await dialog.displayForPlayer(player);
@@ -448,13 +448,13 @@ describe('GangCommands', (it, beforeEach) => {
assert.equal(player.messages.length, 0);
assert.deepEqual(player.getLastDialogAsTable(/* hasColumn= */ true).rows, [
[
'Leader',
'Gunther',
'{FFFF00}Leader',
'{FFFF00}Gunther',
'now',
],
[
'Member',
'Harry',
'{505078}Harry',
'14 days ago',
],
[
@@ -2,6 +2,7 @@
// Use of this source code is governed by the MIT license, a copy of which can
// be found in the LICENSE file.

import { Color } from 'base/color.js';
import Gang from 'features/gangs/gang.js';

// Query for loading a gang's information for a specific player.
@@ -79,9 +80,14 @@ const GANG_MEMBERS_QUERY = `
users_gangs.user_id,
users_gangs.user_role,
users.username,
IF(users_gangs.user_use_gang_color = 1,
IFNULL(gangs.gang_color, users_mutable.custom_color),
users_mutable.custom_color) AS color,
users_mutable.last_seen
FROM
users_gangs
LEFT JOIN
gangs ON gangs.gang_id = users_gangs.gang_id
LEFT JOIN
users ON users.user_id = users_gangs.user_id
LEFT JOIN
@@ -387,6 +393,7 @@ class GangDatabase {
role: GangDatabase.toRoleValue(row.user_role),
userId: row.user_id,
username: row.username,
color: row.color !== 0 ? Color.fromNumberRGBA(row.color) : null,
lastSeen: new Date(row.last_seen),
});
});
@@ -139,6 +139,7 @@ class GangManager {
members.forEach(member => {
const memberInfo = {
nickname: member.username,
color: member.color,
player: gangPlayers[member.userId] || null,
role: member.role,
userId: member.userId,
@@ -4,6 +4,7 @@

import Gang from 'features/gangs/gang.js';
import GangDatabase from 'features/gangs/gang_database.js';
import { Color } from 'base/color.js';

const mockedGangInfo = {
hko: {
@@ -89,24 +90,28 @@ class MockGangDatabase {
role: Gang.ROLE_LEADER,
userId: 42,
username: 'Gunther',
color: Color.fromRGB(255, 255, 0),
lastSeen: new Date(Date.now() - 250)
},
{
role: Gang.ROLE_MEMBER,
userId: 1338,
username: 'Harry',
color: Color.fromRGB(80, 80, 120, 180),
lastSeen: new Date(Date.now() - 13.75 * 86400 * 1000)
},
{
role: Gang.ROLE_MEMBER,
userId: 1337,
username: 'Russell',
color: null,
lastSeen: new Date(Date.now() - 64.75 * 86400 * 1000)
},
{
role: Gang.ROLE_MEMBER,
userId: 1339,
username: 'Sander',
color: null,
lastSeen: new Date(Date.now() - 720 * 86400 * 1000)
}
];

0 comments on commit 2305529

Please sign in to comment.