Skip to content

Commit

Permalink
feat(tourney): sort clients by ipc id
Browse files Browse the repository at this point in the history
  • Loading branch information
KotRikD committed Feb 28, 2024
1 parent d259f0d commit 1d08d0d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
8 changes: 4 additions & 4 deletions packages/tosu/src/api/utils/buildResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,9 @@ const buildTourneyData = (
instanceManager.osuInstances
).filter((instance) => instance.isTourneySpectator);

const mappedOsuTourneyClients = osuTourneyClients.map<TourneyIpcClient>(
(instance, iterator) => {
const mappedOsuTourneyClients = osuTourneyClients
.sort((a, b) => a.ipcId - b.ipcId)
.map<TourneyIpcClient>((instance, iterator) => {
const { allTimesData, gamePlayData, tourneyUserProfileData } =
instance.entities.getServices([
'allTimesData',
Expand Down Expand Up @@ -343,8 +344,7 @@ const buildTourneyData = (
}
}
};
}
);
});

const { tourneyManagerData } = osuTourneyManager[0].entities.getServices([
'tourneyManagerData'
Expand Down
8 changes: 4 additions & 4 deletions packages/tosu/src/api/utils/buildResultV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,9 @@ const buildTourneyData = (
instanceManager.osuInstances
).filter((instance) => instance.isTourneySpectator);

const mappedOsuTourneyClients = osuTourneyClients.map(
(instance, iterator): TourneyClients => {
const mappedOsuTourneyClients = osuTourneyClients
.sort((a, b) => a.ipcId - b.ipcId)
.map((instance, iterator): TourneyClients => {
const {
allTimesData,
gamePlayData,
Expand Down Expand Up @@ -524,8 +525,7 @@ const buildTourneyData = (
unstableRate: gamePlayData.UnstableRate
}
};
}
);
});

const { tourneyManagerData } = osuTourneyManager[0].entities.getServices([
'tourneyManagerData'
Expand Down
3 changes: 3 additions & 0 deletions packages/tosu/src/objects/instanceManager/instanceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export class InstanceManager {

const osuInstance = new OsuInstance(process.pid);
if (process.cmd.includes('-spectateclient')) {
const [_, ipcId] = process.cmd.split(' ');

osuInstance.setTourneyIpcId(Number(ipcId));
osuInstance.setIsTourneySpectator(true);
}

Expand Down
6 changes: 6 additions & 0 deletions packages/tosu/src/objects/instanceManager/osuInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ export class OsuInstance {
isTourneyManager: boolean = false;
isTourneySpectator: boolean = false;

ipcId: number = 0;

emitter: EventEmitter;

constructor(pid: number) {
Expand Down Expand Up @@ -133,6 +135,10 @@ export class OsuInstance {
this.entities.set('userProfile', new UserProfile(this.entities));
}

setTourneyIpcId(ipcId: number) {
this.ipcId = ipcId;
}

setIsTourneySpectator(newVal: boolean) {
this.isTourneySpectator = newVal;
}
Expand Down

0 comments on commit 1d08d0d

Please sign in to comment.