]> git.lizzy.rs Git - nothing.git/blob - devtools/svg2rects.xqe
(#427) Fix svg2rects failure on newlines in labels
[nothing.git] / devtools / svg2rects.xqe
1 declare namespace svg ="http://www.w3.org/2000/svg";
2
3 let $rects := //svg:rect
4 let $texts := //svg:text
5 let $labels := for $text in $texts where matches($text/@id , "^label.*")
6   return concat (
7     $text/@x, " ",
8     $text/@y, " ",
9     replace($text/@style, ".*fill:#([0-9a-z]{6}).*", "$1"), "
",
10     (: TODO: svg2rects doesn't handle newlines in labels :)
11     string-join($text/svg:tspan/text(), " ")
12   )
13 let $player := for $rect in $rects where $rect/@id = "player"
14   return concat (
15     $rect/@x, " ",
16     $rect/@y, " ",
17     replace($rect/@style, ".*fill:#([0-9a-z]{6}).*", "$1")
18   )
19 let $platforms := for $rect in $rects where matches($rect/@id, "^rect.*")
20   return concat (
21     $rect/@x, " ",
22     $rect/@y, " ",
23     $rect/@width, " ",
24     $rect/@height, " ",
25     replace($rect/@style, ".*fill:#([0-9a-z]{6}).*", "$1")
26   )
27 let $boxes := for $rect in $rects where matches($rect/@id, "^box.*")
28   return concat (
29     $rect/@id, " ",
30     $rect/@x, " ",
31     $rect/@y, " ",
32     $rect/@width, " ",
33     $rect/@height, " ",
34     replace($rect/@style, ".*fill:#([0-9a-z]{6}).*", "$1")
35   )
36 let $regions := for $rect in $rects where matches($rect/@id, "region.*") return $rect
37 let $goals := for $rect in $rects where matches($rect/@id, "goal.*") return (
38   let $goal_id := replace($rect/@id, "goal(.*)", "$1")
39   let $goal_region := for $region in $regions where $region/@id = concat("region", $goal_id) return $region
40   return concat (
41     $rect/@x, " ",
42     $rect/@y, " ",
43     $goal_region[1]/@x, " ",
44     $goal_region[1]/@y, " ",
45     $goal_region[1]/@width, " ",
46     $goal_region[1]/@height, " ",
47     replace($rect/@style, ".*fill:#([0-9a-z]{6}).*", "$1")
48   )
49 )
50 let $lavas := for $rect in $rects where matches($rect/@id, "lava.*")
51   return concat (
52     $rect/@x, " ",
53     $rect/@y, " ",
54     $rect/@width, " ",
55     $rect/@height, " ",
56     replace($rect/@style, ".*fill:#([0-9a-z]{6}).*", "$1")
57   )
58 let $background := for $rect in $rects where $rect/@id = "background"
59 return replace($rect/@style, ".*fill:#([0-9a-z]{6}).*", "$1")
60 let $backplatforms := for $rect in $rects where matches($rect/@id, "^backrect.*")
61   return concat (
62     $rect/@x, " ",
63     $rect/@y, " ",
64     $rect/@width, " ",
65     $rect/@height, " ",
66     replace($rect/@style, ".*fill:#([0-9a-z]{6}).*", "$1")
67   )
68 return (
69   $background,
70   $player,
71   count($platforms),
72   $platforms,
73   count($goals),
74   $goals,
75   count($lavas),
76   $lavas,
77   count($backplatforms),
78   $backplatforms,
79   count($boxes),
80   $boxes,
81   count($labels),
82   $labels
83 )