This is less of a bug report and more calling out an inconvenient, breaking pattern, but here goes.
If I write a call like this:
anims.create(object : AnimationConfig {
override var key: String? = "misa-left-walk"
override var frames: Array<AnimationFrameConfig>? = anims.generateFrameNames("atlas", json("prefix" to "misa-left-walk", "start" to 0, "end" to 3, "zeroPad" to 3))
override var frameRate: Int? = 10
override var repeat: Int? = -1
})
where AnimationConfig
is something like this:
external interface AnimationConfig {
var key: String? get() = definedExternally; set(value) = definedExternally
var frames: Array<AnimationFrameConfig>? get() = definedExternally; set(value) = definedExternally
var frameRate: Int? get() = definedExternally; set(value) = definedExternally
var repeat: Int? get() = definedExternally; set(value) = definedExternally
}
The object expression above gets turned into this:
function tuxemon$lambda$lambda$lambda$ObjectLiteral_0(this$) {
this.key_jq6mq5$_0 = 'misa-left-walk';
this.frames_93w5a6$_0 = this$.anims.generateFrameNames('atlas', json([to('prefix', 'misa-left-walk'), to('start', 0), to('end', 3), to('zeroPad', 3)]));
this.frameRate_2yfl4x$_0 = 10;
this.repeat_j15sdp$_0 = -1;
}
Object.defineProperty(tuxemon$lambda$lambda$lambda$ObjectLiteral_0.prototype, 'key', {get: function () {
return this.key_jq6mq5$_0;
}, set: function (key) {
this.key_jq6mq5$_0 = key;
}});
Object.defineProperty(tuxemon$lambda$lambda$lambda$ObjectLiteral_0.prototype, 'frames', {get: function () {
return this.frames_93w5a6$_0;
}, set: function (frames) {
this.frames_93w5a6$_0 = frames;
}});
// snip
Defining key
, frames
, frameRate
, and repeat
as prototypal properties is problematic for libraries that do hasOwnProperty
checks, such as Phaser, in GetValue. Basically, the above code actually doesn’t work – because Phaser checks for attributes in the AnimationConfig
using hasOwnProperty
, it never sees any of the attributes I’m passing in in the above example.
The workaround is moderately annoying – create a dynamic object using js("{}")
and “cast” it to an AnimationConfig
.