Advertisement
kemperrs

Untitled

Dec 8th, 2017
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Scalefrom {
  2.     constructor(scaleformStr) {
  3.         this._handle = mp.game.graphics.requestScaleformMovie(scaleformStr);
  4.         this.queueCallFunction = new Map();
  5.     }
  6.  
  7.     get isLoaded() {
  8.         return !!mp.game.graphics.hasScaleformMovieLoaded(this._handle);
  9.     }
  10.  
  11.     get isValid() {
  12.         return this._handle !== 0;
  13.     }
  14.  
  15.     get handle() {
  16.         return this._handle;
  17.     }
  18.  
  19.     callFunction(strFunction, ...args) {
  20.         if (this.isLoaded && this.isValid) {
  21.             const graphics = mp.game.graphics;
  22.             graphics.pushScaleformMovieFunction(this._handle, strFunction);
  23.             args.forEach(arg => {
  24.                 switch(typeof arg) {
  25.                     case 'string': {
  26.                         graphics.pushScaleformMovieFunctionParameterString(arg);
  27.                         break;
  28.                     }
  29.                     case 'boolean': {
  30.                         graphics.pushScaleformMovieFunctionParameterBool(arg);
  31.                         break;
  32.                     }
  33.                     case 'number': {
  34.                         if(Number(arg) === arg && arg % 1 !== 0) {
  35.                             graphics.pushScaleformMovieFunctionParameterFloat(arg);
  36.                         } else {
  37.                             graphics.pushScaleformMovieFunctionParameterInt(arg);
  38.                         }
  39.                     }
  40.                 }
  41.             });
  42.             graphics.popScaleformMovieFunctionVoid();
  43.         } else {
  44.             this.queueCallFunction.set(strFunction, args);
  45.         }
  46.     }
  47.  
  48.     onUpdate() {
  49.         if (this.isLoaded && this.isValid) {
  50.             this.queueCallFunction.forEach((args, strFunction) => {
  51.                 this.callFunction(strFunction, ...args);
  52.                 this.queueCallFunction.delete(strFunction);
  53.             });
  54.         }
  55.     }
  56.  
  57.     render2D(x, y, width, height) {
  58.         this.onUpdate();
  59.         if (this.isLoaded && this.isValid) {
  60.             const graphics = mp.game.graphics;
  61.             if (typeof x !== 'undefined' && typeof y !== 'undefined' && typeof width !== 'undefined' && typeof height !== 'undefined') {
  62.                 const activeResolution = graphics.getScreenActiveResolution(0, 0);
  63.  
  64.                 graphics.drawScaleformMovie(this._handle, x, y, width, height, 255, 255, 255, 255, 0);
  65.             } else {
  66.                 graphics.drawScaleformMovieFullscreen(this._handle, 255, 255, 255, 255, false);
  67.             }
  68.         }
  69.     }
  70.  
  71.     render3D(position, rotation, scale) {
  72.         this.onUpdate();
  73.         if (this.isLoaded && this.isValid) {
  74.             mp.game.graphics.drawScaleformMovie3dNonAdditive(this._handle, position.x, position.y, position.z, rotation.x, rotation.y, rotation.z, 2, 2, 1, scale.x, scale.y, scale.z, 2);
  75.         }
  76.     }
  77.  
  78.     render3DAdditive(position, rotation, scale) {
  79.         this.onUpdate();
  80.         if (this.isLoaded && this.isValid) {
  81.             mp.game.graphics.drawScaleformMovie3d(this._handle, position.x, position.y, position.z, rotation.x, rotation.y, rotation.z, 2, 2, 1, scale.x, scale.y, scale.z, 2);
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement