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
204204 z: 0,
205205
206206 update: function ass_update() {
207− mp.command_native({
208− name: "osd-overlay",
209− format: this.format,
210− id: this.id,
211− data: this.data,
212− res_x: Math.round(this.res_x),
213− res_y: Math.round(this.res_y),
214− z: this.z,
215− });
207+ var cmd = {}; // shallow clone of `this', excluding methods
208+ for (var k in this) {
209+ if (typeof this[k] != "function")
210+ cmd[k] = this[k];
211+ }
212+
213+ cmd.name = "osd-overlay";
214+ cmd.res_x = Math.round(this.res_x);
215+ cmd.res_y = Math.round(this.res_y);
216+
217+ mp.command_native(cmd);
216218 return mp.last_error() ? undefined : true;
217219 },
218220

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