'
@@ -311,6 +315,7 @@ $(document).ready(function() {
readFile(this);
});
+ // these inputs get added and removed from the DOM so the event handler needs to be on the document
$(document).on('change', '#palette input', function() {
// if this is a colour input, update the palette
if ($(this).attr('type') === 'color') {
@@ -319,10 +324,32 @@ $(document).ready(function() {
// if this is a radio button, pick this palette
if ($(this).attr('type') === 'radio') {
- palette.background = hexToColour($(this).closest('.palette').find('input[type="color"][name="background"]').val());
- palette.tile = hexToColour($(this).closest('.palette').find('input[type="color"][name="tile"]').val());
+ palette.id = parseInt( $(this).closest('.palette').find('input[name="id"]' ).val());
+ palette.background = hexToColour($(this).closest('.palette').find('input[name="background"]').val());
+ palette.tile = hexToColour($(this).closest('.palette').find('input[name="tile"]' ).val());
+ // sprite colour is not currently used
}
renderResult();
});
+
+ $('#save').on('click touchend', function() {
+ var newGameData = $('textarea').val();
+
+ // need to import IDs so we don't give the new room a conflicting ID
+ var roomNames = newGameData.match(/ROOM \d+/g);
+
+ var newRoomId = parseInt(_.last(roomNames).replace(/[^\d]+/g, "")) + 1;
+
+ var newRoom = "ROOM " + newRoomId + "\n";
+
+ _.each(room, function(row) {
+ newRoom += _.toString(row) + "\n";
+ });
+
+ newRoom += "PAL " + palette.id + "\n";
+
+ // write
+ $('textarea').val(newGameData.replace(/(ROOM .*\n(.*\n)*PAL .*)/g, '$1\n\n' + newRoom));
+ });
});
\ No newline at end of file