History

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`.

Avi Halachmi (:avih) committed 6 years ago

Commit 9cf45d81 parent ba70b151 file · +11 −9Browse files

Showing the changes to player/javascript (1 of 1 file). Show all

Unified · Split

player/javascript/defaults.js+11−9
@@ -204,15 +204,17 @@ mp.create_osd_overlay = function create_osd_overlay(format) { · 203 unmodified lines
204 z: 0,204 z: 0,
205 205
206 update: function ass_update() {206 update: function ass_update() {
207 mp.command_native({207 var cmd = {}; // shallow clone of `this', excluding methods
208 name: "osd-overlay",208 for (var k in this) {
209 format: this.format,209 if (typeof this[k] != "function")
210 id: this.id,210 cmd[k] = this[k];
211 data: this.data,211 }
212 res_x: Math.round(this.res_x),212
213 res_y: Math.round(this.res_y),213 cmd.name = "osd-overlay";
214 z: this.z,214 cmd.res_x = Math.round(this.res_x);
215 });215 cmd.res_y = Math.round(this.res_y);
216
217 mp.command_native(cmd);
216 return mp.last_error() ? undefined : true;218 return mp.last_error() ? undefined : true;
217 },219 },
218 220

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t