]> git.lizzy.rs Git - nothing.git/blob - devtools/svg2rects.xqe
(#68) Add boxes to the level format
[nothing.git] / devtools / svg2rects.xqe
1 declare namespace svg ="http://www.w3.org/2000/svg";
2
3 let $rects := //svg:svg/svg:rect
4 let $player := for $rect in $rects where $rect/@id = "player"
5   return concat (
6     $rect/@x, " ",
7     $rect/@y, " ",
8     replace($rect/@style, ".*fill:#([0-9a-z]{6}).*", "$1")
9   )
10 let $platforms := for $rect in $rects where matches($rect/@id, "^rect.*")
11   return concat (
12     $rect/@x, " ",
13     $rect/@y, " ",
14     $rect/@width, " ",
15     $rect/@height, " ",
16     replace($rect/@style, ".*fill:#([0-9a-z]{6}).*", "$1")
17   )
18 let $boxes := for $rect in $rects where matches($rect/@id, "^box.*")
19   return concat (
20     $rect/@x, " ",
21     $rect/@y, " ",
22     $rect/@width, " ",
23     $rect/@height, " ",
24     replace($rect/@style, ".*fill:#([0-9a-z]{6}).*", "$1")
25   )
26 let $regions := for $rect in $rects where matches($rect/@id, "region.*") return $rect
27 let $goals := for $rect in $rects where matches($rect/@id, "goal.*") return (
28   let $goal_id := replace($rect/@id, "goal(.*)", "$1")
29   let $goal_region := for $region in $regions where $region/@id = concat("region", $goal_id) return $region
30   return concat (
31     $rect/@x, " ",
32     $rect/@y, " ",
33     $goal_region[1]/@x, " ",
34     $goal_region[1]/@y, " ",
35     $goal_region[1]/@width, " ",
36     $goal_region[1]/@height, " ",
37     replace($rect/@style, ".*fill:#([0-9a-z]{6}).*", "$1")
38   )
39 )
40 let $lavas := for $rect in $rects where matches($rect/@id, "lava.*")
41   return concat (
42     $rect/@x, " ",
43     $rect/@y, " ",
44     $rect/@width, " ",
45     $rect/@height, " ",
46     replace($rect/@style, ".*fill:#([0-9a-z]{6}).*", "$1")
47   )
48 let $background := for $rect in $rects where $rect/@id = "background"
49 return replace($rect/@style, ".*fill:#([0-9a-z]{6}).*", "$1")
50 let $backplatforms := for $rect in $rects where matches($rect/@id, "^backrect.*")
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 return (
59   $background,
60   $player,
61   count($platforms),
62   $platforms,
63   count($goals),
64   $goals,
65   count($lavas),
66   $lavas,
67   count($backplatforms),
68   $backplatforms,
69   count($boxes),
70   $boxes
71 )