Skip to content

Commit

Permalink
Add languages to the available radio channels
Browse files Browse the repository at this point in the history
  • Loading branch information
RussellLVP committed Dec 17, 2017
1 parent 3787b92 commit 455660f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
34 changes: 29 additions & 5 deletions data/radio.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
[
{
"name": "LVP Radio",
"language": "English",
"stream": "http://play.sa-mp.nl:8000/stream/1/"
},
{
"name": "ChristmasHits.FM",
"name": "3FM",
"language": "Dutch",
"stream": "http://icecast.omroep.nl/3fm-bb-mp3"
},
{
"name": "BBC Radio 1",
"language": "English",
"stream": "http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio1_mf_q"
},
{
"name": "Capital FM",
"language": "English",
"stream": "http://media-ice.musicradio.com/CapitalMP3"
},
{
"name": "Christmas Hits",
"language": "German",
"stream": "http://46.105.118.14:25500/listen.pls"
},
{
"name": "BBC Radio 1 (UK)",
"stream": "http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio1_mf_p?s=1426866326&e=1426880726&h=89d26749151daccea5416a7c310f0b45"
"name": "Oui FM",
"language": "French",
"stream": "http://stream.ouifm.fr/ouifm-high.mp3"
},
{
"name": "Planet Rock",
"language": "English",
"stream": "http://live-bauer-mz.sharp-stream.com/planetrock.mp3"
},
{
"name": "Radio 538 (NL)",
"stream": "http://playerservices.streamtheworld.com/api/livestream-redirect/TLPSTR09.mp3"
"name": "Radio 538",
"language": "Dutch",
"stream": "http://18973.live.streamtheworld.com/RADIO538.mp3"
}
]
7 changes: 7 additions & 0 deletions javascript/features/radio/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,26 @@ class Channel {
if (!configuration.hasOwnProperty('name') || typeof configuration.name !== 'string')
throw new Error('The name of a radio channel must be set as a string.');

if (!configuration.hasOwnProperty('language') || typeof configuration.language !== 'string')
throw new Error('The language of a radio channel must be set as a string.');

if (!configuration.hasOwnProperty('stream') || typeof configuration.stream !== 'string')
throw new Error('The stream of a radio channel must be set as a string.');

if (!configuration.stream.startsWith('http'))
throw new Error('The stream of a radio channel must be a URL.');

this.name_ = configuration.name;
this.language_ = configuration.language;
this.stream_ = configuration.stream;
}

// Gets the name of this radio channel.
get name() { return this.name_; }

// Gets the language of this radio channel.
get language() { return this.language_; }

// Gets the stream URL of this radio channel.
get stream() { return this.stream_; }
}
Expand Down
2 changes: 2 additions & 0 deletions javascript/features/radio/channel_selection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ describe('ChannelSelection', (it, beforeEach, afterEach) => {
const TEST_RADIO_CONFIGURATION = [
{
name: "LVP Radio",
language: "English",
stream: "https://play.sa-mp.nl/stream.pls"
},
{
name: "Fantasy Radio",
language: "English",
stream: "https://example.com/stream.pls"
}
];
Expand Down
11 changes: 5 additions & 6 deletions javascript/features/radio/radio_commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ class RadioCommands {
return;
}

const menu = new Menu('In-game radio options', ['Channel', 'Selected']);
const menu = new Menu('In-game radio options', ['Channel', 'Language']);
const preferredChannel = this.manager_.getPreferredChannelForPlayer(player);

for (const channel of this.selection_.channels) {
const selected = channel === preferredChannel ? 'X' : '';

menu.addItem(channel.name, selected, async () => {
const highlight = channel === preferredChannel ? '{FFFF00}' : '';
menu.addItem(highlight + channel.name, highlight + channel.language, async () => {
this.manager_.setPreferredChannelForPlayer(player, channel);
await MessageBox.display(player, {
title: 'Radio preferences updated!',
Expand All @@ -46,8 +45,8 @@ class RadioCommands {
});
}

const disabled = !preferredChannel ? 'X' : '';
menu.addItem('{DDDDDD}Disable the radio', disabled, async () => {
const highlight = !preferredChannel ? '{FFFF00}' : '{999999}';
menu.addItem(highlight + 'Disable the radio', highlight + '-' /* language */, async () => {
this.manager_.setPreferredChannelForPlayer(player, null /* disabled */);
await MessageBox.display(player, {
title: 'Radio preferences updated!',
Expand Down
2 changes: 2 additions & 0 deletions javascript/features/radio/radio_manager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ describe('RadioManager', (it, beforeEach, afterEach) => {
selection.loadConfigurationFromArray([
{
name: "LVP Radio",
language: "English",
stream: "https://play.sa-mp.nl/stream.pls"
},
{
name: "Alternative Radio",
language: "English",
stream: "https://example.com/stream.pls"
}
]);
Expand Down

0 comments on commit 455660f

Please sign in to comment.