]> git.lizzy.rs Git - nothing.git/blob - devtools/svg2rects.xqe
(#207) lava_float_solid -> lava_float_rigid_rect
[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:svg/svg:rect
6 let $texts := //svg:svg/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/@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 )