From 9cf45d8300b4e89927e61af9e4a9381cc3d75078 Mon Sep 17 00:00:00 2001 From: "Avi Halachmi (:avih)" Date: Sat, 7 Mar 2020 12:00:33 +0200 Subject: js: osd-overlay update: support arbitrary key names Until now the 'update' method used mp.command_native with a hardcoded list of key names. Change it to use whatever keys the user set to this object, so that we can remain oblivious to new keys which 'osd-overlay' may support. This is how the lua code did it from the begining. We didn't, and now we pay the price. Note: could be implemented either as we have now (clone `this` excluding the methods) or by moving the methods up the prototype chain (i.e. class methods) so they don't get enumerated and use `this` as the command object itself. However, in the latter approach we'll have to save the values which we change (name, res_x, res_y) and restore them after the command, so it's simpler to just clone `this`. --- player/javascript/defaults.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/player/javascript/defaults.js b/player/javascript/defaults.js index dcea6734a0..31f944727d 100644 --- a/player/javascript/defaults.js +++ b/player/javascript/defaults.js @@ -204,15 +204,17 @@ mp.create_osd_overlay = function create_osd_overlay(format) { z: 0, update: function ass_update() { - mp.command_native({ - name: "osd-overlay", - format: this.format, - id: this.id, - data: this.data, - res_x: Math.round(this.res_x), - res_y: Math.round(this.res_y), - z: this.z, - }); + var cmd = {}; // shallow clone of `this', excluding methods + for (var k in this) { + if (typeof this[k] != "function") + cmd[k] = this[k]; + } + + cmd.name = "osd-overlay"; + cmd.res_x = Math.round(this.res_x); + cmd.res_y = Math.round(this.res_y); + + mp.command_native(cmd); return mp.last_error() ? undefined : true; }, -- cgit v1.2.3