Skip to content

Commit 2305529

Browse files
committed
Add colours to /gang members
1 parent 78e2a58 commit 2305529

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

Diff for: javascript/features/gangs/gang_commands.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,12 @@ class GangCommands {
415415
ingame.add(otherPlayer.account.userId);
416416
}
417417

418+
const kPositionColor = new Map([
419+
[ 'Leader', '{FFFF00}' ],
420+
[ 'Manager', '{FF8000}' ],
421+
[ 'Member', '' ],
422+
]);
423+
418424
// Display a dialog with all the relevant information about the member(s).
419425
const dialog = new Menu('Gang members', [
420426
'Position',
@@ -425,6 +431,8 @@ class GangCommands {
425431

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

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

437-
dialog.addItem(position, nickname, lastSeen);
445+
dialog.addItem(positionColor + position, color + nickname, lastSeen);
438446
}
439447

440448
await dialog.displayForPlayer(player);

Diff for: javascript/features/gangs/gang_commands.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -448,13 +448,13 @@ describe('GangCommands', (it, beforeEach) => {
448448
assert.equal(player.messages.length, 0);
449449
assert.deepEqual(player.getLastDialogAsTable(/* hasColumn= */ true).rows, [
450450
[
451-
'Leader',
452-
'Gunther',
451+
'{FFFF00}Leader',
452+
'{FFFF00}Gunther',
453453
'now',
454454
],
455455
[
456456
'Member',
457-
'Harry',
457+
'{505078}Harry',
458458
'14 days ago',
459459
],
460460
[

Diff for: javascript/features/gangs/gang_database.js

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by the MIT license, a copy of which can
33
// be found in the LICENSE file.
44

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

78
// Query for loading a gang's information for a specific player.
@@ -79,9 +80,14 @@ const GANG_MEMBERS_QUERY = `
7980
users_gangs.user_id,
8081
users_gangs.user_role,
8182
users.username,
83+
IF(users_gangs.user_use_gang_color = 1,
84+
IFNULL(gangs.gang_color, users_mutable.custom_color),
85+
users_mutable.custom_color) AS color,
8286
users_mutable.last_seen
8387
FROM
8488
users_gangs
89+
LEFT JOIN
90+
gangs ON gangs.gang_id = users_gangs.gang_id
8591
LEFT JOIN
8692
users ON users.user_id = users_gangs.user_id
8793
LEFT JOIN
@@ -387,6 +393,7 @@ class GangDatabase {
387393
role: GangDatabase.toRoleValue(row.user_role),
388394
userId: row.user_id,
389395
username: row.username,
396+
color: row.color !== 0 ? Color.fromNumberRGBA(row.color) : null,
390397
lastSeen: new Date(row.last_seen),
391398
});
392399
});

Diff for: javascript/features/gangs/gang_manager.js

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class GangManager {
139139
members.forEach(member => {
140140
const memberInfo = {
141141
nickname: member.username,
142+
color: member.color,
142143
player: gangPlayers[member.userId] || null,
143144
role: member.role,
144145
userId: member.userId,

Diff for: javascript/features/gangs/test/mock_gang_database.js

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import Gang from 'features/gangs/gang.js';
66
import GangDatabase from 'features/gangs/gang_database.js';
7+
import { Color } from 'base/color.js';
78

89
const mockedGangInfo = {
910
hko: {
@@ -89,24 +90,28 @@ class MockGangDatabase {
8990
role: Gang.ROLE_LEADER,
9091
userId: 42,
9192
username: 'Gunther',
93+
color: Color.fromRGB(255, 255, 0),
9294
lastSeen: new Date(Date.now() - 250)
9395
},
9496
{
9597
role: Gang.ROLE_MEMBER,
9698
userId: 1338,
9799
username: 'Harry',
100+
color: Color.fromRGB(80, 80, 120, 180),
98101
lastSeen: new Date(Date.now() - 13.75 * 86400 * 1000)
99102
},
100103
{
101104
role: Gang.ROLE_MEMBER,
102105
userId: 1337,
103106
username: 'Russell',
107+
color: null,
104108
lastSeen: new Date(Date.now() - 64.75 * 86400 * 1000)
105109
},
106110
{
107111
role: Gang.ROLE_MEMBER,
108112
userId: 1339,
109113
username: 'Sander',
114+
color: null,
110115
lastSeen: new Date(Date.now() - 720 * 86400 * 1000)
111116
}
112117
];

0 commit comments

Comments
 (0)