Skip to content

Commit

Permalink
Merge pull request #720 from wonderunit/706-fountain-errors
Browse files Browse the repository at this point in the history
Fountain scripts: better error handling while loading
  • Loading branch information
audionerd committed Sep 27, 2017
2 parents 57da3e6 + fe631dd commit 0f217cf
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 64 deletions.
55 changes: 46 additions & 9 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,29 @@ let openFile = (file) => {
storyboardsPath,
currentFile,
currentPath
)
).catch(error => {
console.error(error)
})

} else {
let boardSettings = JSON.parse(fs.readFileSync(path.join(storyboardsPath, 'storyboard.settings')))
if (!boardSettings.lastScene) { boardSettings.lastScene = 0 }
//[scriptData, locations, characters, metadata]
let processedData = processFountainData(data, true, false)
addToRecentDocs(currentFile, processedData[3])
loadStoryboarderWindow(currentFile, processedData[0], processedData[1], processedData[2], boardSettings, currentPath)

let processedData
try {
processedData = processFountainData(data, true, false)
} catch (error) {
dialog.showMessageBox({
type: 'error',
message: 'Could not read Fountain script.\n' + error.message,
})
}

if (processedData) {
addToRecentDocs(currentFile, processedData[3])
loadStoryboarderWindow(currentFile, processedData[0], processedData[1], processedData[2], boardSettings, currentPath)
}
}
})
}
Expand Down Expand Up @@ -369,10 +383,13 @@ let processFountainData = (data, create, update) => {
return fs.statSync(path.join(currentPath, file)).isDirectory();
});

// fallback title in case one is not provided
metadata.title = path.basename(currentFile, path.extname(currentFile))

for (var node of scriptData) {
switch (node.type) {
case 'title':
metadata.title = node.text.replace(/<(?:.|\n)*?>/gm, '')
if (node.text) { metadata.title = node.text.replace(/<(?:.|\n)*?>/gm, '') }
break
case 'scene':
metadata.sceneCount++
Expand All @@ -398,6 +415,14 @@ let processFountainData = (data, create, update) => {
}
}

let scenesWithSceneNumbers = scriptData.reduce(
(coll, node) =>
(node.type === 'scene' && node.scene_number)
? coll + 1
: coll
, 0)
if (scenesWithSceneNumbers === 0) throw new Error('Could not find any numbered scenes in this Fountain script.')

switch (scriptData[scriptData.length-1].type) {
case 'section':
metadata.totalMovieTime = scriptData[scriptData.length-1].time + scriptData[scriptData.length-1].duration
Expand Down Expand Up @@ -506,12 +531,24 @@ let createNewFromExistingFile = (aspectRatio, data, storyboardsPath, currentFile
}
fs.writeFileSync(path.join(storyboardsPath, 'storyboard.settings'), JSON.stringify(boardSettings))
//[scriptData, locations, characters, metadata]
let processedData = processFountainData(data, true, false)

addToRecentDocs(currentFile, processedData[3])
loadStoryboarderWindow(currentFile, processedData[0], processedData[1], processedData[2], boardSettings, currentPath)
let processedData
try {
processedData = processFountainData(data, true, false)
} catch (error) {
dialog.showMessageBox({
type: 'error',
message: 'Could not read existing Fountain script.\n' + error.message,
})
}

resolve()
if (processedData) {
addToRecentDocs(currentFile, processedData[3])
loadStoryboarderWindow(currentFile, processedData[0], processedData[1], processedData[2], boardSettings, currentPath)
resolve()
} else {
reject()
}
})

