RememberedHandler.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /// <reference path="../../World/Classes/Action/ActionRetrace.ts" />
  2. /// <reference path="../../World/Classes/Action/ActionGo.ts" />
  3. /// <reference path="../../Controls/Modules/Links.ts" />
  4. /// <reference path="../Elements.ts" />
  5. /// <reference path="HoverInfo.ts" />
  6. /// <reference path="../Classes/RoomNode.ts" />
  7. module Elements.RememberedHandler {
  8. //var target = document.getElementById("rememberedRoomsTarget");
  9. var mapTarget = document.getElementById("mapTarget");
  10. var lastMap : RoomRandomMap;
  11. var elements : { [xy : string] : RoomNode};
  12. export function empty () {
  13. // while (target.firstChild) {
  14. // target.removeChild(target.firstChild);
  15. // }
  16. elements = {};
  17. lastMap = undefined;
  18. while (mapTarget.firstChild) {
  19. mapTarget.removeChild(mapTarget.firstChild);
  20. }
  21. }
  22. export async function updateMap () {
  23. console.debug(Rulebook.getIndentation() + "[MAP] Creating Map");
  24. let regions = Region.InRelation.getAllLeftType(WorldState.player.getRoom(), RegionRandom);
  25. let biggestRegion = <RegionRandom> regions[regions.length - 1];
  26. if (biggestRegion == undefined) {
  27. empty();
  28. return;
  29. }
  30. if (biggestRegion.map != lastMap) {
  31. empty();
  32. } else {
  33. await updateOldMap();
  34. return;
  35. }
  36. let map = biggestRegion.map;
  37. lastMap = map;
  38. map.updateAllLimits();
  39. for (let y = map.highestY; y >= map.lowestY; y--) {
  40. let row = document.createElement("div");
  41. row.classList.add("mapRow");
  42. for (let x = map.lowestX; x <= map.highestX; x++) {
  43. let room = map.getRoom(x, y);
  44. let roomNode = new RoomNode(room);
  45. await roomNode.createRoomNameFloater();
  46. let roomDiv = roomNode.getElement();
  47. row.appendChild(roomDiv);
  48. elements[x.toString() + ";" + y.toString()] = roomNode;
  49. }
  50. mapTarget.appendChild(row);
  51. }
  52. await updateOldMap();
  53. }
  54. export async function updateOldMap () {
  55. let map = lastMap;
  56. for (let y = map.highestY; y >= map.lowestY; y--) {
  57. for (let x = map.lowestX; x <= map.highestX; x++) {
  58. await elements[x.toString() + ";" + y.toString()].update();
  59. }
  60. }
  61. }
  62. }