Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as alt from "alt";
- import * as native from "natives";
- export default class Scaleform {
- isLoaded: boolean;
- handle: number;
- scaleForm: string;
- constructor(scaleForm: string) {
- this.scaleForm = scaleForm;
- this.handle = 0;
- this.isLoaded = false;
- }
- requestScaleformPromise() {
- return new Promise((resolve, reject) => {
- this.handle = native.requestScaleformMovie(this.scaleForm);
- let check = alt.setInterval(() => {
- if(native.hasScaleformMovieLoaded(this.handle))
- {
- alt.clearInterval(check);
- alt.log('loaded');
- resolve(true);
- } else {
- alt.log('Requesting');
- }
- },(5));
- });
- }
- isValid() {
- return this.handle !== 0;
- }
- async call(funcName: string, data: any) {
- alt.log('called scaleform: '+ funcName+ JSON.stringify(data));
- await this.requestScaleformPromise()
- .then(() => {
- alt.log(`isValid: ${this.isValid()}`);
- if(!this.isValid()) return;
- native.beginScaleformMovieMethod(this.handle, funcName);
- alt.log(`Name: ${funcName}`);
- data.forEach((arg: any)=> {
- switch(typeof arg) {
- case "string":
- {
- alt.log(">string");
- native.scaleformMovieMethodAddParamTextureNameString(arg);
- break;
- }
- case "boolean":
- {
- alt.log(">bool");
- native.scaleformMovieMethodAddParamBool(arg);
- break;
- }
- case "number":
- {
- alt.log(">number");
- if(Number(arg) === arg && arg % 1 !== 0) {
- native.scaleformMovieMethodAddParamFloat(arg);
- } else {
- native.scaleformMovieMethodAddParamInt(arg);
- }
- }
- }
- });
- native.endScaleformMovieMethod();
- this.isLoaded = true;
- }).catch(() => alt.log("reject"));
- }
- renderFullscreen() {
- if(!this.isValid() || !this.isLoaded) return;
- native.drawScaleformMovieFullscreen(this.handle, 255, 255, 255, 255, 0);
- }
- destroy() {
- if(!this.isValid) return;
- native.setScaleformMovieAsNoLongerNeeded(this.handle);
- this.handle = 0;
- this.isLoaded = !this.isLoaded;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement