МУРОМ является долговечным игровым редактором, работающим в браузере | MUROM is a durable game editor working in a browser http://opengamestudio.org/murom
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.

167 lines
3.4KB

  1. /*
  2. *
  3. * Скачиваемый файл / Downloaded file
  4. *
  5. */
  6. муром.файл = {};
  7. муром.файл.начало =
  8. `
  9. <!DOCTYPE html>
  10. <html>
  11. <meta charset="utf-8">
  12. <meta name="viewport" content="width=device-width, initial-scale=1">
  13. <body>
  14. <script>
  15. var муром = {};
  16. var murom = муром;
  17. муром.модули = [
  18. `;
  19. муром.файл.конец =
  20. `
  21. ];
  22. Object.defineProperty(murom, "modules", {
  23. get: function()
  24. {
  25. return муром.модули;
  26. },
  27. set: function(значения)
  28. {
  29. муром.модули = значения;
  30. }
  31. });
  32. var загрузочныйМодуль = муром.модули[0];
  33. var код = atob(загрузочныйМодуль[1]);
  34. eval(код);
  35. </script>
  36. </body>
  37. </html>
  38. `;
  39. /*
  40. *
  41. * UUID
  42. *
  43. */
  44. // Create GUID / UUID in JavaScript?
  45. // https://stackoverflow.com/a/2117523
  46. муром.uuid = function()
  47. {
  48. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
  49. /[xy]/g,
  50. function(c)
  51. {
  52. var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
  53. return v.toString(16);
  54. }
  55. );
  56. };
  57. /*
  58. *
  59. * Уведомитель / Reporter
  60. *
  61. */
  62. // ReporterSubscription class.
  63. function ReporterSubscription(id, callback, reporter)
  64. {
  65. this.id = id;
  66. this.callback = callback;
  67. this.reporter = reporter;
  68. }
  69. // Reporter class.
  70. function Reporter(name)
  71. {
  72. this.name =
  73. (typeof name !== "undefined") ?
  74. name :
  75. "";
  76. this.subscriptions = [];
  77. }
  78. Reporter.prototype.report = function()
  79. {
  80. for (var id in this.subscriptions)
  81. {
  82. var subscription = this.subscriptions[id];
  83. subscription.callback();
  84. }
  85. }
  86. Reporter.prototype.subscribe = function(callback)
  87. {
  88. var id = murom.uuid();
  89. var subscription = new ReporterSubscription(id, callback, this);
  90. this.subscriptions.push(subscription);
  91. return subscription;
  92. }
  93. Reporter.prototype.subscribeMany = function(funcs)
  94. {
  95. for (var i = 0; i < funcs.length; ++i)
  96. {
  97. var func = funcs[i];
  98. this.subscribe(func);
  99. }
  100. }
  101. var Уведомитель = Reporter;
  102. Reporter.prototype.уведомить = function()
  103. {
  104. this.report();
  105. };
  106. Reporter.prototype.подписать = function(функция)
  107. {
  108. this.subscribe(функция);
  109. };
  110. Reporter.prototype.подписатьМного = function(funcs)
  111. {
  112. this.subscribeMany(funcs);
  113. };
  114. /*
  115. *
  116. * Пуск / Start
  117. *
  118. */
  119. муром.пуск = new Уведомитель();
  120. // Can also be accessed as 'murom.run'.
  121. Object.defineProperty(murom, "run", {
  122. get: function()
  123. {
  124. return муром.пуск;
  125. }
  126. });
  127. murom.start = function()
  128. {
  129. муром.пуск.уведомить();
  130. };
  131. /*
  132. *
  133. * Левая и правая области / Left and right regions
  134. *
  135. */
  136. муром.создатьЛевуюПравуюОбласти = function()
  137. {
  138. // Левая область.
  139. var ло = document.createElement("div");
  140. ло.id="левая-область";
  141. ло.style.cssText =
  142. "position: fixed; left: 0; top: 0; bottom: 0; width: 50%;";
  143. document.body.appendChild(ло);
  144. // Правая область.
  145. var по = document.createElement("div");
  146. по.id="правая-область";
  147. по.style.cssText =
  148. "position: fixed; right: 0; top: 0; bottom: 0; width: 50%;";
  149. document.body.appendChild(по);
  150. return [ло, по];
  151. };