Files
Paradise/tgui/packages/tgui-say/ChannelIterator.ts
73e861b7c0 Dev team chat (#26669)
* dev team chat initial

* oops

* refactor who code

* allow discord relay

* yeet some un-needed stuff

* tweak the role colour

* Update code/__DEFINES/admin_defines.dm

Co-authored-by: ROdenFL <ROdenFL@yandex.ru>
Signed-off-by:  Sean <12197162+S34NW@users.noreply.github.com>

* .Add to +=

* Update config/example/config.toml

Co-authored-by: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com>
Signed-off-by:  Sean <12197162+S34NW@users.noreply.github.com>

---------

Signed-off-by: Sean <12197162+S34NW@users.noreply.github.com>
Co-authored-by: ROdenFL <ROdenFL@yandex.ru>
Co-authored-by: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com>
2024-09-03 16:49:45 +00:00

70 lines
1.7 KiB
TypeScript

export type Channel = 'Say' | 'Radio' | 'Whisper' | 'Me' | 'OOC' | 'LOOC' | 'Mentor' | 'Admin' | 'Dsay' | 'Dev';
/**
* ### ChannelIterator
* Cycles a predefined list of channels,
* skipping over blacklisted ones,
* and providing methods to manage and query the current channel.
*/
export class ChannelIterator {
private index: number = 0;
private readonly channels: Channel[] = [
'Say',
'Radio',
'Whisper',
'Me',
'OOC',
'LOOC',
'Mentor',
'Admin',
'Dsay',
'Dev',
];
private readonly blacklist: Channel[] = ['Mentor', 'Admin', 'Dsay', 'Dev'];
private readonly quiet: Channel[] = ['OOC', 'LOOC', 'Mentor', 'Admin', 'Dsay', 'Dev'];
public next(): Channel {
if (this.blacklist.includes(this.channels[this.index])) {
return this.channels[this.index];
}
for (let index = 1; index <= this.channels.length; index++) {
let nextIndex = (this.index + index) % this.channels.length;
if (!this.blacklist.includes(this.channels[nextIndex])) {
this.index = nextIndex;
break;
}
}
return this.channels[this.index];
}
public isCurrentChannelBlacklisted(): boolean {
return this.blacklist.includes(this.channels[this.index]);
}
public set(channel: Channel): void {
this.index = this.channels.indexOf(channel) || 0;
}
public current(): Channel {
return this.channels[this.index];
}
public isMe(): boolean {
return this.channels[this.index] === 'Me';
}
public isSay(): boolean {
return this.channels[this.index] === 'Say';
}
public isVisible(): boolean {
return !this.quiet.includes(this.channels[this.index]);
}
public reset(): void {
this.index = 0;
}
}