-
Notifications
You must be signed in to change notification settings - Fork 30
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
Retrieving Color property correctly. #21
Comments
Hey! tson::Colori color = map->getLayer("Object Layer")->firstObj("text")->get<tson::Colori>("color"); From here you can use the
Hope this helps 😄 |
Hey, thanks for the assistance! So I still couldn't get it to work, but I discovered something while trying to mess around. Using ->getText()-> you have access to "text" and "wrap" and why not color? What I think is happening is I'm trying to access color, but I have to access the text list first? My text is on a GameObjects layer, I think you can only put them on GameObject layers, to begin with.
Results: No font is shown. |
I looked into the details, and you are right. There is something missing! When I look at the first example map, I see that there is an additional property for I'll look into this asap, and get back to you. Thank you very much for reporting! I'll get back to you 🙂 |
Great! 😂 I thought I was going crazy! |
Nope, you were right all along! Anyways, I just pushed a fix for this into master. A little copy/paste from my integration test: tson::Colori color = map->getLayer("Object Layer")->firstObj("text")->getText().color;
REQUIRE(color.r == 254);
REQUIRE(color.g == 254);
REQUIRE(color.b == 254);
REQUIRE(color.a == 255); Can you verify that this fixes your problem? 🙂 |
Yay! It works! Thanks! Few more questions if you don't mind. My computer doesn't like the u8strings used in Tileson::Parse for the error message and ProjectFolder::loadData(). So I had to go and change that and I just changed them to string. It says cannot cast from std::basic_string<char8_t> to std::basic_string via functional cast. Secondly, Now, I am expanding basically on the example you provide. When you are parsing the file, do I have to do something more to get all the properties in the vector? I'd like to just be about to cout everything it's reading if that makes sense? It was a kind of version of debugging the problem making sure it was even reading the property "Color" at the time. I call it the cout trial and error solution! 😄 I appreciate the prompt fix and I am really liking this library and I appreciate all the work. Thanks and have a great night or day depending on where you are. 😁 |
Thanks for your kind feedback 🙂 When it comes to adding properties, I have to look on the details, but the library is a parser, so I would guess all property related stuff are defined as read-only by default. With that said: I have no problem allowing the user to add custom properties, if that is a feature that is wanted. It's a very low-risk change that I have no problems making. I'll look into it this weekend. You should be able to get |
@LedLoaf : Sorry, I think I read your message too quickly and misread some important details 😛 You can actually add whatever custom property you want, but as it stands there is a requirement that you have an existing default/parameterless constructor if you use an own class. Example: class CustomProperty
{
public:
CustomProperty() = default;
explicit CustomProperty(std::string str) : m_str{std::move(str)}
{
};
[[nodiscard]] const std::string &getStr() const
{
return m_str;
}
private:
std::string m_str{};
};
TEST_CASE( "Add custom property - expect working", "[property][custom]" ) {
tson::PropertyCollection props;
props.add("james", CustomProperty("CustomValue"), tson::Type::Undefined);
CustomProperty custom = props.getValue<CustomProperty>("james");
REQUIRE( custom.getStr() == "CustomValue" );
} Does this answer your question? 🙂 |
As for |
Hey SSBMTonberry, Sorry, been a bit busy. I am a bit confused though. So it should already parse any custom keys from the JSON file correct? For instance, in Tiled where the properties are you can add for example, "num" and assign it as 9. Irrelevant variable, but I'm sure there could be valuable variables. At the time, I had added "ColorTest" (something like that) as a property, which I actually just assigned an int value to see if it was even reading it. After getting the map of properties, I was unable to find it, or anything for that matter after
As you can see What I am expecting is all those properties showing up, name, and value. I can't access the vector or map because it's size is 0.
|
No problem! If you'd want to add {
"height":19,
"id":12,
"name":"text",
"properties":[
{
"name":"num",
"type":"int",
"value":9
}],
"rotation":0,
"text":
{
"color":"#fefefe",
"text":"Tileson - Demo Map",
"wrap":true
},
"type":"",
"visible":true,
"width":170,
"x":144,
"y":0
} Then I just get it like this: int num = map->getLayer("Object Layer")->firstObj("text")->get<int>("num"); It would otherwise show up in your for-loop like any other property would 🙂 The for-loop you have to print the values looks like it will fail as well, if your To be clear: The only property you will get from this example is 1, which is |
Appreciate it, great! Merry Christmas. |
Hello,
I'm wondering how you retrieve the Color property and then access the RGB values. I'm trying to make a text from TILED parse the correct color data and create a sf::Text.
Thanks
The text was updated successfully, but these errors were encountered: