Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ldtk file support for tilemaps in Gdevelop #2828

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
2bc895f
implement ldtk parser
blurymind Jul 21, 2021
41e556f
add missed edit
blurymind Jul 21, 2021
87d1a8a
add new/old pixi-tilemap
blurymind Jul 21, 2021
a534a9a
tidy up
blurymind Jul 21, 2021
d6faa7e
pass pixiRenderer to extensions, make tilemap editor use it
blurymind Jul 21, 2021
bcdaaa3
add opacity parsing
blurymind Jul 21, 2021
d8e59a0
fix paste error
blurymind Jul 22, 2021
09e90f5
add layer opacity for tiled
blurymind Jul 22, 2021
42910e0
protect against ayeredIndex not being there - in case of an older fil…
blurymind Jul 22, 2021
5db9008
make runtime work with new pixi-tilemap
blurymind Jul 22, 2021
217927d
fix levelIndex doesnt update
blurymind Jul 22, 2021
e5148e8
protect against -1 levelIndex
blurymind Jul 22, 2021
ef55960
add flipped tiles for ldtk
blurymind Jul 22, 2021
ac2faae
Remove redundant caching of flipped tiles, simplify the code
blurymind Jul 23, 2021
77cb12b
cleanup
blurymind Jul 23, 2021
c0f0405
tidy up
blurymind Jul 23, 2021
3e0320b
tidy up
blurymind Jul 23, 2021
50abb82
run formatter
blurymind Jul 23, 2021
114eafc
fix evaluation of relative path to ldtk file
blurymind Jul 23, 2021
2016ca8
add pixi renderer type
blurymind Jul 23, 2021
424b677
add missed gridTiles
blurymind Jul 24, 2021
584b901
add ability to render level background
blurymind Jul 24, 2021
8d1e0b9
fix commit error
blurymind Jul 24, 2021
c0289e5
crop level backgrounds so they render consistently with ldtk
blurymind Jul 24, 2021
a696876
implement ldtk parser
blurymind Jul 21, 2021
500ace3
add missed edit
blurymind Jul 21, 2021
12d584e
add new/old pixi-tilemap
blurymind Jul 21, 2021
8bf5419
tidy up
blurymind Jul 21, 2021
d046981
pass pixiRenderer to extensions, make tilemap editor use it
blurymind Jul 21, 2021
374180e
add opacity parsing
blurymind Jul 21, 2021
3e622a9
fix paste error
blurymind Jul 22, 2021
c084032
add layer opacity for tiled
blurymind Jul 22, 2021
b7d3f18
protect against ayeredIndex not being there - in case of an older fil…
blurymind Jul 22, 2021
2498ea3
make runtime work with new pixi-tilemap
blurymind Jul 22, 2021
6ec886f
fix levelIndex doesnt update
blurymind Jul 22, 2021
cc08052
protect against -1 levelIndex
blurymind Jul 22, 2021
754f295
add flipped tiles for ldtk
blurymind Jul 22, 2021
f34df4f
Remove redundant caching of flipped tiles, simplify the code
blurymind Jul 23, 2021
bba5960
cleanup
blurymind Jul 23, 2021
13b7cbc
tidy up
blurymind Jul 23, 2021
7f849a0
tidy up
blurymind Jul 23, 2021
f6a6555
run formatter
blurymind Jul 23, 2021
e623447
fix evaluation of relative path to ldtk file
blurymind Jul 23, 2021
04aa043
add pixi renderer type
blurymind Jul 23, 2021
261c341
add missed gridTiles
blurymind Jul 24, 2021
e99784e
add ability to render level background
blurymind Jul 24, 2021
bc7a647
fix commit error
blurymind Jul 24, 2021
b4c2c09
crop level backgrounds so they render consistently with ldtk
blurymind Jul 24, 2021
78ea3d8
Merge remote-tracking branch 'origin/ldtk-p6' into ldtk-p6
blurymind Nov 9, 2021
9fe7518
Merge remote-tracking branch '4ian/master' into ldtk-p6
blurymind Nov 9, 2021
997e2c4
try to restore tilemap resource after merge conflict
blurymind Nov 9, 2021
6640e66
review note
blurymind Nov 9, 2021
1acd676
replace setter/getters with new shorter methods
blurymind Nov 28, 2021
c666266
add protection against level being undefined
blurymind Nov 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Core/GDCore/Project/ResourcesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ std::shared_ptr<Resource> ResourcesManager::CreateResource(
return std::make_shared<VideoResource>();
else if (kind == "json")
return std::make_shared<JsonResource>();
else if (kind == "tilemap")
return std::make_shared<TilemapResource>();
else if (kind == "bitmapFont")
return std::make_shared<BitmapFontResource>();

Expand Down Expand Up @@ -674,6 +676,47 @@ bool JsonResource::UpdateProperty(const gd::String& name,

#endif

//TilemapResource
void TilemapResource::SetFile(const gd::String& newFile) {
file = newFile;

// Convert all backslash to slashs.
while (file.find('\\') != gd::String::npos)
file.replace(file.find('\\'), 1, "/");
}

void TilemapResource::UnserializeFrom(const SerializerElement& element) {
SetUserAdded(element.GetBoolAttribute("userAdded"));
SetFile(element.GetStringAttribute("file"));
DisablePreload(element.GetBoolAttribute("disablePreload", false));
}

#if defined(GD_IDE_ONLY)
void TilemapResource::SerializeTo(SerializerElement& element) const {
element.SetAttribute("userAdded", IsUserAdded());
element.SetAttribute("file", GetFile());
element.SetAttribute("disablePreload", IsPreloadDisabled());
}

std::map<gd::String, gd::PropertyDescriptor> TilemapResource::GetProperties()
const {
std::map<gd::String, gd::PropertyDescriptor> properties;
properties["disablePreload"]
.SetValue(disablePreload ? "true" : "false")
.SetType("Boolean")
.SetLabel(_("Disable preloading at game startup"));

return properties;
}

bool TilemapResource::UpdateProperty(const gd::String& name,
const gd::String& value) {
if (name == "disablePreload") disablePreload = value == "1";

return true;
}
#endif

void BitmapFontResource::SetFile(const gd::String& newFile) {
file = newFile;

Expand Down
42 changes: 42 additions & 0 deletions Core/GDCore/Project/ResourcesManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,48 @@ class GD_CORE_API BitmapFontResource : public Resource {
gd::String file;
};

/**
* \brief Describe a tilemap file used by a project.
*
* \see Resource
* \ingroup ResourcesManagement
*/
class GD_CORE_API TilemapResource : public Resource {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea to have this tilemap resource! Will be much cleaner 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so too. Having one interface for both file types makes it much simpler to use

public:
TilemapResource() : Resource(), disablePreload(false) { SetKind("tilemap"); };
virtual ~TilemapResource(){};
virtual TilemapResource* Clone() const override {
return new TilemapResource(*this);
}

virtual const gd::String& GetFile() const override { return file; };
virtual void SetFile(const gd::String& newFile) override;

#if defined(GD_IDE_ONLY)
virtual bool UseFile() override { return true; }

std::map<gd::String, gd::PropertyDescriptor> GetProperties() const override;
bool UpdateProperty(const gd::String& name, const gd::String& value) override;

void SerializeTo(SerializerElement& element) const override;
#endif

void UnserializeFrom(const SerializerElement& element) override;

/**
* \brief Return true if the loading at game startup must be disabled
*/
bool IsPreloadDisabled() const { return disablePreload; }

/**
* \brief Set if the tilemap preload at game startup must be disabled
*/
void DisablePreload(bool disable = true) { disablePreload = disable; }

private:
bool disablePreload; ///< If "true", don't load the Tilemap at game startup
gd::String file;
};
/**
* \brief Inventory all resources used by a project
*
Expand Down
Loading