Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import * as alt from "alt";
  2. import * as native from "natives";
  3.  
  4. export default class Scaleform {
  5.     isLoaded: boolean;
  6.     handle: number;
  7.     scaleForm: string;
  8.     constructor(scaleForm: string) {
  9.         this.scaleForm = scaleForm;
  10.         this.handle = 0;
  11.         this.isLoaded = false;
  12.     }
  13.  
  14.     requestScaleformPromise() {
  15.         return new Promise((resolve, reject) => {
  16.             this.handle = native.requestScaleformMovie(this.scaleForm);
  17.             let check = alt.setInterval(() => {
  18.                 if(native.hasScaleformMovieLoaded(this.handle))
  19.                 {
  20.                     alt.clearInterval(check);
  21.                     alt.log('loaded');
  22.                     resolve(true);
  23.                 } else {
  24.                     alt.log('Requesting');
  25.                 }
  26.  
  27.             },(5));
  28.         });
  29.     }
  30.  
  31.     isValid() {
  32.         return this.handle !== 0;
  33.     }
  34.  
  35.     async call(funcName: string, data: any) {
  36.         alt.log('called scaleform: '+ funcName+ JSON.stringify(data));
  37.         await this.requestScaleformPromise()
  38.         .then(() => {
  39.             alt.log(`isValid: ${this.isValid()}`);
  40.             if(!this.isValid()) return;
  41.  
  42.             native.beginScaleformMovieMethod(this.handle, funcName);
  43.             alt.log(`Name: ${funcName}`);
  44.             data.forEach((arg: any)=> {
  45.                 switch(typeof arg) {
  46.                     case "string":
  47.                     {
  48.                         alt.log(">string");
  49.                         native.scaleformMovieMethodAddParamTextureNameString(arg);
  50.                         break;
  51.                     }
  52.                     case "boolean":
  53.                     {
  54.                         alt.log(">bool");
  55.                         native.scaleformMovieMethodAddParamBool(arg);
  56.                         break;
  57.                     }
  58.                     case "number":
  59.                     {
  60.                         alt.log(">number");
  61.                         if(Number(arg) === arg && arg % 1 !== 0) {
  62.                             native.scaleformMovieMethodAddParamFloat(arg);
  63.                         } else {
  64.                             native.scaleformMovieMethodAddParamInt(arg);
  65.                         }
  66.                     }
  67.                 }
  68.             });
  69.             native.endScaleformMovieMethod();
  70.             this.isLoaded = true;
  71.  
  72.         }).catch(() => alt.log("reject"));
  73.     }
  74.  
  75.     renderFullscreen() {
  76.         if(!this.isValid() || !this.isLoaded) return;
  77.         native.drawScaleformMovieFullscreen(this.handle, 255, 255, 255, 255, 0);
  78.     }
  79.  
  80.     destroy() {
  81.         if(!this.isValid) return;
  82.         native.setScaleformMovieAsNoLongerNeeded(this.handle);
  83.         this.handle = 0;
  84.         this.isLoaded = !this.isLoaded;
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement