You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix#3149: Allow kOS users to read the non-gui KSPField properties (#3150)
* Just removed the checks
* Refactor it by creating a 3 new suffixes.
* Revert changes to the solution properties file
* No need to make HasHiddenField virtual
* Added the GEtAllHiddenFieldNames suffix. Refactored some inherited methods using function overload to avoid unnecessary changes in the child classes
* Refactor FieldISVisible method to prevent nulls from sneaking into the list.
* Forgot to update this.
* Update the docs
* Use GUI instead of UI everywhere
* Fix typos.
---------
Co-authored-by: Anton Kuzin <[email protected]>
Copy file name to clipboardExpand all lines: doc/source/structures/vessels/partmodule.rst
+43-2Lines changed: 43 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,9 +29,15 @@ Once you have a :struct:`PartModule`, you can use it to invoke the behaviors tha
29
29
* - :attr:`ALLFIELDS`
30
30
- :struct:`List` of strings
31
31
- Accessible fields
32
+
* - :attr:`ALLHIDDENFIELDS`
33
+
- :struct:`List` of strings
34
+
- Fields not normally accessible via GUI
32
35
* - :attr:`ALLFIELDNAMES`
33
36
- :struct:`List` of strings
34
37
- Accessible fields (name only)
38
+
* - :attr:`ALLHIDDENFIELDNAMES`
39
+
- :struct:`List` of strings
40
+
- Fields not normally accessible via GUI (name only)
35
41
* - :attr:`ALLEVENTS`
36
42
- :struct:`List` of strings
37
43
- Triggerable events
@@ -47,6 +53,9 @@ Once you have a :struct:`PartModule`, you can use it to invoke the behaviors tha
47
53
* - :meth:`GETFIELD(name)`
48
54
-
49
55
- Get value of a field by name
56
+
* - :meth:`GETHIDDENFIELD(name)`
57
+
-
58
+
- Get value of a hidden field by name
50
59
* - :meth:`SETFIELD(name,value)`
51
60
-
52
61
- Set value of a field by name
@@ -59,6 +68,9 @@ Once you have a :struct:`PartModule`, you can use it to invoke the behaviors tha
59
68
* - :meth:`HASFIELD(name)`
60
69
- :struct:`Boolean`
61
70
- Check if field exists
71
+
* - :meth:`HASHIDDENFIELD(name)`
72
+
- :struct:`Boolean`
73
+
- Check if a hidden field exists
62
74
* - :meth:`HASEVENT(name)`
63
75
- :struct:`Boolean`
64
76
- Check if event exists
@@ -90,12 +102,26 @@ Once you have a :struct:`PartModule`, you can use it to invoke the behaviors tha
90
102
91
103
Get a list of all the names of KSPFields on this PartModule that the kos script is CURRENTLY allowed to get or set with :GETFIELD or :SETFIELD. Note the Security access comments below. This list can become obsolete as the game continues running depending on what the PartModule chooses to do.
92
104
105
+
.. attribute:: PartModule:ALLHIDDENFIELDS
106
+
107
+
:access: Get only
108
+
:test::struct:`List` of strings
109
+
110
+
Get a list of all the names of KSPFields on this PartModule that are not normally displayed in the GUI. The returned field names should be used with :GETHIDDENFIELD and cannot be used with :SETFIELD. Note the Security access comments below. This list can become obsolete as the game continues running depending on what the PartModule chooses to do.
111
+
93
112
.. attribute:: PartModule:ALLFIELDNAMES
94
113
95
114
:access: Get only
96
115
:test::struct:`List` of strings
97
116
98
117
Similar to :ALLFIELDS except that it returns the string without the formatting to make it easier to use in a script. This list can become obsolete as the game continues running depending on what the PartModule chooses to do.
118
+
119
+
.. attribute:: PartModule:ALLHIDDENFIELDNAMES
120
+
121
+
:access: Get only
122
+
:test::struct:`List` of strings
123
+
124
+
Similar to :ALLHIDDENFIELDS except that it returns the string without the formatting to make it easier to use in a script. This list can become obsolete as the game continues running depending on what the PartModule chooses to do.
99
125
100
126
.. attribute:: PartModule:ALLEVENTS
101
127
@@ -132,6 +158,13 @@ Once you have a :struct:`PartModule`, you can use it to invoke the behaviors tha
132
158
133
159
Get the value of one of the fields that this PartModule has placed onto the right-click menu for the part. Note the Security comments below.
134
160
161
+
.. method:: PartModule:GETHIDDENFIELD(name)
162
+
163
+
:parameter name: (:struct:`String`) Name of the field
164
+
:return: varies
165
+
166
+
Get the value of one of the hidden(internal) PartModule fields that aren't normally displayed in the right-click menu for the part. Note the Security comments below.
167
+
135
168
.. method:: PartModule:SETFIELD(name,value)
136
169
137
170
:parameter name: (:struct:`String`) Name of the field
@@ -177,6 +210,13 @@ Once you have a :struct:`PartModule`, you can use it to invoke the behaviors tha
177
210
178
211
Return true if the given field name is currently available for use with :GETFIELD or :SETFIELD on this PartModule, false otherwise.
179
212
213
+
.. method:: PartModule:HASHIDDENFIELD(name)
214
+
215
+
:parameter name: (:struct:`String`) Name of the field
216
+
:return::struct:`Boolean`
217
+
218
+
Return true if the given hidden(internal) field is present in the PartModule, false otherwise.
219
+
180
220
.. method:: PartModule:HASEVENT(name)
181
221
182
222
:parameter name: (:struct:`String`) Name of the event
@@ -197,19 +237,20 @@ Notes
197
237
-----
198
238
199
239
In all the above cases where there is a name being passed in to :GETFIELD, :SETFIELD, :DOEVENT, or :DOACTION, the name is meant to be the name that is seen by you, the user, in the GUI screen, and NOT necessarily the actual name of the variable that the programmer of that PartModule chose to call the value behind the scenes. This is so that you can view the GUI right-click menu to see what to call things in your script.
240
+
When it comes to the hidden fields, they can be inspected using the :ALLHIDDENFIELDS method, or by looking into the source code. Generally, manipulating the hidden fields is recommended for experienced users only.
200
241
201
242
.. note::
202
243
203
244
**Security and Respecting other Mod Authors**
204
245
205
-
There are often a lot more fields and events and actions that a partmodule can do than are usable via kOS. In designing kOS, the kOS developers have deliberately chosen NOT to expose any "hidden" fields of a partmodule that are not normally shown to the user, without the express permission of a mod's author to do so.
246
+
It was decided that providing the kOS users with a read-only access to the part module's hidden fields would allow to create even better scripts and wouldn't do any harm. Obviously, manipulating the module's internal state would result in all kind of troubles, so this is forbidden.
206
247
207
248
The access rules that kOS uses are as follows:
208
249
209
250
KSPFields
210
251
~~~~~~~~~
211
252
212
-
Is this a value that the user can normally see on the right-click context menu for a part? If so, then let kOS scripts GET the value. Is this a value that the user can normally manipulate via "tweakable" adjustments on the right-click context menu for a part, AND, is that tweakable a CURRENTLY enabled one? If so, then let KOS scripts SET the value, BUT they must set it to one of the values that the GUI would normally allow, according to the following rules.
253
+
Is this a value that the user can normally see on the right-click context menu for a part? If so, then let kOS scripts GET the value using the :GETFIELD method. Is this a value that represents the part's internal state and not normally displayed in the GUI? Then the :GETHIDDENFIELD method should be used. Is this a value that the user can normally manipulate via "tweakable" adjustments on the right-click context menu for a part, AND, is that tweakable a CURRENTLY enabled one? If so, then let KOS scripts SET the value, BUT they must set it to one of the values that the GUI would normally allow, according to the following rules.
0 commit comments