• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mobalazs / rotor-framework / 18919729013

29 Oct 2025 07:21PM UTC coverage: 85.379% (-0.1%) from 85.479%
18919729013

push

github

mobalazs
fix: update debug setting in bsconfig to enable debugging

1781 of 2086 relevant lines covered (85.38%)

1.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.8
/src/source/utils/NodeUtils.bs
1
namespace Rotor.Utils
2

3
    '==========================================================================
4
    ' NODE CREATION UTILITIES
5
    '==========================================================================
6

7
    ' ---------------------------------------------------------------------
8
    ' createNode - Creates a SceneGraph node with custom fields
9
    '
10
    ' @param {string} nodeType - Type of SceneGraph node to create
11
    ' @param {object} fields - Fields to set on the node (default: {})
12
    ' @returns {object} Created SceneGraph node
13
    '
14
    function createNode(nodeType as string, fields = {} as object) as object
15
        node = CreateObject("roSGNode", nodeType)
1✔
16
        setCustomFields(node, fields, true, true)
1✔
17
        return node
1✔
18
    end function
19

20
    ' ---------------------------------------------------------------------
21
    ' createContentNode - Creates a ContentNode with fields
22
    '
23
    ' @param {object} fields - Fields to add to the content node (default: {})
24
    ' @param {string} nodeType - Type of content node (default: "ContentNode")
25
    ' @returns {object} Created ContentNode
26
    '
27
    function createContentNode(fields = {} as object, nodeType = "ContentNode" as string) as object
28
        contentNode = CreateObject("roSGNode", nodeType)
1✔
29
        if nodeType = "ContentNode"
2✔
30
            contentNode.addFields(fields)
1✔
31
        else
3✔
32
            contentNode.setFields(fields)
1✔
33
        end if
34
        return contentNode
1✔
35
    end function
36

37
    '==========================================================================
38
    ' FIELD MANIPULATION UTILITIES
39
    '==========================================================================
40

41
    ' ---------------------------------------------------------------------
42
    ' setCustomFields - Sets custom fields on a SceneGraph node
43
    '
44
    ' Dynamically adds fields if they don't exist, then sets their values.
45
    ' Uses addField to enable alwaysNotify feature for runtime field creation.
46
    '
47
    ' @param {object} node - SceneGraph node to modify
48
    ' @param {object} fields - Fields to set (key-value pairs)
49
    ' @param {boolean} overwrite - If true, overwrites existing field values (default: true)
50
    ' @param {boolean} alwaysNotify - If true, field changes always trigger observers (default: true)
51
    '
52
    sub setCustomFields(node as object, fields as object, overwrite = true as boolean, alwaysNotify = true as boolean)
53
        for each attr in fields.Items()
1✔
54
            key = attr.key
1✔
55
            value = attr.value
1✔
56

57

58
            if node.hasField(key) = false
2✔
59

60
                ' Only addFiled can set `alwaysNotify` feature to true in runtime, so we need it;
61
                ' Type conversion and formatting are mandatory to make it possible.
62
                typeStr = convertIntrinsicType(type(value))
1✔
63
                node.addField(key, typeStr, alwaysNotify)
1✔
64

65
            end if
66

67
            if overwrite = true
3✔
68
                node.setField(key, value)
1✔
69
            end if
70

71
        end for
72
    end sub
73

74
    '==========================================================================
75
    ' CALLBACK UTILITIES
76
    '==========================================================================
77

78
    ' ---------------------------------------------------------------------
79
    ' callbackScoped - Invokes a callback function in a specific scope
80
    '
81
    ' Supports both function references and method name strings.
82
    ' Automatically handles 0-2 payload parameters.
83
    '
84
    ' @param {dynamic} callback - Function reference or method name string
85
    ' @param {object} scope - Scope (m) in which to execute the callback
86
    ' @param {dynamic} payload1 - Optional first parameter (default: invalid)
87
    ' @param {dynamic} payload2 - Optional second parameter (default: invalid)
88
    ' @returns {dynamic} Result of callback invocation or invalid
89
    '
90
    function callbackScoped(callback as dynamic, scope as object, payload1 = invalid as dynamic, payload2 = invalid as dynamic) as dynamic
91

92
        if callback = invalid or scope = invalid then return invalid
2✔
93

94
        ' check if callback valid, otherwise return
95
        if not (Rotor.Utils.isFunction(callback) or (Rotor.Utils.isString(callback) and callback <> "")) then return invalid
2✔
96

97
        ' check possible arguments
98
        isValidPayload1 = Rotor.Utils.isValid(payload1)
1✔
99
        isValidPayload2 = Rotor.Utils.isValid(payload2)
1✔
100

101
        if Rotor.Utils.isString(callback)
2✔
102
            if true = isValidPayload2
2✔
103
                return scope[callback](payload1, payload2)
×
104
            else if true = isValidPayload1
3✔
105
                return scope[callback](payload1)
1✔
106
            else
×
107
                return scope[callback]()
×
108
            end if
109
        else if Rotor.Utils.isFunction(callback)
3✔
110
            scope.rotor_tmp_callback_scoped = callback
1✔
111
            if true = isValidPayload2
2✔
112
                return scope.rotor_tmp_callback_scoped(payload1, payload2)
1✔
113
            else if true = isValidPayload1
2✔
114
                return scope.rotor_tmp_callback_scoped(payload1)
1✔
115
            else
3✔
116
                return scope.rotor_tmp_callback_scoped()
1✔
117
            end if
118
        end if
119
        scope.rotor_tmp_callback_scoped = invalid
×
120
        return invalid
×
121
    end function
122

123
    '==========================================================================
124
    ' FONT UTILITIES
125
    '==========================================================================
126

127
    ' ---------------------------------------------------------------------
128
    ' setFontAttribute - Sets font attributes on a node
129
    '
130
    ' @param {object} node - SceneGraph node to modify
131
    ' @param {object} params - Font parameters (uri, size)
132
    '
133
    sub setFontAttribute(node as object, params as object)
134
        font = createNode("Font", {
1✔
135
            uri: params.uri,
136
            size: params.size
137
        })
138
        node.font = font
1✔
139
    end sub
140

141
    ' ---------------------------------------------------------------------
142
    ' removeFontAttribute - Removes font from a node
143
    '
144
    ' @param {object} node - SceneGraph node to modify
145
    '
146
    sub removeFontAttribute(node as object)
147
        node.font = invalid
1✔
148
    end sub
149

150
    '==========================================================================
151
    ' TYPE CONVERSION UTILITIES
152
    '==========================================================================
153

154
    ' ---------------------------------------------------------------------
155
    ' convertIntrinsicType - Converts BrightScript intrinsic type to field type string
156
    '
157
    ' Converts type strings like "roInt" to "integer", "roAssocArray" to "assocarray", etc.
158
    ' Used for dynamic field creation via addField.
159
    '
160
    ' @param {string} typeKey - Intrinsic type string (e.g., "roInt", "roAssocArray")
161
    ' @returns {string} Converted field type string
162
    '
163
    function convertIntrinsicType(typeKey as string) as string
164
        typeKey = LCase(typeKey)
1✔
165
        types = {
1✔
166
            roint: "integer",
167
            roassocarray: "assocarray",
168
            rosgnode: "node"
169
        }
170
        converted = types.lookUp(typeKey)
1✔
171
        if converted <> invalid
3✔
172
            return converted
1✔
173
        else if Left(typeKey, 2) = "ro"
3✔
174
            return Right(typeKey, Len(typeKey) - 2)
1✔
175
        end if
176
        return typeKey
1✔
177

178
    end function
179

180
end namespace
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc