Skip to content

Commit 109ed6a

Browse files
committed
⏰🔀 Updated in browser at strd6.github.io/editor
1 parent bf38c3b commit 109ed6a

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

actions.coffee.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,18 @@ Actions
179179
editor.resize({width, height})
180180
editor.vintageReplay(data)
181181
else
182-
# New replays should handle resizing and intial state themselves
183-
editor.replay(data)
182+
editor.restoreState data, true
183+
184+
"f7":
185+
name: "Load local"
186+
description: "Load local file as replay"
187+
method: ({editor}) ->
188+
Modal.show FileReading.readerInput
189+
accept: "application/json"
190+
json: (data) ->
191+
editor.restoreState data, true
192+
chose: ->
193+
Modal.hide()
184194
185195
"ctrl+shift+s":
186196
name: "Save State"

command.coffee.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Command
77
Commands that can be done/undone in the editor.
88

99
module.exports = (I={}, self) ->
10+
self.imageDataToJSON = imageDataToJSON
11+
self.imageDataFromJSON = imageDataFromJSON
12+
1013
self.Command = {}
1114
1215
This is a weird DSL for each command to inherit a toJSON method and to register

editor.coffee.md

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Editor
4747
lastCommand = null
4848
4949
replaying = false
50-
initialSize = pixelExtent()
50+
initialState = null
5151
5252
self ?= Model(I)
5353
@@ -178,24 +178,35 @@ Editor
178178
179179
setTimeout runStep, delay
180180
181-
restoreState: (state) ->
181+
restoreState: (state, performReplay=false) ->
182182
self.palette state.palette.map Observable
183183
184+
initialState = self.imageDataFromJSON(state.initialState)
185+
self.restoreInitialState()
186+
184187
commands = state.history.map self.Command.parse
185-
commands.forEach (command) -> command.execute()
186-
self.history commands
187188
188-
self.repaint()
189+
if performReplay
190+
self.replay commands
191+
else
192+
commands.forEach (command) -> command.execute()
193+
self.history commands
194+
195+
self.repaint()
189196
190197
saveState: ->
191-
# TODO: Need to add our initial state to the json
192-
self.Command.Resize
193-
size: initialSize
194-
sizePrevious: initialSize
195-
imageData: self.getSnapshot()
196-
198+
version: "1"
197199
palette: self.palette().map (o) -> o()
198200
history: self.history().invoke "toJSON"
201+
initialState: self.imageDataToJSON initialState
202+
203+
setInitialState: (imageData) ->
204+
initialState = imageData
205+
206+
restoreInitialState: ->
207+
# Become the image with no history
208+
self.resize initialState, initialState
209+
self.history([])
199210
200211
withCanvasMods: (cb) ->
201212
canvas.context().globalAlpha = thumbnailCanvas.context().globalAlpha = self.alpha() / 100
@@ -459,4 +470,6 @@ Editor
459470
460471
# self.include require("./plugins/save_to_s3")
461472
473+
initialState = self.getSnapshot()
474+
462475
return self

0 commit comments

Comments
 (0)