@urso/core 0.7.30 → 0.7.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@urso/core",
3
- "version": "0.7.30",
3
+ "version": "0.7.32",
4
4
  "description": "HTML5 game engine",
5
5
  "main": "build/js/index.js",
6
6
  "author": "Megbrimef",
@@ -599,6 +599,67 @@ class LibHelper {
599
599
 
600
600
  return string
601
601
  }
602
+
603
+ /**
604
+ * Converts color number to object that contents RGB values
605
+ * @param { Number } color - color number
606
+ * @returns { Object }
607
+ */
608
+ getRGB(color) {
609
+ return {
610
+ alpha: 16777215 < color ? color >>> 24 : 255,
611
+ red: color >> 16 & 255,
612
+ green: color >> 8 & 255,
613
+ blue: 255 & color
614
+ };
615
+ }
616
+
617
+ /**
618
+ * Converts RGB values to 32 bit
619
+ * @param { Number } alpha
620
+ * @param { Number } red
621
+ * @param { Number } green
622
+ * @param { Number } blue
623
+ * @returns { Number }
624
+ */
625
+ getColor32(alpha, red, green, blue) {
626
+ return alpha << 24 | red << 16 | green << 8 | blue;
627
+ }
628
+
629
+ /**
630
+ * Returns color interpolation depends on step value
631
+ * @param { Number } startColor
632
+ * @param { Number } targetColor
633
+ * @param { Number } step - intermediate value from 0 to 1
634
+ * @returns { Number }
635
+ */
636
+ interpolateColor32(startColor, targetColor, step) {
637
+ if(startColor === targetColor)
638
+ return startColor;
639
+
640
+ const startColorRGB = this.getRGB(startColor);
641
+ const targetColorRGB = this.getRGB(targetColor);
642
+ const nextColorRGB = this.interpolateColorRGB(startColorRGB, targetColorRGB, step);
643
+ const color32 = this.getColor32(255, nextColorRGB.red, nextColorRGB.green, nextColorRGB.blue);
644
+ return 16777215 + color32;
645
+ }
646
+
647
+ /**
648
+ * Returns color interpolation as RGB object depends on step value
649
+ * @param { Object } startColorRGB - object that contents start values for red, green and blue
650
+ * @param { Object } targetColorRGB - object that contents target values for red, green and blue
651
+ * @param { Number } step - intermediate value from 0 to 1
652
+ * @returns { Object }
653
+ */
654
+ interpolateColorRGB(startColorRGB, targetColorRGB, step) {
655
+ const nextRGB = {};
656
+
657
+ Object.keys(startColorRGB).forEach(color => {
658
+ nextRGB[color] = (targetColorRGB[color] - startColorRGB[color]) * step + startColorRGB[color];
659
+ });
660
+
661
+ return nextRGB;
662
+ }
602
663
  }
603
664
 
604
665
  module.exports = LibHelper;
@@ -85,8 +85,10 @@ class SoundSprite {
85
85
  this.setRelaunch(soundKey, relaunch);
86
86
  this.setLoop(soundKey, loop);
87
87
 
88
- if (resetVolume)
89
- this.setVolume({ soundKey, volume });
88
+ if (!resetVolume) //set saved volume value
89
+ volume = this._soundsState[soundKey].volume
90
+
91
+ this.setVolume({ soundKey, volume });
90
92
 
91
93
  return true;
92
94
  };