Skip to content

Commit

Permalink
Merge pull request FreezingMoon#2266 from andretchen0/soundsys
Browse files Browse the repository at this point in the history
New Sound System API, fixes FreezingMoon#2264
  • Loading branch information
DreadKnight authored Apr 28, 2023
2 parents d7365da + 0577200 commit e72abe1
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 126 deletions.
2 changes: 1 addition & 1 deletion src/abilities/Bounty-Hunter.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ export default (G) => {
];

hex.createTrap('mud-bath', effects, ability.creature.player);
G.soundsys.playSound(G.soundLoaded[7], G.soundsys.effectsGainNode);
G.soundsys.playSFX('sounds/mudbath');
// Trigger trap immediately if on self
if (isSelf) {
// onCreatureMove is Spa Goggles' trigger event
Expand Down
2 changes: 1 addition & 1 deletion src/abilities/Swine-Thug.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ export default (G) => {
];

hex.createTrap('mud-bath', effects, ability.creature.player);
G.soundsys.playSound(G.soundLoaded[7], G.soundsys.effectsGainNode);
G.soundsys.playSFX('sounds/mudbath');
// Trigger trap immediately if on self
if (isSelf) {
// onCreatureMove is Spa Goggles' trigger event
Expand Down
2 changes: 1 addition & 1 deletion src/ability.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ export class Ability {

setTimeout(() => {
if (!game.triggers.onUnderAttack.test(this.getTrigger())) {
game.soundsys.playSound(game.soundLoaded[2], game.soundsys.effectsGainNode);
game.soundsys.playSFX('sounds/swing2');
activateAbility();
}
}, animationData.delay);
Expand Down
6 changes: 3 additions & 3 deletions src/animations.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class Animations {
}

// Sound Effect
game.soundsys.playSound(game.soundLoaded[0], game.soundsys.effectsGainNode);
game.soundsys.playSFX('sounds/step');

if (!opts.ignoreMovementPoint) {
creature.remainingMove--;
Expand Down Expand Up @@ -115,7 +115,7 @@ export class Animations {

tween.onComplete.add(() => {
// Sound Effect
game.soundsys.playSound(game.soundLoaded[0], game.soundsys.effectsGainNode);
game.soundsys.playSFX('sounds/step');

if (!opts.ignoreMovementPoint) {
// Determine distance
Expand Down Expand Up @@ -165,7 +165,7 @@ export class Animations {

tween.onComplete.add(() => {
// Sound Effect
game.soundsys.playSound(game.soundLoaded[0], game.soundsys.effectsGainNode);
game.soundsys.playSFX('sounds/step');

// position
creature.grp.x = currentHex.displayPos.x;
Expand Down
41 changes: 18 additions & 23 deletions src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,6 @@ export default class Game {
this.matchInitialized = false;
this.realms = ['A', 'E', 'G', 'L', 'P', 'S', 'W'];
this.availableMusic = [];
this.soundEffects = [
'sounds/step',
'sounds/swing',
'sounds/swing2',
'sounds/swing3',
'sounds/heartbeat',
'sounds/drums',
'sounds/upgrade',
'sounds/mudbath',
'sounds/AncientBeast',
];
this.inputMethod = 'Mouse';

// Gameplay properties
Expand Down Expand Up @@ -207,7 +196,7 @@ export default class Game {
creature.type = type;

// Load unit shouts
this.soundsys.getSound(getUrl('units/shouts/' + name), 1000 + creatureId);
this.soundsys.loadSound('units/shouts/' + name);

// Load artwork
this.getImage(getUrl('units/artwork/' + name));
Expand Down Expand Up @@ -258,8 +247,6 @@ export default class Game {
this.matchid = matchid;
}

let totalSoundEffects = this.soundEffects.length,
i;
this.gameState = 'loading';
if (setupOpt) {
this.gamelog.gameConfig = setupOpt;
Expand All @@ -270,18 +257,26 @@ export default class Game {
this.startLoading();

// Sounds
this.musicPlayer = new MusicPlayer();
this.soundLoaded = {};
this.soundsys = new SoundSys({}, this);
const paths = [
'sounds/step',
'sounds/swing',
'sounds/swing2',
'sounds/swing3',
'sounds/heartbeat',
'sounds/drums',
'sounds/upgrade',
'sounds/mudbath',
'sounds/AncientBeast',
];

for (i = 0; i < totalSoundEffects; i++) {
this.soundsys.getSound(getUrl(this.soundEffects[i]), this.availableMusic.length + i);
}
this.soundsys = new SoundSys({ paths });
this.musicPlayer = this.soundsys.musicPlayer;

this.Phaser.load.onFileComplete.add(this.loadFinish, this);

// Health
let playerColors = ['red', 'blue', 'orange', 'green'];
let i;
for (i = 0; i < 4; i++) {
this.Phaser.load.image('p' + i + '_health', getUrl('interface/rectangle_' + playerColors[i]));
this.Phaser.load.image('p' + i + '_plasma', getUrl('interface/capsule_' + playerColors[i]));
Expand Down Expand Up @@ -753,7 +748,7 @@ export default class Game {

// Play heartbeat sound on other player's turn
if (differentPlayer) {
this.soundsys.playSound(this.soundLoaded[4], this.soundsys.heartbeatGainNode);
this.soundsys.playHeartBeat('sounds/heartbeat');
}

this.log('Active Creature : %CreatureName' + this.activeCreature.id + '%');
Expand Down Expand Up @@ -1422,7 +1417,7 @@ export default class Game {
*/
endGame() {
this.soundsys.stopMusic();
this.endGameSound = this.soundsys.playSound(this.soundLoaded[5], this.soundsys.effectsGainNode);
this.endGameSound = this.soundsys.playSFX('sounds/drums');

this.stopTimer();
this.gameState = 'ended';
Expand Down Expand Up @@ -1538,7 +1533,7 @@ export default class Game {
}

resetGame() {
this.endGameSound.stop();
this.endGameSound.pause();
this.UI.showGameSetup();
this.stopTimer(this.timeInterval);
this.players = [];
Expand Down
2 changes: 1 addition & 1 deletion src/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@
</div>
<div style="position:relative">
<b style="position:absolute; right:43px; top:8px; color:grey;">+</b>
<input id="sfx" class="slider" type="range" min="0" max="10" value="5" step="0.2">
<input id="sfx" class="slider" type="range" min="0" max="1" value="1" step="0.02">
<b style="position:absolute; left:43px; top:8px; color:grey; rotate:90deg;">-</b>
</div>
</div>
Expand Down
7 changes: 2 additions & 5 deletions src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,8 @@ export class Player {
temp: false,
}); // Create the full data for creature creation

for (let i = game.creatureData.length - 1; i >= 0; i--) {
// Avoid Dark Priest shout at the begining of a match
if (game.creatureData[i].type == type && i !== 0) {
game.soundsys.playSound(game.soundLoaded[1000 + i], game.soundsys.announcerGainNode);
}
if (data.name !== 'Dark Priest') {
game.soundsys.playShout(data.name);
}

creature = new Creature(data, game);
Expand Down
83 changes: 0 additions & 83 deletions src/sound/soundsys.js

This file was deleted.

Loading

0 comments on commit e72abe1

Please sign in to comment.