/** * @param saveName * @param doneCb (error) called when operation is done */ public void saveAppData(Callback1<String> doneCb) { log.info("saving application config from game storage"); Object data = JSObjectAdapter.$js("{}"); ListUtil.forEachArrayValue( appHandlers, (index, appHandler) -> { Object handlerData = JSObjectAdapter.$js("{}"); appHandler.onAppSave(handlerData); JSObjectAdapter.$put(data, ClassUtil.getClassName(appHandler), handlerData); }); pm.set(CONFIG_APP_JSON, data, (err, savedData) -> doneCb.$invoke(err)); }
public static Canvas pull() { Canvas canvas = (Canvas) Global.window.document.getElementById("store"); if (canvas == null) { canvas = (Canvas) Global.window.document.createElement("canvas"); Global.window.document.body.appendChild(canvas); } canvas.setAttribute("id", "store"); if (buffer == null) { canvas.setAttribute("width", "100"); canvas.setAttribute("height", "100"); } else { canvas.setAttribute("width", "" + lx); canvas.setAttribute("height", "" + ly); } canvas.setAttribute("style", "display:none"); CanvasRenderingContext2D ctx = canvas.getContext("2d"); if (buffer == null) { CanvasImageData imgData = ctx.createImageData(100, 100); for (int i = 0; i < imgData.data.$length(); i += 4) { imgData.data.$set(i, 255); imgData.data.$set(i + 1, 0); imgData.data.$set(i + 2, 0); imgData.data.$set(i + 3, 100); } ctx.putImageData(imgData, 0, 0); } else { CanvasImageData imgData = ctx.createImageData(lx, ly); JSObjectAdapter.$js("var view = new Uint8Array(this.buffer)"); for (int i = 0; i < imgData.data.$length(); i++) JSObjectAdapter.$js("imgData.data[i] = view[i]"); ctx.putImageData(imgData, 0, 0); } return canvas; // Canvas c = (Canvas)Global.window.document.getElementById("gameCanvas"); // ctx = c.getContext("2d"); // ctx.drawImage(canvas, 100, 100); }
public static void push() { Image img = (Image) Global.window.document.getElementById("image"); if (img == null) { img = (Image) Global.window.document.createElement("img"); Global.window.document.body.appendChild(img); } Canvas canvas = (Canvas) Global.window.document.getElementById("store"); if (canvas == null) { canvas = (Canvas) Global.window.document.createElement("canvas"); Global.window.document.body.appendChild(canvas); } canvas.setAttribute("id", "store"); canvas.setAttribute("height", "" + img.height); canvas.setAttribute("width", "" + img.width); canvas.setAttribute("style", "display:none"); CanvasRenderingContext2D ctx = canvas.getContext("2d"); ctx.drawImage(img, 0, 0); Global.console.log("(" + canvas.width + "," + canvas.height + ")"); CanvasImageData imgData = ctx.getImageData(0, 0, canvas.width, canvas.height); // We are going to use that JSObject Adapter to really make sure we obtain // all the JS code // Currently, it is working like intended lx = img.width; ly = img.height; JSObjectAdapter.$js("this.buffer = new ArrayBuffer(imgData.data.length)"); JSObjectAdapter.$js("var view = new Uint8Array(this.buffer)"); for (int i = 0; i < imgData.data.$length(); i++) { JSObjectAdapter.$js("view[i] = imgData.data[i]"); } }
/** * @param saveName * @param doneCb (error) called when operation is done */ public void loadAppData(Callback1<String> doneCb) { pm.get( CONFIG_APP_JSON, (err, data) -> { if (NullUtil.isPresent(data)) { log.info("loading application config from game storage"); ListUtil.forEachArrayValue( appHandlers, (index, appHandler) -> { Object handlerData = JSObjectAdapter.$get(data, ClassUtil.getClassName(appHandler)); if (NullUtil.isPresent(handlerData)) { appHandler.onAppLoad(handlerData); } }); } else { log.info("there is no application config in the game storage yet"); } doneCb.$invoke(""); }); }