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