2014-04-05 16:16:30 +03:00
|
|
|
Sahli Editor
|
|
|
|
|
============
|
|
|
|
|
|
|
|
|
|
Editor for Sahli files.
|
|
|
|
|
|
|
|
|
|
- open existing file
|
|
|
|
|
- create new item
|
|
|
|
|
* get filename from dir
|
|
|
|
|
* insert SAUCE data if available
|
|
|
|
|
* use SAUCE data to find font
|
|
|
|
|
* allow Amiga choices
|
|
|
|
|
* colorpicker
|
|
|
|
|
- edit existing item
|
2014-04-06 15:08:32 +03:00
|
|
|
- remove item
|
|
|
|
|
- clear whole file
|
2014-04-05 16:16:30 +03:00
|
|
|
- copy/clone
|
|
|
|
|
- move items around
|
2014-04-06 15:08:32 +03:00
|
|
|
- sort items
|
2014-04-05 16:16:30 +03:00
|
|
|
- output to screen (copy into file)
|
|
|
|
|
* run from node - save filename dialog
|
|
|
|
|
|
2014-04-16 18:21:19 +03:00
|
|
|
***
|
|
|
|
|
It should be noted that this does not do bounds checking, and it would be very
|
|
|
|
|
possible to overflow this by using a debugger and such. As the purpose of this
|
|
|
|
|
is limited, and this should NOT be put on a live website, I feel that is ok for
|
|
|
|
|
now. Perhaps I will fix it after Revision.
|
|
|
|
|
|
|
|
|
|
***
|
|
|
|
|
|
2014-04-05 16:16:30 +03:00
|
|
|
== Create Initial crappage
|
|
|
|
|
We need to make a screen that has a few things in it for starters
|
|
|
|
|
Title, load existing, and new file options.
|
|
|
|
|
|
|
|
|
|
Silliness for checking that this works.
|
2014-04-14 20:09:27 +03:00
|
|
|
|
2014-04-05 16:16:30 +03:00
|
|
|
$(-> $("h1").hide().slideDown(500))
|
|
|
|
|
|
2014-04-15 15:49:09 +03:00
|
|
|
Create buttos to choose between the New and Load functionalities
|
2014-04-06 15:08:32 +03:00
|
|
|
(As we aren't going to ever load a file _and_ do a new file.)
|
|
|
|
|
(If someone wants to do that, they can restart with F5 or something.)
|
2014-04-15 15:49:09 +03:00
|
|
|
Also hide the editor until needed, and initialize some elements.
|
2014-04-06 15:08:32 +03:00
|
|
|
|
2014-04-14 13:47:01 +03:00
|
|
|
$(->
|
|
|
|
|
$("#newsahli")
|
|
|
|
|
.button { disabled: false}
|
2014-04-15 15:49:09 +03:00
|
|
|
.click -> newsahli()
|
|
|
|
|
)
|
2014-04-14 13:47:01 +03:00
|
|
|
|
|
|
|
|
$(->
|
|
|
|
|
$("#loadsahli")
|
|
|
|
|
.button { disabled: false}
|
2014-04-15 16:23:32 +03:00
|
|
|
.click -> loadsahli()
|
2014-04-14 13:47:01 +03:00
|
|
|
)
|
2014-04-14 20:09:27 +03:00
|
|
|
$(->
|
|
|
|
|
$(".hidden").hide()
|
2014-04-16 11:23:56 +03:00
|
|
|
$("#entryamiga").button {icons: {primary:"ui-icon-gear"}}
|
2014-04-15 14:07:52 +03:00
|
|
|
.click ->
|
|
|
|
|
stuff = $(@).children()
|
|
|
|
|
if @.value == "1"
|
|
|
|
|
stuff[1].textContent = 'Ansi'
|
|
|
|
|
@.value = "0"
|
|
|
|
|
else
|
|
|
|
|
stuff[1].textContent = 'Ascii'
|
|
|
|
|
@.value = "1"
|
2014-04-16 07:51:06 +03:00
|
|
|
$(".45box").css {width:'45%',display:'inline-block'}
|
|
|
|
|
$(".groupbox p").css {margin:"0 0 .25em 0"}
|
2014-04-16 00:54:12 +03:00
|
|
|
$("#entryfilepick").change ->
|
|
|
|
|
if @.files[0]? then $("#entryfile").val @.files[0].name
|
|
|
|
|
$("#entryfile").click ->
|
|
|
|
|
$("#entryfilepick").click()
|
2014-04-15 14:07:52 +03:00
|
|
|
)
|
2014-04-06 15:08:32 +03:00
|
|
|
|
2014-04-14 13:47:01 +03:00
|
|
|
The sahli file definition format is as follows:
|
|
|
|
|
"file" - the actual filename on disk, "name" - the title of the piece,
|
|
|
|
|
the boolean 'amiga' indicates if it is ansi or ascii (True = ascii),
|
|
|
|
|
width is the width (widest point of the file), author the author of the piece,
|
|
|
|
|
the color and bg items define the color for amiga ascii, and the font
|
|
|
|
|
defines the font similarly. For PC ansi, this should be 'ansifont.'
|
|
|
|
|
The three remaining lines are informational and optional.
|
|
|
|
|
|
|
|
|
|
The slide format is currently unused, but consists of a background picture,
|
|
|
|
|
a html template, and a css file.
|
|
|
|
|
|
|
|
|
|
class Sahli
|
2014-04-14 14:25:37 +03:00
|
|
|
constructor: ->
|
2014-04-15 15:49:09 +03:00
|
|
|
@emptyfiledef = {
|
2014-04-14 14:25:37 +03:00
|
|
|
"file": "",
|
|
|
|
|
"name": "",
|
|
|
|
|
"amiga": true,
|
|
|
|
|
"width": "",
|
|
|
|
|
"author": "",
|
|
|
|
|
"font": "Propaz",
|
|
|
|
|
"color": [ 0,0,0,0 ],
|
|
|
|
|
"bg": [ 0,0,0,0 ],
|
|
|
|
|
"line1": "",
|
|
|
|
|
"line2": "",
|
|
|
|
|
"text": ""
|
|
|
|
|
}
|
2014-04-15 15:49:09 +03:00
|
|
|
@emptyslidesdef = {
|
2014-04-14 14:25:37 +03:00
|
|
|
"background": "",
|
|
|
|
|
"template": "",
|
|
|
|
|
"css": ""
|
|
|
|
|
}
|
2014-04-15 15:49:09 +03:00
|
|
|
@empty = {
|
|
|
|
|
"slides": @emptyslidesdef,
|
2014-04-15 16:23:32 +03:00
|
|
|
"filedata": [ ]
|
2014-04-14 14:25:37 +03:00
|
|
|
}
|
2014-04-14 13:47:01 +03:00
|
|
|
|
2014-04-14 20:09:27 +03:00
|
|
|
loader: ->
|
2014-04-15 16:23:32 +03:00
|
|
|
$.ajax {
|
|
|
|
|
url: '../list.sahli',
|
|
|
|
|
dataType: "json",
|
|
|
|
|
success: (result) =>
|
|
|
|
|
@data = result
|
|
|
|
|
@.edit()
|
|
|
|
|
}
|
2014-04-14 20:09:27 +03:00
|
|
|
|
2014-04-15 15:49:09 +03:00
|
|
|
Editor functionality:
|
|
|
|
|
Close the new/load buttons - unneeded now.
|
|
|
|
|
list, and allow dragon-droppings for sorting. Doubleclick to edit, or use
|
|
|
|
|
edit button.
|
|
|
|
|
|
|
|
|
|
edit: ->
|
|
|
|
|
$('#buttonbox').hide()
|
2014-04-16 00:54:12 +03:00
|
|
|
$('#listsave').button {icons: {primary:"ui-icon-disk"}}
|
|
|
|
|
.click =>
|
|
|
|
|
alert 'SAVE ME'
|
2014-04-16 11:14:16 +03:00
|
|
|
|
2014-04-16 00:54:12 +03:00
|
|
|
You need to save the order, and extract these in that order; moving around
|
|
|
|
|
does not alter the array. Alternately, _have_ it alter the array.
|
|
|
|
|
|
2014-04-15 15:49:09 +03:00
|
|
|
@buildlist @data
|
|
|
|
|
|
|
|
|
|
buildlist: (data) ->
|
|
|
|
|
$('#list').show 100
|
2014-04-15 18:57:23 +03:00
|
|
|
$('#sortlist').append @.additem item for item in @data.filedata
|
2014-04-16 18:21:19 +03:00
|
|
|
$('#sortlist').sortable
|
|
|
|
|
start: (event,ui) ->
|
|
|
|
|
ui.item.data {startpos:ui.item.index()}
|
|
|
|
|
stop: (event,ui) =>
|
|
|
|
|
s = ui.item.data().startpos
|
|
|
|
|
e = ui.item.index()
|
|
|
|
|
@data.filedata = @.rearrangearray s,e,@data.filedata
|
|
|
|
|
console.log name.author for name in @data.filedata
|
|
|
|
|
console.log '---'
|
|
|
|
|
|
|
|
|
|
Given a start and and end position, pop the array element at start off and
|
|
|
|
|
insert it into the array at end position. A la the draggon-dropping.
|
|
|
|
|
|
|
|
|
|
rearrangearray: (startpos,endpos,a) ->
|
|
|
|
|
moving = a[startpos]
|
|
|
|
|
alen = a.length
|
|
|
|
|
tarr = a[0...startpos].concat a[startpos+1..-1]
|
|
|
|
|
tarr[0...endpos].concat [moving].concat tarr[endpos..-1]
|
2014-04-15 18:57:23 +03:00
|
|
|
|
2014-04-15 15:49:09 +03:00
|
|
|
|
|
|
|
|
additem: (item) ->
|
2014-04-16 00:54:12 +03:00
|
|
|
entry = $("<li class='entry' id='#{item.file}'><span class='ui-icon ui-icon-arrowthick-2-n-s'></span>#{item.author} : #{item.name} : #{item.file}</li>")
|
|
|
|
|
entry.dblclick =>
|
|
|
|
|
@.editline item
|
2014-04-15 15:49:09 +03:00
|
|
|
|
|
|
|
|
editline: (data) ->
|
|
|
|
|
$("#formica").dialog {
|
|
|
|
|
width:'800',
|
|
|
|
|
modal: false,
|
2014-04-16 00:54:12 +03:00
|
|
|
title:"Entry #{data.file} ",
|
|
|
|
|
buttons: [{
|
2014-04-16 11:14:16 +03:00
|
|
|
text: "Cancel",
|
|
|
|
|
icons: {primary: 'ui-icon-trash'},
|
|
|
|
|
click: ->
|
|
|
|
|
$(@).dialog "close"
|
|
|
|
|
},{
|
|
|
|
|
text: "Save",
|
|
|
|
|
icons: {primary: 'ui-icon-disk'},
|
2014-04-15 15:49:09 +03:00
|
|
|
click: ->
|
2014-04-16 11:14:16 +03:00
|
|
|
$('#smt').click()
|
2014-04-15 15:49:09 +03:00
|
|
|
$(@).dialog "close"
|
2014-04-16 11:14:16 +03:00
|
|
|
|
|
|
|
|
}]
|
2014-04-16 00:54:12 +03:00
|
|
|
}
|
2014-04-16 10:03:52 +03:00
|
|
|
|
2014-04-16 11:49:40 +03:00
|
|
|
$("#smt").click (event) =>
|
2014-04-16 11:14:16 +03:00
|
|
|
event.preventDefault()
|
2014-04-16 18:21:19 +03:00
|
|
|
|
|
|
|
|
alert @
|
2014-04-16 11:14:16 +03:00
|
|
|
|
2014-04-16 11:49:40 +03:00
|
|
|
data.amiga = booltoint data.amiga
|
|
|
|
|
|
2014-04-16 18:21:19 +03:00
|
|
|
$("#entryindex").val data.index
|
2014-04-16 00:54:12 +03:00
|
|
|
$("#entryname").val data.name
|
|
|
|
|
$("#entryauthor").val data.author
|
|
|
|
|
$("#entryamiga").val data.amiga
|
2014-04-16 11:49:40 +03:00
|
|
|
$("#entryamiga").children()[1].textContent = ansiorascii data.amiga
|
2014-04-16 00:54:12 +03:00
|
|
|
$("#entryfont").val data.font
|
|
|
|
|
|
|
|
|
|
fix these color entries to supply rgb() bits
|
|
|
|
|
|
|
|
|
|
$("#entrycolor").val data.color
|
|
|
|
|
$("#entrybg").val data.bg
|
|
|
|
|
$("#entrywidth").val data.width
|
|
|
|
|
$("#entryline1").val data.line1
|
|
|
|
|
$("#entryline2").val data.line2
|
|
|
|
|
$("#entrytext").val data.text
|
|
|
|
|
$("#entryfile").val data.file
|
|
|
|
|
Need to change the file name, but we don't seem to have the ability to do so.
|
|
|
|
|
|
2014-04-14 20:09:27 +03:00
|
|
|
|
|
|
|
|
A Helper function to dump json out of an object as text:
|
|
|
|
|
|
2014-04-14 13:47:01 +03:00
|
|
|
dumpjson = (obj) ->
|
|
|
|
|
JSON.stringify(obj)
|
|
|
|
|
|
2014-04-16 11:49:40 +03:00
|
|
|
Boolean / integer Helpers
|
|
|
|
|
|
|
|
|
|
booltoint = (bool) ->
|
|
|
|
|
bool + 1 - 1
|
|
|
|
|
|
|
|
|
|
inttobool = (intstr) ->
|
|
|
|
|
(intstr == 1).toString()
|
|
|
|
|
|
|
|
|
|
Resolve ansi or ascii status
|
|
|
|
|
|
|
|
|
|
ansiorascii = (status) ->
|
|
|
|
|
if status is 0 then "Ansi" else "Ascii"
|
|
|
|
|
|
|
|
|
|
|
2014-04-16 10:03:52 +03:00
|
|
|
Color conversion from array to color item:
|
|
|
|
|
|
|
|
|
|
This decimal to hex conversion only handles 00-FF but it's fine for this purpose;
|
|
|
|
|
we actually _want_ that limitation in the output.
|
|
|
|
|
|
|
|
|
|
dec2hex = (num) ->
|
|
|
|
|
"#{('000'+num.toString 16).slice -2}"
|
|
|
|
|
|
|
|
|
|
hex2dec = (num) ->
|
|
|
|
|
parseInt num,16
|
|
|
|
|
|
|
|
|
|
arraytocolor = (array) ->
|
|
|
|
|
c = (dec2hex x for x in array)[0..2].join ''
|
|
|
|
|
"##{c}"
|
|
|
|
|
|
|
|
|
|
colortoarray = (color) ->
|
|
|
|
|
re = /(\d\d)(\d\d)(\d\d)/
|
|
|
|
|
c = color.slice 1
|
|
|
|
|
c1 = c.replace re,"$1,$2,$3"
|
|
|
|
|
x = (hex2dec i for i in c1.split ",")
|
|
|
|
|
x.push 0
|
|
|
|
|
x
|
|
|
|
|
|
2014-04-14 20:09:27 +03:00
|
|
|
When clicking 'New' we want to make a brand new Sahli, and then clear out
|
|
|
|
|
the buttons and create the editor bit as blank.
|
|
|
|
|
|
2014-04-14 13:47:01 +03:00
|
|
|
newsahli = ->
|
|
|
|
|
sahli = new Sahli
|
2014-04-15 15:49:09 +03:00
|
|
|
sahli.data = sahli.empty
|
2014-04-15 16:23:32 +03:00
|
|
|
sahli.data.filedata.push sahli.emptyfiledef
|
2014-04-15 15:49:09 +03:00
|
|
|
sahli.edit()
|
2014-04-14 20:09:27 +03:00
|
|
|
|
2014-04-15 15:49:09 +03:00
|
|
|
And when clicking 'load' we want to load the existing sahli file.
|
2014-04-14 14:25:37 +03:00
|
|
|
|
2014-04-15 15:49:09 +03:00
|
|
|
loadsahli = ->
|
|
|
|
|
sahli = new Sahli
|
2014-04-15 16:23:32 +03:00
|
|
|
sahli.loader 'list.sahli'
|