let loadStoryboarderWindow = (filename, scriptData, locations, characters, boardSettings, currentPath) => {
Expand Down
121 changes: 66 additions & 55 deletions src/js/window/main-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,57 +144,64 @@ remote.getCurrentWindow().on('focus', () => {
///////////////////////////////////////////////////////////////

const load = async (event, args) => {
if (args[1]) {
log({ type: 'progress', message: 'Loading Fountain File' })
console.log("LOADING FOUNTAIN FILE", args[0])
ipcRenderer.send('analyticsEvent', 'Application', 'open script', args[0])

// there is scriptData - the window opening is a script type
scriptData = args[1]
locations = args[2]
characters = args[3]
boardSettings = args[4]
currentPath = args[5]

//renderScenes()
currentScene = boardSettings.lastScene
await loadScene(currentScene)

assignColors()
document.querySelector('#scenes').style.display = 'block'
document.querySelector('#script').style.display = 'block'
renderScenes()
renderScript()

} else {
log({ type: 'progress', message: 'Loading Project File' })
// if not, its just a simple single boarder file
boardFilename = args[0]
boardPath = boardFilename.split(path.sep)
boardPath.pop()
boardPath = boardPath.join(path.sep)
console.log(' BOARD PATH: ', boardFilename)
boardData = JSON.parse(fs.readFileSync(boardFilename))
ipcRenderer.send('analyticsEvent', 'Application', 'open', boardFilename, boardData.boards.length)
}
try {
if (args[1]) {
log({ type: 'progress', message: 'Loading Fountain File' })
console.log("LOADING FOUNTAIN FILE", args[0])
ipcRenderer.send('analyticsEvent', 'Application', 'open script', args[0])

// there is scriptData - the window opening is a script type
scriptData = args[1]
locations = args[2]
characters = args[3]
boardSettings = args[4]
currentPath = args[5]

//renderScenes()
currentScene = boardSettings.lastScene
await loadScene(currentScene)

assignColors()
document.querySelector('#scenes').style.display = 'block'
document.querySelector('#script').style.display = 'block'
renderScenes()
renderScript()
} else {
log({ type: 'progress', message: 'Loading Project File' })
// if not, its just a simple single boarder file
boardFilename = args[0]
boardPath = boardFilename.split(path.sep)
boardPath.pop()
boardPath = boardPath.join(path.sep)
console.log(' BOARD PATH: ', boardFilename)
boardData = JSON.parse(fs.readFileSync(boardFilename))
ipcRenderer.send('analyticsEvent', 'Application', 'open', boardFilename, boardData.boards.length)
}

loadBoardUI()
await updateBoardUI()
loadBoardUI()
await updateBoardUI()

log({ type: 'progress', message: 'Preparing to display' })
log({ type: 'progress', message: 'Preparing to display' })

resize()
setTimeout(() => {
storyboarderSketchPane.resize()
resize()
setTimeout(() => {
storyboarderSketchPane.resize()

setImmediate(() =>
requestAnimationFrame(() =>
setImmediate(() =>
requestAnimationFrame(() =>
ipcRenderer.send('workspaceReady')
requestAnimationFrame(() =>
ipcRenderer.send('workspaceReady')
)
)
)
)
}, 500) // TODO hack, remove this #440
}, 500) // TODO hack, remove this #440
} catch (error) {
remote.dialog.showMessageBox({
type: 'error',
message: error.message
})
log({ type: 'error', message: error.message })
}
}
ipcRenderer.on('load', load)

Expand Down Expand Up @@ -2877,21 +2884,25 @@ let loadScene = async (sceneNumber) => {
}
}

boardPath = boardFilename.split(path.sep)
boardPath.pop()
boardPath = boardPath.join(path.sep)
console.log('BOARD PATH:', boardPath)
if (boardFilename) {
boardPath = boardFilename.split(path.sep)
boardPath.pop()
boardPath = boardPath.join(path.sep)
console.log('BOARD PATH:', boardPath)

if (onionSkin) {
onionSkin.setBoardPath(boardPath)
}
if (onionSkin) {
onionSkin.setBoardPath(boardPath)
}

dragTarget = document.querySelector('#thumbnail-container')
dragTarget.style.scrollBehavior = 'unset'
dragTarget = document.querySelector('#thumbnail-container')
dragTarget.style.scrollBehavior = 'unset'

ipcRenderer.send('analyticsEvent', 'Application', 'open', boardFilename, boardData.boards.length)
ipcRenderer.send('analyticsEvent', 'Application', 'open', boardFilename, boardData.boards.length)

return ensureBoardExists()
return ensureBoardExists()
} else {
throw new Error(`Missing .storyboarder file for scene ${sceneNumber}.`)
}
}

const ensureBoardExists = () => {
Expand Down
3 changes: 3 additions & 0 deletions src/loading-status.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
if (opt.type === 'progress') {
messagesEl.textContent = opt.message + ' …'
}
if (opt.type === 'error') {
messagesEl.textContent = '⚠ ' + opt.message
}
})
</script>
</html>

0 comments on commit 0f217cf

Please sign in to comment.