]> git.lizzy.rs Git - nothing.git/blobdiff - devtools/svg2rects.xqe
(#408) use stdbool in camera unit
[nothing.git] / devtools / svg2rects.xqe
index 80861363d97f27ae420c3513a196755de80c1485..e944b9424f57ccfa3035f8b254628f5ddd09078d 100644 (file)
@@ -1,8 +1,15 @@
 declare namespace svg ="http://www.w3.org/2000/svg";
 
-(: TODO(#255): svg2rects.xqe doesn't support labels :)
-
-let $rects := //svg:svg/svg:rect
+let $rects := //svg:rect
+let $texts := //svg:text
+let $labels := for $text in $texts where matches($text/@id , "^label.*")
+  return concat (
+    $text/@x, " ",
+    $text/@y, " ",
+    replace($text/@style, ".*fill:#([0-9a-z]{6}).*", "$1"), "
",
+    (: TODO(#432): svg2rects doesn't handle newlines in labels :)
+    string-join($text/svg:tspan/text(), " ")
+  )
 let $player := for $rect in $rects where $rect/@id = "player"
   return concat (
     $rect/@x, " ",
@@ -19,6 +26,7 @@ let $platforms := for $rect in $rects where matches($rect/@id, "^rect.*")
   )
 let $boxes := for $rect in $rects where matches($rect/@id, "^box.*")
   return concat (
+    $rect/@id, " ",
     $rect/@x, " ",
     $rect/@y, " ",
     $rect/@width, " ",
@@ -57,7 +65,11 @@ let $backplatforms := for $rect in $rects where matches($rect/@id, "^backrect.*"
     $rect/@height, " ",
     replace($rect/@style, ".*fill:#([0-9a-z]{6}).*", "$1")
   )
-return (
+return if (count($player) = 0) then (
+  error(QName('', 'ERROR'), 'Position of the Player is not defined. Create a rectangle with id "player"')
+) else if (count($background) = 0) then (
+  error(QName('', 'ERROR'), 'Color of the Background is not defined. Create a rectangle with id "background"')
+) else (
   $background,
   $player,
   count($platforms),
@@ -69,5 +81,7 @@ return (
   count($backplatforms),
   $backplatforms,
   count($boxes),
-  $boxes
+  $boxes,
+  count($labels),
+  $labels
 )