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