You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

103 lines
2.0 KiB

  1. define([
  2. 'js/system/globals'
  3. ], function (
  4. globals
  5. ) {
  6. let mRandom = Math.random.bind(Math);
  7. let customRenderer = null;
  8. const renderCustomLoginBg = async (renderer, path) => {
  9. if (!customRenderer) {
  10. await (new Promise(res => {
  11. require([path], loadedModule => {
  12. customRenderer = loadedModule;
  13. res();
  14. });
  15. }));
  16. }
  17. customRenderer(renderer);
  18. };
  19. const renderLoginBackground = renderer => {
  20. const { loginBgGeneratorPath } = globals.clientConfig;
  21. if (loginBgGeneratorPath) {
  22. renderCustomLoginBg(renderer, loginBgGeneratorPath);
  23. return;
  24. }
  25. const { width, height, layers } = renderer;
  26. let w = Math.ceil(width / scale) + 1;
  27. let h = Math.ceil(height / scale) + 1;
  28. renderer.setPosition({
  29. pos: {
  30. x: w / 2,
  31. y: h / 2
  32. },
  33. instant: true
  34. });
  35. const midX = ~~(w / 2);
  36. const midY = ~~(h / 2);
  37. const rGrass = 10;
  38. const rBeach = 2;
  39. const rShallow = 3;
  40. const noiseFactor = 3;
  41. let container = layers.tileSprites;
  42. for (let i = 0; i < w; i++) {
  43. for (let j = 0; j < h; j++) {
  44. let tile = 5;
  45. let distance = Math.sqrt(Math.pow(i - midX, 2) + Math.pow(j - midY, 2));
  46. if (distance < rGrass + (Math.random() * noiseFactor))
  47. tile = 3;
  48. else if (distance < rGrass + rBeach + (Math.random() * noiseFactor))
  49. tile = 4;
  50. else if (distance < rGrass + rBeach + rShallow + (Math.random() * noiseFactor))
  51. tile = 53;
  52. let alpha = mRandom();
  53. if ([5, 53].indexOf(tile) > -1)
  54. alpha *= 2;
  55. if (Math.random() < 0.3) {
  56. tile = {
  57. 5: 6,
  58. 3: 0,
  59. 4: 1,
  60. 53: 54
  61. }[tile];
  62. }
  63. let sprite = new PIXI.Sprite(renderer.getTexture('sprites', tile));
  64. alpha = Math.min(Math.max(0.15, alpha), 0.65);
  65. sprite.alpha = alpha;
  66. sprite.position.x = i * scale;
  67. sprite.position.y = j * scale;
  68. sprite.width = scale;
  69. sprite.height = scale;
  70. if (mRandom() < 0.5) {
  71. sprite.position.x += scale;
  72. sprite.scale.x = -scaleMult;
  73. }
  74. container.addChild(sprite);
  75. }
  76. }
  77. };
  78. return renderLoginBackground;
  79. });