Clone wiki

ignifuga / pQuery

Become a pQuery ninja in 42 easy steps

You should start by reading the Remote Console guide for a way to test these recipes easily and interactively while the game runs.

pQuery is inspired in jQuery, so familiarity with jQuery's selectors is expected. For more information, check their documentation. While pQuery's common shorthand name is the symbol $, due to Python's syntax rules we use the underscore "_" as a nickname for pQuery.

pQuery works to select and act upon Ignifuga's Entities, Components and Scenes, and it also works (with the same syntax) on LibRocket elements. To distinguish which sort of elements pQuery should select, a "context" is provided.

def pQuery(selector, context = None):

By default, the context is the current scene (except for Python code ran from inside a libRocket document, in which case the default context is the current document), so selecting without a context will yield entities and components in the current scene. If the context is an entity, then the selection will yield components belonging to the given entity. Finally, if the context is a Rocket document, document elements will be selected.

Animations

pQuery has a "animate" method that can modify properties over time.

def animate(self, properties, duration = 0.400, easing='linear',onStart = None, onLoop=None, onStop=None):

Here are some examples that can be ran using the Remote Console and the demo project,

# Change the "load" button text color to blue, then to red.
_('#loadBtn', gui).animate({'color': '#0000ff'}, 3.0).animate({'color':'#ff0000'}, 3.0)

# Animate the menu position and background color simultaneously 
_('#menu', gui).animate({'bottom': '10px', 'background-color': '#000000'}, 3.0).animate({'bottom':'0px', 'background-color': '#ff0000'}, 3.0)

# Animate all the menu options at the same time, with three different type of selectors (which in this case produce equivalent results)
_('a', gui).animate({'color': '#0000ff'}, 3.0).animate({'color':'#ff0000'}, 3.0)
_('.container a', gui).animate({'color': '#0000ff'}, 3.0).animate({'color':'#ff0000'}, 3.0)
_('span a', gui).animate({'color': '#0000ff'}, 3.0).animate({'color':'#ff0000'}, 3.0)

# You can also change Ignifuga's entities in the same manner, the properties modifiable are different though.
_('#igni').animate({'red': 0.0}).animate({'red':1.0}).animate({'blue':0.0, 'green':0.0}).animate({'blue':1.0, 'green':1.0})

Updated