Path: blob/main/misc/retro-bowl/html5game/uph_poki.js
28391 views
console.log("Poki wrapper load");1///~2function poki_init_raw() {3console.log("Poki wrapper init");4// fix GMS1 bug with iframes5var ctr = document.getElementById("gm4html5_div_id");6if (ctr && !ctr.frames) ctr.frames = [];7return 0;8}9///~10function poki_script_closure_raw(self, other, script, custom) {11return function (result) {12window.gml_Script_gmcallback_poki_closure(self, other, script, result, custom);13};14}1516function poki_is_blocked() {17return !window.PokiSDK_OK;18}1920function poki_gameplay_start() {21if (PokiSDK) PokiSDK.gameplayStart();22}2324function poki_gameplay_stop() {25if (PokiSDK) PokiSDK.gameplayStop();26}2728function poki_happy_time(magnitude) {29if (PokiSDK) PokiSDK.happyTime(magnitude);30}3132///~33function poki_commercial_break_raw(fn) {34if (PokiSDK) {35PokiSDK.commercialBreak().then(function () {36fn(true);37});38} else39setTimeout(function () {40fn(false);41}, 0);42}4344///~45function poki_rewarded_break_raw(fn) {46if (PokiSDK) {47PokiSDK.rewardedBreak().then(fn);48} else49setTimeout(function () {50fn(false);51}, 0);52}5354/// https://yal.cc/gamemaker-html5-loading-bar-extended/55var inst = {};56///~57function poki_loadbar(ctx, width, height, total, current, image) {58if (window.PokiSDK) {59// if you have your own loadbar, just copy this block in there60if (window.PokiSDK_loadState == 0) {61window.PokiSDK_isLoading = 1;62PokiSDK.gameLoadingStart();63}64PokiSDK.gameLoadingProgress({ percentageDone: current / total });65if (current >= total && window.PokiSDK_loadState != 2) {66window.PokiSDK_loadState = 2;67PokiSDK.gameLoadingFinished();68}69}7071function getv(s) {72if (window.gml_Script_gmcallback_poki_loadbar) {73return window.gml_Script_gmcallback_poki_loadbar(inst, null, s, current, total, width, height, image ? image.width : 0, image ? image.height : 0);74} else return undefined;75}76function getf(s, d) {77var r = getv(s);78return typeof r == "number" ? r : d;79}80function getw(s, d) {81var r = getv(s);82return r && r.constructor == Array ? r : d;83}84function getc(s, d) {85var r = getv(s);86if (typeof r == "number") {87r = r.toString(16);88while (r.length < 6) r = "0" + r;89return "#" + r;90} else if (typeof r == "string") {91return r;92} else return d;93}94// get parameters:95var backgroundColor = getc("background_color", "#FFFFFF");96var barBackgroundColor = getc("bar_background_color", "#FFFFFF");97var barForegroundColor = getc("bar_foreground_color", "#242238");98var barBorderColor = getc("bar_border_color", "#242238");99var barWidth = getf("bar_width", Math.round(width * 0.6));100var barHeight = getf("bar_height", 20);101var barBorderWidth = getf("bar_border_width", 2);102var barOffset = getf("bar_offset", 10);103// background:104ctx.fillStyle = backgroundColor;105ctx.fillRect(0, 0, width, height);106// image:107var totalHeight, barTop;108if (image != null) {109var rect = getw("image_rect");110if (!rect) rect = [0, 0, image.width, image.height];111totalHeight = rect[3] + barOffset + barHeight;112var image_y = (height - totalHeight) >> 1;113ctx.drawImage(image, rect[0], rect[1], rect[2], rect[3], (width - rect[2]) >> 1, image_y, rect[2], rect[3]);114barTop = image_y + rect[3] + barOffset;115} else barTop = (height - barHeight) >> 1;116// bar border:117var barLeft = (width - barWidth) >> 1;118ctx.fillStyle = barBorderColor;119ctx.fillRect(barLeft, barTop, barWidth, barHeight);120//121var barInnerLeft = barLeft + barBorderWidth;122var barInnerTop = barTop + barBorderWidth;123var barInnerWidth = barWidth - barBorderWidth * 2;124var barInnerHeight = barHeight - barBorderWidth * 2;125// bar background:126ctx.fillStyle = barBackgroundColor;127ctx.fillRect(barInnerLeft, barInnerTop, barInnerWidth, barInnerHeight);128// bar foreground:129var barLoadedWidth = Math.round((barInnerWidth * current) / total);130ctx.fillStyle = barForegroundColor;131ctx.fillRect(barInnerLeft, barInnerTop, barLoadedWidth, barInnerHeight);132}133///~134function poki_get_team_raw() {135return PokiSDK.getURLParam("team");136}137138function poki_set_team_raw(team) {139return window.parent.postMessage({ type: "RetroBowl_teamSwitch", content: { team } }, "*");140}141142