@@ -206,10 +206,9 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext {
206206 }
207207
208208 // TODO: move to pixeleditor.ts?
209- addPaletteEditorViews ( parentdiv : JQuery , pal2rgb : pixed . PaletteFormatToRGB , callback ) {
209+ addPaletteEditorViews ( parentdiv : JQuery , pal2rgb : pixed . PaletteFormatToRGB , callback ) : ( ) => void {
210210 var adual = $ ( '<div class="asset_dual"/>' ) . appendTo ( parentdiv ) ;
211211 var aeditor = $ ( '<div class="asset_editor"/>' ) . hide ( ) ; // contains editor, when selected
212- // TODO: they need to update when refreshed from right
213212 var allrgbimgs = [ ] ;
214213 pal2rgb . getAllColors ( ) . forEach ( ( rgba ) => { allrgbimgs . push ( new Uint32Array ( [ rgba ] ) ) ; } ) ; // array of array of 1 rgb color (for picker)
215214 var atable = $ ( '<table/>' ) . appendTo ( adual ) ;
@@ -224,13 +223,17 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext {
224223 layout . push ( [ "" , i , Math . min ( len - i , imgsperline ) ] ) ;
225224 }
226225 }
226+ var cells : { cell : JQuery , index : number } [ ] = [ ] ;
227227 function updateCell ( cell , j ) {
228228 var val = pal2rgb . words [ j ] ;
229229 var rgb = pal2rgb . palette [ j ] ;
230230 var hexcol = '#' + hex ( rgb2bgr ( rgb ) , 6 ) ;
231231 var textcol = ( rgb & 0x008000 ) ? 'black' : 'white' ;
232232 cell . text ( hex ( val , 2 ) ) . css ( 'background-color' , hexcol ) . css ( 'color' , textcol ) ;
233233 }
234+ function updateAllCells ( ) {
235+ cells . forEach ( ( { cell, index } ) => updateCell ( cell , index ) ) ;
236+ }
234237 // iterate over each row of the layout
235238 layout . forEach ( ( [ name , start , len ] ) => {
236239 if ( start < pal2rgb . palette . length ) { // skip row if out of range
@@ -243,6 +246,7 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext {
243246 inds . reverse ( ) ;
244247 inds . forEach ( ( i ) => {
245248 var cell = $ ( '<td/>' ) . addClass ( 'asset_cell asset_editable' ) . appendTo ( arow ) ;
249+ cells . push ( { cell, index : i } ) ;
246250 updateCell ( cell , i ) ;
247251 cell . click ( ( e ) => {
248252 var chooser = new pixed . ImageChooser ( ) ;
@@ -258,6 +262,7 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext {
258262 } ) ;
259263 }
260264 } ) ;
265+ return updateAllCells ;
261266 }
262267
263268 addPixelEditor ( parentdiv : JQuery , firstnode : pixed . PixNode , fmt : pixed . PixelEditorImageFormat ) {
@@ -279,9 +284,7 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext {
279284 firstnode . addRight ( pal2rgb ) ;
280285 // TODO: refresh twice?
281286 firstnode . refreshRight ( ) ;
282- // TODO: add view objects
283- // TODO: show which one is selected?
284- this . addPaletteEditorViews ( parentdiv , pal2rgb ,
287+ var updateAllCells = this . addPaletteEditorViews ( parentdiv , pal2rgb ,
285288 ( index , newvalue ) => {
286289 console . log ( 'set entry' , index , '=' , newvalue ) ;
287290 // TODO: this forces update of palette rgb colors and file data
@@ -290,6 +293,8 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext {
290293 pal2rgb . updateRight ( ) ;
291294 pal2rgb . refreshLeft ( ) ;
292295 } ) ;
296+ // add view node to repaint cells when data changes (e.g. undo)
297+ pal2rgb . addRight ( new pixed . PaletteEditorView ( updateAllCells ) ) ;
293298 }
294299
295300 ensureFileDiv ( fileid : string ) : JQuery < HTMLElement > {
0 commit comments