forked from 4ian/GDevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlatformBehavior.cpp
More file actions
77 lines (68 loc) · 2.58 KB
/
Copy pathPlatformBehavior.cpp
File metadata and controls
77 lines (68 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
GDevelop - Platform Behavior Extension
Copyright (c) 2014-2016 Florian Rival (Florian.Rival@gmail.com)
This project is released under the MIT License.
*/
#include "PlatformBehavior.h"
#include <memory>
#include "GDCore/Tools/Localization.h"
#include "GDCore/CommonTools.h"
#include "GDCore/Project/Layout.h"
#include "GDCore/Serialization/SerializerElement.h"
#if defined(GD_IDE_ONLY)
#include <iostream>
#include <map>
#include "GDCore/Project/PropertyDescriptor.h"
#endif
void PlatformBehavior::InitializeContent(
gd::SerializerElement& behaviorContent) {
behaviorContent.SetAttribute("platformType", "NormalPlatform");
behaviorContent.SetAttribute("canBeGrabbed", true);
behaviorContent.SetAttribute("yGrabOffset", 0);
}
#if defined(GD_IDE_ONLY)
std::map<gd::String, gd::PropertyDescriptor> PlatformBehavior::GetProperties(
const gd::SerializerElement& behaviorContent) const {
std::map<gd::String, gd::PropertyDescriptor> properties;
gd::String platformType = behaviorContent.GetStringAttribute("platformType");
properties["PlatformType"]
.SetLabel(_("Type"))
.SetValue(platformType.empty() ? "NormalPlatform" : platformType)
.SetType("Choice")
.AddChoice("NormalPlatform", _("Platform"))
.AddChoice("Jumpthru", _("Jumpthru platform"))
.AddChoice("Ladder", _("Ladder"));
properties["CanBeGrabbed"]
.SetLabel(_("Ledges can be grabbed"))
.SetGroup(_("Ledge"))
.SetValue(behaviorContent.GetBoolAttribute("canBeGrabbed", true)
? "true"
: "false")
.SetType("Boolean");
properties["YGrabOffset"]
.SetLabel(_("Grab offset on Y axis"))
.SetGroup(_("Ledge"))
.SetValue(
gd::String::From(behaviorContent.GetDoubleAttribute("yGrabOffset")));
return properties;
}
bool PlatformBehavior::UpdateProperty(gd::SerializerElement& behaviorContent,
const gd::String& name,
const gd::String& value) {
if (name == "CanBeGrabbed")
behaviorContent.SetAttribute("canBeGrabbed", (value == "1"));
else if (name == "PlatformType") {
auto normalizedValue = value.LowerCase();
if (normalizedValue == "jumpthru")
behaviorContent.SetAttribute("platformType", "Jumpthru");
else if (normalizedValue == "ladder")
behaviorContent.SetAttribute("platformType", "Ladder");
else
behaviorContent.SetAttribute("platformType", "NormalPlatform");
} else if (name == "YGrabOffset")
behaviorContent.SetAttribute("yGrabOffset", value.To<double>());
else
return false;
return true;
}
#endif