17 lines
484 B
JavaScript
17 lines
484 B
JavaScript
import Phaser from '../vendor/phaser.js';
|
|
|
|
/**
|
|
* Converts a config color (number or CSS string like '#1b2540')
|
|
* into the integer format Phaser expects.
|
|
*/
|
|
export function toColor(value, fallback = 0xffffff) {
|
|
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
return value >>> 0;
|
|
}
|
|
if (typeof value === 'string' && value.length > 0) {
|
|
const color = Phaser.Display.Color.ValueToColor(value.trim());
|
|
if (color) return color.color;
|
|
}
|
|
return fallback;
|
|
}
|