This patch modifies "space_logic.py" to enable the end user to re order game properties
It should be noted that it makes no difference to the game engine pipeline if the order of game properties should differ, so this is a more cosmetic expansion.
Because properties are drawn from the prop_collection collection, it is impossible to modify the order of properties once they have been added.
This operator does the following:
Take the index of the calling button. Determine the new index. Reorder property list and recreate properties.
This could become expensive if the user has hundreds of properties, but that is unlikely that any game user would manually create such a volume - at that point the drawing code is the biggest bottleneck.
I was unsure where to add the operator, so I provide the operator and modified properties panel in the same file - space_logic.py (patch)
Description
Related Objects
Event Timeline
version 2.66 (sub 6), revision b'56420M'. b'Release'
build date: b'2013-04-30', b'21:31:38'
platform: b'Windows:32bit'
Manual test:
added three properties:
prop, prop0, prop1 - passed
moved prop1 up. The new order is:
prop, prop1, prop2 - passed
moved prop down:
prop1, prop, prop0 - passed
moved prop1 up:
prop1, prop, prop0 -passed
moved prop0 down:
prop1, prop, prop0 - passed
all test passed.
Fine from my site
Operators have a naming convention. I don't remember it off-hand, but I'm pretty sure your two new operators are not following it. Other than that, I'm assigning this to Dalai since this is more his area of expertise.
After reviewing my patch, I have made some changes to improve code quality.
namely, simplifying iterators, removing essentially a duplicate operator (single semantic difference) and attempting to use a more conventional operator name. As I am not at home, I am currently unable to produce a patch for this, but I can attach the reviewed file.
Overall I think this is a very nice addition. It's something I've missed :)
There are no operators defined in the bl_ui package. I think it would be better to keep it that way, and to move your operator to a new module bl_operators.logic
properties.remove(current) requires O(n) operations just to find the element to remove. It's more efficient to use del properties[index], which only uses O(1) to find the element.
PEP 8: remove the whitespace between i : in the line prop_match = {i : (v.name, v.type, v.value, v.show_debug) for i, v in enumerate(properties)}
More PEP 8: use triple-double quotes for docstrings.
Such an invoke() is unnecessary, as by default self.execute() is called anyway:
def invoke(self, context, event):
return self.execute(context)The up-arrow also moves the property down (at least on my Blender), so add move_up.direction = "UP" to the GUI code.
It would be nice if the top up-arrow and bottom down-arrow are disabled.
Made requested changes, included license block.
Thanks for catching the remove call, poor consideration there.
thumbs up for the patch and thumbs up for sybren's review.
best to move that in before getting in fix-only mode tomorrow at the meeting.
Comments:
- don't forget to add license block to the new file
- # <pep8 compliant>
- import bpy
- bl_label = "Move game property up in stack" -> up/down in the list? I think it is a more common wording... totally non important
another tip, for the direction enum, you can attribute a specific value of -1 for down and +1 for up, so that you attribute it to direction and use directly instead of index + 1
See how other moves do (they are typically executed in C, though, because the order matters for functionality there)
Thanks Brita - I thought it better practice to separate that behaviour from the implementation, but perhaps it's not an issue.
I'll get this in when we're back at bcon1 (I was without internet before, sorry about that).
Committed the C version of this (rBa8adeeb6fbd3b) so this can be closed.
@Angus Hollands (agoose77), thanks for this nevertheless :)