tools/map_templates_tool/main.qml
author unC0Rr
Tue, 17 Dec 2024 15:44:21 +0100
branchtransitional_engine
changeset 16049 db18f1a30b0c
parent 16044 5c941f5deeec
permissions -rw-r--r--
Implement passing of available ammo to rust AI
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16043
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
     1
import QtQuick
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
     2
import QtQuick.Controls
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
     3
import QtQuick.Layouts
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
     4
import QtQuick.Shapes
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
     5
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
     6
Window {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
     7
  id: control
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
     8
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
     9
  width: 1024
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    10
  height: 768
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    11
  visible: true
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    12
  title: qsTr("Map Templates")
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    13
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    14
  property bool hasError: false
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    15
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    16
  Page {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    17
    id: page
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    18
    anchors.fill: parent
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    19
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    20
    Rectangle {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    21
      id: mapContainer
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    22
16044
5c941f5deeec * Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents: 16043
diff changeset
    23
      property int spaceForCode: Math.max(250, parent.height * 0.6)
16043
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    24
      property int mapWidth: 2048
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    25
      property int mapHeight: 1024
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    26
      property real aspectRatio: mapWidth / mapHeight
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    27
      property bool fitWidth: aspectRatio > (parent.width / (parent.height - spaceForCode))
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    28
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    29
      implicitWidth: fitWidth ? parent.width : (parent.height - spaceForCode) * aspectRatio
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    30
      implicitHeight: fitWidth ? parent.width / aspectRatio : (parent.height - spaceForCode)
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    31
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    32
      x: (parent.width - width) / 2
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    33
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    34
      border.width: 2
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    35
      border.color: hasError ? "red" : "black"
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    36
    }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    37
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    38
    Shape {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    39
      id: shape
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    40
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    41
      anchors.fill: mapContainer
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    42
    }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    43
16044
5c941f5deeec * Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents: 16043
diff changeset
    44
    MouseArea {
5c941f5deeec * Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents: 16043
diff changeset
    45
      id: mouseArea
5c941f5deeec * Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents: 16043
diff changeset
    46
      anchors.fill: mapContainer
5c941f5deeec * Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents: 16043
diff changeset
    47
      hoverEnabled: true
5c941f5deeec * Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents: 16043
diff changeset
    48
    }
5c941f5deeec * Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents: 16043
diff changeset
    49
5c941f5deeec * Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents: 16043
diff changeset
    50
    Label {
5c941f5deeec * Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents: 16043
diff changeset
    51
      text: mouseArea.containsMouse ? "(%1, %2)".arg(Math.floor(mouseArea.mouseX / mouseArea.width * mapContainer.mapWidth)).arg(Math.floor(mouseArea.mouseY / mouseArea.height * mapContainer.mapHeight)) : ""
5c941f5deeec * Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents: 16043
diff changeset
    52
    }
5c941f5deeec * Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents: 16043
diff changeset
    53
16043
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    54
    Rectangle {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    55
      anchors.fill: codeInput
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    56
      color: "gray"
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    57
    }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    58
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    59
    TextEdit {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    60
      id: codeInput
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    61
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    62
      anchors.bottom: parent.bottom
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    63
      anchors.left: parent.left
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    64
      anchors.right: parent.right
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    65
      height: parent.height - mapContainer.height
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    66
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    67
      text: "  -
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    68
    width: 3072
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    69
    height: 1424
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    70
    can_flip: false
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    71
    can_invert: false
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    72
    can_mirror: true
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    73
    is_negative: false
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    74
    put_girders: true
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    75
    max_hedgehogs: 18
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    76
    outline_points:
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    77
      -
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    78
        - {x: 748, y: 1424, w: 1, h: 1}
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    79
        - {x: 636, y: 1252, w: 208, h: 72}
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    80
        - {x: 898, y: 1110, w: 308, h: 60}
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    81
        - {x: 1128, y: 1252, w: 434, h: 40}
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    82
        - {x: 1574, y: 1112, w: 332, h: 40}
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    83
        - {x: 1802, y: 1238, w: 226, h: 36}
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    84
        - {x: 1930, y: 1424, w: 1, h: 1}
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    85
      -
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    86
        - {x: 2060, y: 898, w: 111, h: 111}
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    87
        - {x: 1670, y: 876, w: 34, h: 102}
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    88
        - {x: 1082, y: 814, w: 284, h: 132}
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    89
        - {x: 630, y: 728, w: 126, h: 168}
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    90
        - {x: 810, y: 574, w: 114, h: 100}
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    91
        - {x: 1190, y: 572, w: 352, h: 120}
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    92
        - {x: 1674, y: 528, w: 60, h: 240}
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    93
        - {x: 1834, y: 622, w: 254, h: 116}
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    94
    fill_points:
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    95
      - {x: 1423, y: 0}
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    96
"
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    97
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    98
      onTextChanged: {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
    99
        const template = parseInput()
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   100
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   101
        if (template) {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   102
          mapContainer.mapWidth = Number(template.width)
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   103
          mapContainer.mapHeight = Number(template.height)
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   104
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   105
          shape.data = renderTemplate(template)
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   106
        }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   107
      }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   108
    }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   109
  }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   110
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   111
  function parseInput() {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   112
    let code = codeInput.text.split('\n')
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   113
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   114
    if(code[0] !== "  -") {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   115
      hasError = true
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   116
      return
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   117
    }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   118
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   119
    code = code.slice(1)
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   120
    code.push("")
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   121
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   122
    let parsed = ({})
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   123
    let polygonAccumulator = []
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   124
    let pointAccumulator = []
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   125
    let key = ""
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   126
    code.forEach(line => {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   127
                   let newKey
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   128
                   if (line === "    outline_points:") {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   129
                     newKey = "outline_points"
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   130
                   }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   131
16044
5c941f5deeec * Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents: 16043
diff changeset
   132
                   if (line === "    walls:") {
5c941f5deeec * Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents: 16043
diff changeset
   133
                     newKey = "walls"
16043
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   134
                   }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   135
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   136
                   if (line === "    fill_points:") {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   137
                     newKey = "fill_points"
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   138
                   }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   139
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   140
                   if (line === "") {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   141
                     newKey = "_"
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   142
                   }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   143
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   144
                   if (key === "fill_points" && line.startsWith("      - {")) {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   145
                     // ignore
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   146
                     return
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   147
                   }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   148
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   149
                   if (newKey) {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   150
                     if (key.length > 0) {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   151
                       polygonAccumulator.push(pointAccumulator)
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   152
                       parsed[key] = polygonAccumulator
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   153
                     }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   154
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   155
                     key = newKey
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   156
                     polygonAccumulator = []
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   157
                     pointAccumulator = []
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   158
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   159
                     return
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   160
                   }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   161
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   162
                   if (line === "      -") {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   163
                    if (pointAccumulator.length > 0) {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   164
                       polygonAccumulator.push(pointAccumulator)
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   165
                       pointAccumulator = []
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   166
                     }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   167
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   168
                     return
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   169
                   }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   170
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   171
                   const matchValue = line.match(/^\s{4}(\w+):\s(.+)$/);
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   172
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   173
                   if (matchValue) {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   174
                     parsed[matchValue[1]] = matchValue[2]
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   175
                     return
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   176
                   }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   177
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   178
                   const matchPoint = line.match(/^\s{8}-\s\{([^}]+)\}$/);
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   179
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   180
                   if (matchPoint) {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   181
                    const point = matchPoint[1].split(", ").reduce((obj, pair) => {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   182
                                                              const [key, value] = pair.split(": ");
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   183
                                                              obj[key] = isNaN(value) ? value : parseInt(value);
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   184
                                                              return obj;
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   185
                                                            }, {})
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   186
                    pointAccumulator.push(point)
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   187
                    return
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   188
                   }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   189
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   190
                   console.log("Unrecognized: " + JSON.stringify(line))
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   191
                   hasError = true
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   192
                   throw ""
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   193
                 })
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   194
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   195
    hasError = false
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   196
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   197
    return parsed
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   198
  }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   199
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   200
  Component {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   201
    id: shapePathComponent
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   202
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   203
    ShapePath {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   204
      fillColor: "transparent"
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   205
      scale: Qt.size(mapContainer.width / mapContainer.mapWidth, mapContainer.height / mapContainer.mapHeight)
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   206
      strokeWidth: 3
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   207
    }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   208
  }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   209
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   210
  Component {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   211
    id: pathLineComponent
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   212
    PathLine {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   213
    }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   214
  }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   215
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   216
  function polygons2shapes(polygons, lineColor, rectColor) {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   217
    if (!Array.isArray(polygons)) {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   218
      return []
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   219
    }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   220
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   221
    let rectangles = []
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   222
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   223
    polygons.forEach(polygon => polygon.forEach(r => {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   224
                                                   let shapePath = shapePathComponent.createObject(shape)
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   225
                                                   shapePath.strokeWidth = 1
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   226
                                                   shapePath.strokeColor = rectColor
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   227
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   228
                                                   shapePath.startX = r.x
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   229
                                                   shapePath.startY = r.y
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   230
                                                   shapePath.pathElements = [
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   231
                                                      pathLineComponent.createObject(shapePath, {x: r.x, y: r.y + r.h}),
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   232
                                                      pathLineComponent.createObject(shapePath, {x: r.x + r.w, y: r.y + r.h}),
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   233
                                                      pathLineComponent.createObject(shapePath, {x: r.x + r.w, y: r.y}),
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   234
                                                      pathLineComponent.createObject(shapePath, {x: r.x, y: r.y})
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   235
                                                   ]
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   236
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   237
                                                   rectangles.push(shapePath)
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   238
                                                 }))
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   239
    let polygonShapes = polygons.map(polygon => {
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   240
                                             let points = polygon.map(r => ({x: r.x + r.w / 2, y: r.y + r.h / 2}))
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   241
                                             let shapePath = shapePathComponent.createObject(shape)
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   242
                                             let start = points[points.length - 1]
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   243
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   244
                                             shapePath.strokeColor = lineColor
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   245
                                             shapePath.startX = start.x
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   246
                                             shapePath.startY = start.y
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   247
                                             shapePath.pathElements = points.map(p => pathLineComponent.createObject(shapePath, p))
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   248
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   249
                                             return shapePath
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   250
                                             })
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   251
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   252
    return rectangles.concat(polygonShapes)
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   253
  }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   254
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   255
  function renderTemplate(template) {
16044
5c941f5deeec * Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents: 16043
diff changeset
   256
    return polygons2shapes(template.outline_points, "red", "black").concat(polygons2shapes(template.walls, "gray", "gray"))
16043
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   257
  }
adb44a2d8226 Add a tool visualizing map templates
unC0Rr
parents:
diff changeset
   258
}