From 61686c559cb25e9e72a32264a28901dbdf89cf7b Mon Sep 17 00:00:00 2001 From: Iam Naughton Phier Date: Wed, 6 Aug 2014 15:24:11 +0300 Subject: [PATCH] bugfix: color functions / color defs / color selection --- editor/sahliedit.js | 44 ++++++++++++++++++++++++++++++++------ editor/sahliedit.litcoffee | 40 +++++++++++++++++++++++++++++----- 2 files changed, 72 insertions(+), 12 deletions(-) diff --git a/editor/sahliedit.js b/editor/sahliedit.js index 00b93e7..039de7e 100644 --- a/editor/sahliedit.js +++ b/editor/sahliedit.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript 1.7.1 (function() { - var Sahli, ansiorascii, arraytocolor, booltoint, colortoarray, colortoname, dec2hex, dumpjson, hex2dec, inttobool, loadsahli, newsahli, resolvefiletype, statustobool; + var Sahli, ansiorascii, arraytocolor, booltoint, colorindex, colortoarray, colortoname, dec2hex, dumpjson, hex2dec, inttobool, loadsahli, newsahli, resolvefiletype, statustobool; $(function() { return $("h1").hide().slideDown(500); @@ -199,6 +199,7 @@ }; Sahli.prototype.editline = function(data, pos) { + var bcol, fcol; $("#formica").dialog({ width: '800', modal: false, @@ -228,6 +229,8 @@ ] }); data.amiga = booltoint(data.amiga); + fcol = colortoname(arraytocolor(data.color)); + bcol = colortoname(arraytocolor(data.bg)); $("#entryindex").val(pos); $("#entryname").val(data.name); $("#entryauthor").val(data.author); @@ -236,8 +239,10 @@ $("#entryamiga").val(data.amiga); $("#entryamiga").children()[1].textContent = ansiorascii(data.amiga); $("#entryfont").val(data.font); - $("#entrycolor").val(colortoname(arraytocolor(data.color))); - $("#entrybg").val(colortoname(arraytocolor(data.bg))); + $("#entrycolor").val(fcol); + $("#entrycolor").children()[colorindex(fcol)].selected = true; + $("#entrybg").val(bcol); + $("#entrybg").children()[colorindex(bcol)].selected = true; $("#entrywidth").val(data.width); $("#entryline1").val(data.line1); $("#entryline2").val(data.line2); @@ -334,7 +339,7 @@ }; colortoname = function(color) { - var names, x; + var bw, colorname, names, ret; names = { "#E0E0E0": "Light Grey", "#A0A0E0": "Light Blue", @@ -342,9 +347,9 @@ "#FF0000": "Red", "#FF8000": "Orange", "#FFFF00": "Yellow", - "#00f000": "Green", + "#00F000": "Green", "#2EFEF7": "Cyan", - "#2EFEF7": "Blue", + "#002EF7": "Blue", "#0B0B3B": "Navy", "#FF00FF": "Magenta", "#8000FF": "Purple", @@ -354,7 +359,32 @@ "#000000": "Black" }; color = color.toUpperCase(); - return x = hex2dec(color.slice(1)) > 8421504 ? "#FFFFFF" : "#000000"; + colorname = names[color]; + bw = hex2dec(color.slice(1)) > 8421504 ? 'White' : "Black"; + return ret = colorname != null ? colorname : bw; + }; + + colorindex = function(colorname) { + var names; + names = { + "Light Grey": 0, + "Light Blue": 1, + "Light Green": 2, + "Red": 3, + "Orange": 4, + "Yellow": 5, + "Green": 6, + "Cyan": 7, + "Blue": 8, + "Navy": 9, + "Magenta": 10, + "Purple": 11, + "Dark Green": 12, + "Dark Grey": 13, + "White": 14, + "Black": 15 + }; + return names[colorname]; }; newsahli = function() { diff --git a/editor/sahliedit.litcoffee b/editor/sahliedit.litcoffee index 1dfe1d0..ef20c5b 100644 --- a/editor/sahliedit.litcoffee +++ b/editor/sahliedit.litcoffee @@ -218,6 +218,9 @@ insert it into the array at end position. A la the draggon-dropping. data.amiga = booltoint data.amiga + fcol = colortoname arraytocolor data.color + bcol = colortoname arraytocolor data.bg + $("#entryindex").val pos $("#entryname").val data.name $("#entryauthor").val data.author @@ -226,8 +229,10 @@ insert it into the array at end position. A la the draggon-dropping. $("#entryamiga").val data.amiga $("#entryamiga").children()[1].textContent = ansiorascii data.amiga $("#entryfont").val data.font - $("#entrycolor").val colortoname arraytocolor data.color - $("#entrybg").val colortoname arraytocolor data.bg + $("#entrycolor").val fcol + $("#entrycolor").children()[colorindex fcol ].selected = true + $("#entrybg").val bcol + $("#entrybg").children()[colorindex bcol ].selected = true $("#entrywidth").val data.width $("#entryline1").val data.line1 $("#entryline2").val data.line2 @@ -306,9 +311,9 @@ Need a way to convert the array back to the color name. "#FF0000":"Red" "#FF8000":"Orange" "#FFFF00":"Yellow" - "#00f000":"Green" + "#00F000":"Green" "#2EFEF7":"Cyan" - "#2EFEF7":"Blue" + "#002EF7":"Blue" "#0B0B3B":"Navy" "#FF00FF":"Magenta" "#8000FF":"Purple" @@ -318,7 +323,32 @@ Need a way to convert the array back to the color name. "#000000":"Black" } color = color.toUpperCase() - x = if hex2dec(color.slice(1)) > 8421504 then "#FFFFFF" else "#000000" + colorname = names[color] + bw = if hex2dec(color.slice(1)) > 8421504 then 'White' else "Black" + ret = if colorname? then colorname else bw + +Similarly, need to be able to get the color index. + + colorindex = (colorname) -> + names = { + "Light Grey":0 + "Light Blue":1 + "Light Green":2 + "Red":3 + "Orange":4 + "Yellow":5 + "Green":6 + "Cyan":7 + "Blue":8 + "Navy":9 + "Magenta":10 + "Purple":11 + "Dark Green":12 + "Dark Grey":13 + "White":14 + "Black":15 + } + names[colorname] When clicking 'New' we want to make a brand new Sahli, and then clear out the buttons and create the editor bit as blank.