-
Notifications
You must be signed in to change notification settings - Fork 24
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
Missing Color type of custom property . #12
Comments
I write a method for detect property type , but it's not good. I hope TIledMap could supply some ways. function parseProperties(obj) {
// const properties = obj.properties()
const properties = obj.resolvedProperties()
const p = {}
for (const key in properties) {
const value = properties[key]
const isObject = typeof value === 'object';
const isString = typeof value === 'string';
// const isNumber = typeof value === 'number'
// const isBoolean = typeof value === 'boolean'
const str = String(value)
if (isObject && str.indexOf('Tiled::ObjectRef') === 0) {
// object, but unset
continue
}
if (isObject && str.indexOf('Tiled::EditableMapObject') === 0) {
// object
p[key] = {
id: value.id,
location: ObjectLocation[value.id]
}
} else if (isObject && str.indexOf('#') === 0) {
// color
p[key] = {
color: str
}
} else if (isObject && value && !value.url) {
// file , but unset
continue
} else if (isObject && value && value.url) {
// file
p[key] = {
file: value.url
}
} else if (isString && !value) {
// string , but unset or ""
continue
} else {
// string number boolean
p[key] = value
}
// console.log(key, typeof value, String(value))
}
return p
} |
Right, there is no reliable way to get the type of a property in JavaScript. I think I'll need to add a function like Though one question is, in case of custom classes or enums, whether this function should return the name of the custom class or enum, or a generic string like "class" or "enum". |
when I set a color-type, I can't check it's type.
the
typeof value
is object. but the object hasn't any property.The text was updated successfully, but these errors were encountered: