@@ -1,7 +1,7 @@ | |||
define([ | |||
'js/sound/sound' | |||
], function ( | |||
sound | |||
soundManager | |||
) { | |||
return { | |||
type: 'sound', | |||
@@ -10,8 +10,20 @@ define([ | |||
volume: 0, | |||
init: function () { | |||
let obj = this.obj; | |||
sound.addSound(obj.zoneId, this.sound, this.volume, obj.x, obj.y, obj.width, obj.height, obj.area); | |||
const { obj: { zoneId, x, y, width, height, area }, sound, volume, minDistance, fadeInOut } = this; | |||
soundManager.addSoundFromConfig({ | |||
scope: zoneId, | |||
file: sound, | |||
volume, | |||
x, | |||
y, | |||
w: width, | |||
h: height, | |||
area, | |||
minDistance, | |||
fadeInOut | |||
}); | |||
} | |||
}; | |||
}); |
@@ -58,46 +58,54 @@ define([ | |||
soundEntry.sound.play(); | |||
}, | |||
update: function (x, y) { | |||
update: function (playerX, playerY) { | |||
this.sounds.forEach(s => { | |||
const { x, y, w, area, sound, minDistance, fadeInOut } = s; | |||
let volume; | |||
if (!s.w) { | |||
let dx = Math.abs(s.x - x); | |||
if (dx > 10) { | |||
if (s.sound) | |||
s.sound.volume(0); | |||
if (!w) { | |||
let dx = Math.abs(x - playerX); | |||
if (dx >= minDistance) { | |||
if (sound) | |||
sound.volume(0); | |||
return; | |||
} | |||
let dy = Math.abs(s.y - y); | |||
if (dy > 10) { | |||
if (s.sound) | |||
s.sound.volume(0); | |||
let dy = Math.abs(y - playerY); | |||
if (dy >= minDistance) { | |||
if (sound) | |||
sound.volume(0); | |||
return; | |||
} | |||
let dist = 10 - Math.max(dx, dy); | |||
dist = (dist * dist) / 100; | |||
let dist = minDistance - Math.max(dx, dy); | |||
dist = (dist * dist) / Math.pow(minDistance, 2); | |||
volume = 0.3 * dist; | |||
} else if (physics.isInPolygon(x, y, s.area)) | |||
} else if (physics.isInPolygon(playerX, playerY, area)) | |||
volume = 0.3; | |||
else { | |||
let distance = physics.distanceToPolygon([x, y], s.area); | |||
if (distance > 10) { | |||
if (s.sound) | |||
s.sound.volume(0); | |||
let distance = physics.distanceToPolygon([playerX, playerY], area); | |||
if (distance >= minDistance) { | |||
if (sound) { | |||
if (fadeInOut) | |||
sound.fade(sound.volume(), 0, 3000); | |||
else | |||
sound.volume(0); | |||
} | |||
return; | |||
} | |||
let dist = 10 - distance; | |||
dist = (dist * dist) / 100; | |||
let dist = minDistance - distance; | |||
dist = (dist * dist) / Math.pow(minDistance, 2); | |||
volume = 0.3 * dist; | |||
} | |||
if (!s.sound) { | |||
if (!sound) { | |||
const file = s.file.includes('server') ? s.file : `audio/${s.file}`; | |||
//eslint-disable-next-line no-undef | |||
s.sound = new Howl({ | |||
src: ['audio/' + s.file], | |||
src: [file], | |||
autoplay: true, | |||
loop: true, | |||
volume: 0 | |||
@@ -107,12 +115,27 @@ define([ | |||
s.sound.mute(true); | |||
} | |||
if (!this.muted) | |||
s.sound.volume(volume * s.volume); | |||
if (this.muted) | |||
return; | |||
const oldVolume = s.sound.volume(); | |||
const newVolume = volume * s.volume; | |||
const volumeChanged = newVolume !== oldVolume; | |||
if (volumeChanged) { | |||
if (fadeInOut) | |||
s.sound.fade(oldVolume, newVolume, 3000); | |||
else | |||
s.sound.volume(newVolume); | |||
} | |||
}); | |||
}, | |||
addSound: function (scope, file, volume, x, y, w, h, area) { | |||
this.addSoundFromConfig({ scope, file, volume, x, y, w, h, area }); | |||
}, | |||
addSoundFromConfig: function ({ scope, file, volume, x, y, w, h, area, minDistance, fadeInOut }) { | |||
if (!area && w) { | |||
area = [ | |||
[x, y], | |||
@@ -131,7 +154,9 @@ define([ | |||
volume, | |||
area, | |||
sound: null, | |||
scope | |||
scope, | |||
minDistance, | |||
fadeInOut | |||
}; | |||
this.sounds.push(sound); | |||
@@ -3,12 +3,18 @@ module.exports = { | |||
sound: null, | |||
volume: 0, | |||
minDistance: 10, | |||
fadeInOut: false, | |||
simplify: function () { | |||
const { sound, volume, minDistance, fadeInOut } = this; | |||
return { | |||
type: 'sound', | |||
sound: this.sound, | |||
volume: this.volume | |||
sound, | |||
volume, | |||
minDistance, | |||
fadeInOut | |||
}; | |||
} | |||
}; |
@@ -1907,6 +1907,554 @@ | |||
"width":8, | |||
"x":1056, | |||
"y":920 | |||
}, | |||
{ | |||
"height":0, | |||
"id":993, | |||
"name":"", | |||
"polygon":[ | |||
{ | |||
"x":0, | |||
"y":0 | |||
}, | |||
{ | |||
"x":0, | |||
"y":112 | |||
}, | |||
{ | |||
"x":-72, | |||
"y":112 | |||
}, | |||
{ | |||
"x":-72, | |||
"y":120 | |||
}, | |||
{ | |||
"x":-80, | |||
"y":120 | |||
}, | |||
{ | |||
"x":-80, | |||
"y":112 | |||
}, | |||
{ | |||
"x":-96, | |||
"y":112 | |||
}, | |||
{ | |||
"x":-96, | |||
"y":128 | |||
}, | |||
{ | |||
"x":-96, | |||
"y":136 | |||
}, | |||
{ | |||
"x":-104, | |||
"y":136 | |||
}, | |||
{ | |||
"x":-104, | |||
"y":144 | |||
}, | |||
{ | |||
"x":-112, | |||
"y":144 | |||
}, | |||
{ | |||
"x":-112, | |||
"y":152 | |||
}, | |||
{ | |||
"x":-168, | |||
"y":152 | |||
}, | |||
{ | |||
"x":-168, | |||
"y":160 | |||
}, | |||
{ | |||
"x":-184, | |||
"y":160 | |||
}, | |||
{ | |||
"x":-184, | |||
"y":168 | |||
}, | |||
{ | |||
"x":-232, | |||
"y":168 | |||
}, | |||
{ | |||
"x":-232, | |||
"y":160 | |||
}, | |||
{ | |||
"x":-256, | |||
"y":160 | |||
}, | |||
{ | |||
"x":-256, | |||
"y":152 | |||
}, | |||
{ | |||
"x":-264, | |||
"y":152 | |||
}, | |||
{ | |||
"x":-264, | |||
"y":144 | |||
}, | |||
{ | |||
"x":-304, | |||
"y":144 | |||
}, | |||
{ | |||
"x":-304, | |||
"y":136 | |||
}, | |||
{ | |||
"x":-328, | |||
"y":136 | |||
}, | |||
{ | |||
"x":-328, | |||
"y":128 | |||
}, | |||
{ | |||
"x":-368, | |||
"y":128 | |||
}, | |||
{ | |||
"x":-368, | |||
"y":120 | |||
}, | |||
{ | |||
"x":-384, | |||
"y":120 | |||
}, | |||
{ | |||
"x":-384, | |||
"y":112 | |||
}, | |||
{ | |||
"x":-392, | |||
"y":112 | |||
}, | |||
{ | |||
"x":-392, | |||
"y":104 | |||
}, | |||
{ | |||
"x":-408, | |||
"y":104 | |||
}, | |||
{ | |||
"x":-408, | |||
"y":80 | |||
}, | |||
{ | |||
"x":-424, | |||
"y":80 | |||
}, | |||
{ | |||
"x":-424, | |||
"y":56 | |||
}, | |||
{ | |||
"x":-432, | |||
"y":56 | |||
}, | |||
{ | |||
"x":-432, | |||
"y":24 | |||
}, | |||
{ | |||
"x":-440, | |||
"y":24 | |||
}, | |||
{ | |||
"x":-440, | |||
"y":-8 | |||
}, | |||
{ | |||
"x":-416, | |||
"y":-8 | |||
}, | |||
{ | |||
"x":-416, | |||
"y":-16 | |||
}, | |||
{ | |||
"x":-408, | |||
"y":-16 | |||
}, | |||
{ | |||
"x":-408, | |||
"y":-24 | |||
}, | |||
{ | |||
"x":-384, | |||
"y":-24 | |||
}, | |||
{ | |||
"x":-384, | |||
"y":-32 | |||
}, | |||
{ | |||
"x":-360, | |||
"y":-32 | |||
}, | |||
{ | |||
"x":-360, | |||
"y":-80 | |||
}, | |||
{ | |||
"x":-368, | |||
"y":-80 | |||
}, | |||
{ | |||
"x":-368, | |||
"y":-88 | |||
}, | |||
{ | |||
"x":-392, | |||
"y":-88 | |||
}, | |||
{ | |||
"x":-392, | |||
"y":-96 | |||
}, | |||
{ | |||
"x":-400, | |||
"y":-96 | |||
}, | |||
{ | |||
"x":-400, | |||
"y":-104 | |||
}, | |||
{ | |||
"x":-584, | |||
"y":-104 | |||
}, | |||
{ | |||
"x":-584, | |||
"y":-216 | |||
}, | |||
{ | |||
"x":0, | |||
"y":-216 | |||
}], | |||
"properties":[ | |||
{ | |||
"name":"cpnSound", | |||
"type":"string", | |||
"value":"{\"sound\":\"server\/mods\/iwd-ui-sounds\/audio\/music\/fjol_town.ogg\",\"volume\":0.5,\"minDistance\":0, \"fadeInOut\": true}" | |||
}], | |||
"rotation":0, | |||
"type":"", | |||
"visible":true, | |||
"width":0, | |||
"x":936, | |||
"y":344 | |||
}, | |||
{ | |||
"height":0, | |||
"id":994, | |||
"name":"", | |||
"polygon":[ | |||
{ | |||
"x":0, | |||
"y":0 | |||
}, | |||
{ | |||
"x":8, | |||
"y":0 | |||
}, | |||
{ | |||
"x":8, | |||
"y":8 | |||
}, | |||
{ | |||
"x":16, | |||
"y":8 | |||
}, | |||
{ | |||
"x":16, | |||
"y":16 | |||
}, | |||
{ | |||
"x":40, | |||
"y":16 | |||
}, | |||
{ | |||
"x":40, | |||
"y":24 | |||
}, | |||
{ | |||
"x":48, | |||
"y":24 | |||
}, | |||
{ | |||
"x":48, | |||
"y":72 | |||
}, | |||
{ | |||
"x":24, | |||
"y":72 | |||
}, | |||
{ | |||
"x":24, | |||
"y":80 | |||
}, | |||
{ | |||
"x":0, | |||
"y":80 | |||
}, | |||
{ | |||
"x":0, | |||
"y":88 | |||
}, | |||
{ | |||
"x":-8, | |||
"y":88 | |||
}, | |||
{ | |||
"x":-8, | |||
"y":96 | |||
}, | |||
{ | |||
"x":-32, | |||
"y":96 | |||
}, | |||
{ | |||
"x":-32, | |||
"y":128 | |||
}, | |||
{ | |||
"x":-24, | |||
"y":128 | |||
}, | |||
{ | |||
"x":-24, | |||
"y":160 | |||
}, | |||
{ | |||
"x":-16, | |||
"y":160 | |||
}, | |||
{ | |||
"x":-16, | |||
"y":184 | |||
}, | |||
{ | |||
"x":0, | |||
"y":184 | |||
}, | |||
{ | |||
"x":0, | |||
"y":208 | |||
}, | |||
{ | |||
"x":16, | |||
"y":208 | |||
}, | |||
{ | |||
"x":16, | |||
"y":216 | |||
}, | |||
{ | |||
"x":24, | |||
"y":216 | |||
}, | |||
{ | |||
"x":24, | |||
"y":224 | |||
}, | |||
{ | |||
"x":40, | |||
"y":224 | |||
}, | |||
{ | |||
"x":40, | |||
"y":232 | |||
}, | |||
{ | |||
"x":80, | |||
"y":232 | |||
}, | |||
{ | |||
"x":80, | |||
"y":240 | |||
}, | |||
{ | |||
"x":104, | |||
"y":240 | |||
}, | |||
{ | |||
"x":104, | |||
"y":248 | |||
}, | |||
{ | |||
"x":144, | |||
"y":248 | |||
}, | |||
{ | |||
"x":144, | |||
"y":256 | |||
}, | |||
{ | |||
"x":152, | |||
"y":256 | |||
}, | |||
{ | |||
"x":152, | |||
"y":264 | |||
}, | |||
{ | |||
"x":176, | |||
"y":264 | |||
}, | |||
{ | |||
"x":176, | |||
"y":272 | |||
}, | |||
{ | |||
"x":224, | |||
"y":272 | |||
}, | |||
{ | |||
"x":224, | |||
"y":264 | |||
}, | |||
{ | |||
"x":240, | |||
"y":264 | |||
}, | |||
{ | |||
"x":240, | |||
"y":256 | |||
}, | |||
{ | |||
"x":296, | |||
"y":256 | |||
}, | |||
{ | |||
"x":296, | |||
"y":248 | |||
}, | |||
{ | |||
"x":304, | |||
"y":248 | |||
}, | |||
{ | |||
"x":304, | |||
"y":240 | |||
}, | |||
{ | |||
"x":312, | |||
"y":240 | |||
}, | |||
{ | |||
"x":312, | |||
"y":216 | |||
}, | |||
{ | |||
"x":328, | |||
"y":216 | |||
}, | |||
{ | |||
"x":328, | |||
"y":224 | |||
}, | |||
{ | |||
"x":336, | |||
"y":224 | |||
}, | |||
{ | |||
"x":336, | |||
"y":216 | |||
}, | |||
{ | |||
"x":408, | |||
"y":216 | |||
}, | |||
{ | |||
"x":408, | |||
"y":-112 | |||
}, | |||
{ | |||
"x":592, | |||
"y":-232 | |||
}, | |||
{ | |||
"x":1024, | |||
"y":-232 | |||
}, | |||
{ | |||
"x":1024, | |||
"y":368 | |||
}, | |||
{ | |||
"x":1024, | |||
"y":1192 | |||
}, | |||
{ | |||
"x":1024, | |||
"y":1264 | |||
}, | |||
{ | |||
"x":856, | |||
"y":1264 | |||
}, | |||
{ | |||
"x":472, | |||
"y":1264 | |||
}, | |||
{ | |||
"x":152, | |||
"y":1264 | |||
}, | |||
{ | |||
"x":-256, | |||
"y":1256 | |||
}, | |||
{ | |||
"x":-424, | |||
"y":1048 | |||
}, | |||
{ | |||
"x":-360, | |||
"y":752 | |||
}, | |||
{ | |||
"x":-152, | |||
"y":536 | |||
}, | |||
{ | |||
"x":-168, | |||
"y":376 | |||
}, | |||
{ | |||
"x":-184, | |||
"y":48 | |||
}, | |||
{ | |||
"x":-64, | |||
"y":8 | |||
}], | |||
"properties":[ | |||
{ | |||
"name":"cpnSound", | |||
"type":"string", | |||
"value":"{\"sound\":\"server\/mods\/iwd-ui-sounds\/audio\/music\/fjol_wild.ogg\",\"volume\":0.5,\"minDistance\":0, \"fadeInOut\": true}" | |||
}], | |||
"rotation":0, | |||
"type":"", | |||
"visible":true, | |||
"width":0, | |||
"x":528, | |||
"y":240 | |||
}], | |||
"opacity":1, | |||
"type":"objectgroup", | |||
@@ -4218,7 +4766,7 @@ | |||
"y":0 | |||
}], | |||
"nextlayerid":31, | |||
"nextobjectid":991, | |||
"nextobjectid":995, | |||
"orientation":"orthogonal", | |||
"properties":[ | |||
{ | |||