Level Editing¶
gd.py provides convenient API for creating and editing levels.
You can create objects like this:
from gd.api import Object
obj = Object(id=1, x=150, y=150).add_groups(1)
# <Object id=1 x=150 y=150 groups={1}>
string = some_object.dump()
# "1,1,2,150,3,150,57,1"
And open editor, like the following:
from gd.api import Editor
# assume we have our "some_object" from above
editor = Editor()
editor.add_objects(some_object)
string = editor.dump()
# "...;1,1,2,150,3,150,57,1;"
There is an option to load the level’s editor:
import gd
client = gd.Client()
level = client.run(client.get_level(30029017))
editor = level.open_editor()
gd.py also gives some helpers in case user does not know some values:
from gd.api import Object
some_object = Object(x=150, y=150, lock_to_player_x=True, target_group_id=1)
# <Object id=1 x=150 y=150 target_group_id=1 lock_to_player_x=True>
some_object.set_id("trigger:move") # move trigger
# <Object id=901 x=150 y=150 target_group_id=1 lock_to_player_x=True>
some_object.set_easing("sine_in_out")
# <Object id=901 x=150 y=150 easing=Easing.SINE_IN_OUT target_group_id=1 lock_to_player_x=True>
-
gd.api.get_id(string: str, into_enum: bool = False, delim: str = ':') → Any[source]¶ Calculate required value from the given directive
string.The format is, as follows:
class:name, e.g.special:h. Spaces around:are allowed.- Parameters
- Returns
The value found, if any.
- Return type
Any
- Raises
EditorError – Failed to convert directive to the value.
Editor¶
-
class
gd.api.Editor(*objects: gd.api.struct.Object, **header_args)[source]¶ Editor interface of gd.py.
Editor can be created either by hand, from decoded level’s data, or taken from a level itself.
-
classmethod
load_from(callback: Union[GameLevel, Level, gd.api.struct.LevelAPI], attribute: str) → Editor[source]¶ Load the editor from
Level,LevelAPIorGameLevel, and set a callback to dumb the editor to it. This method is intented to be used internally.
-
classmethod
from_object_iterable(objects: Iterable[gd.api.struct.Object], **header_args) → gd.api.editor.Editor[source]¶ Create the editor from
objects, constructing header withheader_args.
-
classmethod
from_string(data: Union[bytes, str], delim: str = ';', ignore_empty: bool = True) → gd.api.editor.Editor[source]¶ Create the editor from
datastring.
-
classmethod
load(data: Union[bytes, str], delim: str = ';', ignore_empty: bool = True) → gd.api.editor.Editor¶ Create the editor from
datastring.
-
set_header(header: gd.api.struct.Header) → gd.api.editor.Editor[source]¶ Set header of Editor instance to
header.
-
get_color_ids() → Iterable[int][source]¶ Fetch all used color IDs in Editor instance and return them as a set.
-
get_free_group() → Optional[int][source]¶ Get next free group of Editor instance.
Noneif not found.
-
get_free_color_id() → Optional[int][source]¶ Get next free color ID of Editor instance.
Noneif not found.
-
get_portals() → List[gd.api.struct.Object][source]¶ Fetch all portals / speed triggers used in this level, sorted by position in level.
-
get_speeds() → List[gd.api.struct.Object][source]¶ Fetch all speed changes used in this level, sorted by position in level.
-
get_color(directive_or_id: Union[int, str]) → Optional[gd.api.struct.ColorChannel][source]¶ Get color by ID or special directive.
Noneif not found.
-
get_colors() → gd.api.struct.ColorCollection[source]¶ Return a reference to colors of the Editor instance.
-
set_colors(colors: gd.api.struct.ColorCollection) → gd.api.editor.Editor[source]¶ Set colors of the Editor instance to
colors.
-
property
colors¶ Return a reference to colors of the Editor instance.
-
add_colors(*colors: gd.api.struct.ColorChannel) → gd.api.editor.Editor[source]¶ Add colors to the Editor.
-
remove_colors(*colors: gd.api.struct.ColorChannel) → gd.api.editor.Editor[source]¶ Remove colors from the Editor.
-
get_objects() → List[gd.api.struct.Object][source]¶ Return a reference to object of the Editor instance.
-
set_objects(objects: List[gd.api.struct.Object]) → gd.api.editor.Editor[source]¶ Set objects of the Editor instance to
objects.
-
add_objects(*objects: gd.api.struct.Object) → gd.api.editor.Editor[source]¶ Add objects to
self.objects.
-
classmethod
HSV¶
-
class
gd.api.HSV(*, use_default: bool = True, **kwargs)[source]¶ A class that represents HSV - Hue, Saturation, Value (Brightness) options.
Below is a table that shows how S and V depend on whether they are checked:
value range
false
true
s range
[0, 2]
[-1, 1]
v range
[0, 2]
[-1, 1]
- Parameters
h (
int) – Hue integer value in range [-180, 180].s (
float) – Saturation float value in range [0, 2] or [-1, 1] depending ons_checked.v (
float) – Value (Brightness) float value in range [0, 2] or [-1, 1] depending onv_checked.s_checked (
bool) – Whethersis checked.v_checked (
bool) – Whethervis checked.
ColorCollection¶
-
class
gd.api.ColorCollection(iterable: Optional[Iterable[gd.api.struct.ColorChannel]] = None, use_default: bool = True)[source]¶ -
remove(directive_or_id: Union[int, str]) → None[source]¶ Remove an element from a set; it must be a member.
If the element is not a member, raise a KeyError.
-
difference(other: Iterable[gd.api.struct.ColorChannel]) → gd.api.struct.ColorCollection[source]¶ Return the difference of two or more sets as a new set.
(i.e. all elements that are in this set but not the others.)
-
intersection(other: Iterable[gd.api.struct.ColorChannel]) → gd.api.struct.ColorCollection[source]¶ Return the intersection of two sets as a new set.
(i.e. all elements that are in both sets.)
-
symmetric_difference(other: Iterable[gd.api.struct.ColorChannel]) → gd.api.struct.ColorCollection[source]¶ Return the symmetric difference of two sets as a new set.
(i.e. all elements that are in exactly one of the sets.)
-