1 module rpui.basic_rpdl_exts;
2
3 import rpui.primitives;
4 import rpdl.accessors;
5 import rpdl.exception;
6 import rpdl.node;
7
8 Rect getRect(Node node, in string path) {
9 return Rect(node.getVec4f(path));
10 }
11
12 Rect optRect(Node node, in string path, in Rect defaultVal = Rect.init) {
13 try {
14 return node.getRect(path);
15 } catch (NotFoundException) {
16 return defaultVal;
17 }
18 }
19
20 FrameRect getFrameRect(Node accessorNode, in string path) {
21 Node node = accessorNode.getNode(path);
22
23 if (node is null) {
24 throw new NotFoundException("Node with path \"" ~ path ~ "\" not found");
25 }
26
27 if (node.length == 1) {
28 const float val = accessorNode.getNumber(path ~ ".0");
29 return FrameRect(val, val, val, val);
30 }
31
32 if (node.length == 2) {
33 const float vertical = accessorNode.getNumber(path ~ ".0");
34 const float horizontal = accessorNode.getNumber(path ~ ".1");
35 return FrameRect(horizontal, vertical, horizontal, vertical);
36 }
37
38 if (node.length == 3) {
39 const float top = accessorNode.getNumber(path ~ ".0");
40 const float horizontal = accessorNode.getNumber(path ~ ".1");
41 const float bottom = accessorNode.getNumber(path ~ ".2");
42 return FrameRect(horizontal, top, horizontal, bottom);
43 }
44
45 return FrameRect(accessorNode.getVec4f(path));
46 }
47
48 FrameRect optFrameRect(Node node, in string path,
49 in FrameRect defaultVal = FrameRect.init)
50 {
51 try {
52 return node.getFrameRect(path);
53 } catch (NotFoundException) {
54 return defaultVal;
55 }
56 }
57
58 IntRect getIntRect(Node node, in string path) {
59 return IntRect(node.getVec4i(path));
60 }
61
62 IntRect optIntRect(Node node, in string path, in IntRect defaultVal = IntRect.init) {
63 try {
64 return node.getIntRect(path);
65 } catch (NotFoundException) {
66 return defaultVal;
67 }
68 }