Mercurial > hg > forks > multipaint-js
changeset 212:b3579297e04e
Implement rest of the stuff needed for selecting external palettes in the
launcher and actual Multipaint code.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 03 Sep 2018 14:22:20 +0300 |
parents | 6d866e284dd2 |
children | ddb36f1c515f |
files | files.pde mpui.js multipaint.pde |
diffstat | 3 files changed, 26 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/files.pde Wed Aug 29 20:27:00 2018 +0300 +++ b/files.pde Mon Sep 03 14:22:20 2018 +0300 @@ -233,13 +233,16 @@ // XXX TODO: Make this support other platforms than C64 boolean mpLoadPalette(String fname) { - byte fdata[] = mpLoadbinaryFile(fname); + String ffname = "palettes/"+ g_map[13] +"/"+ fname; + byte fdata[] = mpLoadBinaryFile(ffname); + if (fdata == null || fdata.length != 772 || - fdata[0x301] != byte(0x10) || - fdata[0x302] != byte(0xff) || - fdata[0x303] != byte(0xff)) + fdata[0x301] != 0x10 || + fdata[0x302] != 0xff || + fdata[0x303] != 0xff) { + console.log("Could not load palette file '"+ ffname +"'."); return false; }
--- a/mpui.js Wed Aug 29 20:27:00 2018 +0300 +++ b/mpui.js Mon Sep 03 14:22:20 2018 +0300 @@ -2,8 +2,9 @@ * Multipaint.JS - Javascript launcher * (C) Copyright 2018 Matti 'ccr' Hämäläinen <ccr@tnsp.org> */ -var mpMachine = 0, mpUIScale, mpUIForcedWidth, mpUIForcedHeight; -var mpURL; +var mpMachine = 0, mpUIScale, + mpUIForcedWidth, mpUIForcedHeight, mpURL, + mpUIPalette; // Machine ID, Name/desc, Alt.palette array index (-1 if none) var mpMachines = @@ -146,13 +147,18 @@ } +function stCleanFilename(vstr) +{ + return vstr.replace(/[^a-z0-9_\.]/ig, ""); +} + + function mpMachineChanged() { var tmp = stGetSelIndex("machineID"); var velem = stGE("paletteID"); var palID = mpMachines[tmp][2]; velem.style.display = (palID >= 0) ? "block" : "none"; - velem.disabled = true; stClearChildren(velem); if (palID >= 0) { @@ -209,7 +215,6 @@ mdiv.appendChild(mobj); mobj.appendChild(stCE("select", "paletteID")); - mdiv = stCE("div", "mdimensions"); mpUI.appendChild(mdiv); @@ -269,6 +274,9 @@ mpUIForcedWidth = mpUIForcedHeight = 0; mpUIScale = stGetSelValue(stGE("scalesID"), -1); + index = stGetSelValue(stGE("paletteID"), -1); + if (index >= 0) + mpUIPalette = mpPalettes[mpMachine][index]; stClearChildren(mpUI); @@ -276,7 +284,9 @@ var mpCanvas = stGE("mpCanvas"); mpCanvas.style.display = "block"; - window.location.href = mpURL +"?"+ mpMachine.toString() +":"+ mpUIForcedWidth +":"+ mpUIForcedHeight +":"+ mpUIScale; + window.location.href = mpURL +"?"+ + mpMachine.toString() +":"+ + mpUIForcedWidth +":"+ mpUIForcedHeight +":"+ mpUIScale +":"+ mpUIPalette; mpRunSketch(mpCanvas); } @@ -305,6 +315,9 @@ } if (sargs.length >= 4) mpUIScale = parseInt(sargs[3]); + + if (sargs.length >= 5) + mpUIPalette = stCleanFilename(sargs[4]); } else mpURL = slink;
--- a/multipaint.pde Wed Aug 29 20:27:00 2018 +0300 +++ b/multipaint.pde Mon Sep 03 14:22:20 2018 +0300 @@ -111,6 +111,7 @@ g_uiscale = (mpUIScale >= 1 && mpUIScale <= 3) ? mpUIScale : 2; g_forced_width = mpUIForcedWidth > 0 ? mpUIForcedWidth : 0; g_forced_height = mpUIForcedHeight > 0 ? mpUIForcedHeight : 0; + g_forced_palette = mpUIPalette ? mpUIPalette : ""; g_animspeed = 1; //normi