Lib for work this Geometry Dash levels
from gddecoder import *
levels = LocalLevels()
If you need to work with a save file that is not in the standard path
levels = LocalLevels("path/to/file/CCLocalLevels.dat")
LocalLevels
is list of levels, to get the level, use the levels.get_level()
method or standard list syntax levels[n]
.
level1 = levels.get_level(10)
level2 = levels.get_level("first level")
level3 = level[10]
levels[n]
don't support levels names, level["first level"].
Level is dict
. To refer to a key in a level, you can use the name of the key that matches the name of the key in the game's save file, or use the LevelSettings
enum.
level["k2"] = "test level"
level[LevelSettings.objects_count] = 800
Print names of all levels:
from gddecoder import *
levels = LocalLevels()
for lvl in levels:
print(lvl[LevelSettings.name])
Counting the total number of jumps in levels:
from gddecoder import *
levels = LocalLevels()
jumps = 0
for lvl in levels:
# test because the level may not have jumps
if LevelSettings.jumps in lvl:
jumps += lvl[LevelSettings.jumps]
print(jumps)
Level has method get_editor
, it return Editor object.
editor = level.get_editor()
Editor object has attribute blocks
and colors
. Other properties are stored as in a dictionary. Use EditorSettings
enum or game key.
# set 2 player mode
editor[EditorSettings.two_player_mode] = True
# get 20 block in level
blocks = editor.blocks[19]
# get bg Color
color_bg = editor.colors[1000]
Blocks are also dictionaries. Use BlockSettings
enum.
block = editor.blocks[9]
block[BlockSettings.x] = 30
block[BlockSettings.y] = 15
editor.blocks.add(Block(
{
BlockSettings.id: 1,
BlockSettings.x: 15,
BlockSettings.y: 15,
}
))
editor.blocks.add(Block(
editor.blocks[9]
))
Groups
is set.
block = editor.blocks[9]
block[BlockSettings.groups] = Groups([1, 2, 10])
block[BlockSettings.groups].add(14)
block[BlockSettings.groups].pop(10)
The block stores only the color channel of the block as an int. To change a color, you need to change the corresponding color in editor.colors
and then assign it to the block.
Save to standart path:
level.set_editor(editor)
levels.save()
For other path:
level.set_editor(editor)
levels.save("other/path/file.dat")