Created
December 27, 2011 18:01
-
-
Save Ondina/1524621 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EditStoryCommand extends SimpleCommand | |
{ | |
private var chapter:ChapterVO; | |
private var part:PartVO; | |
private var scene:SceneVO; | |
override public function execute(note:INotification):void | |
{ | |
// Get the story from the note body. | |
var story:StoryVO=StoryVO(note.getBody()); | |
// Get the SelectionContext | |
var scProxy:IProxy=facade.retrieveProxy(SelectionContext.NAME); | |
var context:SelectionContext=SelectionContext(scProxy.getData()); | |
// Be sure we have the full Story | |
if (story.isStub) | |
{ | |
var storyProxy:StoryProxy=StoryProxy(facade.retrieveProxy(StoryProxy.NAME)); | |
story=storyProxy.loadStory(story); | |
} | |
// Select the farthest point in the story for editing | |
context.selectStory(story); | |
if (story.useScenes) | |
{ | |
trace("EditStoryCommand.execute(note) story.useScenes "); | |
buildSceneInStory(story); | |
} | |
else if (story.useChapters) | |
{ | |
trace("EditStoryCommand.execute(note) story.useChapters "); | |
buildChapterInStory(story); | |
context.selectChapter(chapter); | |
} | |
else if (story.useParts) | |
{ | |
trace("EditStoryCommand.execute(note) story.useParts "); | |
buildPartInStory(story); | |
context.selectPart(part); | |
context.selectChapter(chapter); | |
} | |
else | |
{ //story type is null in case the file doesn't exist or file is empty | |
trace("----------------->story type null"); | |
buildSceneInStory(story); //build a simple story | |
} | |
context.selectScene(scene); | |
context.selectDraft(scene.currentDraft); | |
// Tell the View to edit the story. | |
sendNotification(AppConstants.SHOW_EDITOR); | |
} | |
private function buildSceneInStory(story:StoryVO):void | |
{ //simple story | |
trace("EditStoryCommand.buildSceneInStory(story) " + story.scenes.length); | |
if (story.scenes.length == 0) | |
{ | |
scene=new SceneVO(); | |
story.addScene(scene); | |
} | |
else | |
{ | |
scene=story.scenes[story.scenes.length - 1]; | |
} | |
} | |
private function buildChapterInStory(story:StoryVO):void | |
{ //normal story | |
trace("EditStoryCommand.buildChapterInStory(story) " + story.chapters.length); | |
if (story.chapters.length == 0) | |
{ | |
chapter=new ChapterVO(); | |
story.addChapter(chapter); | |
} | |
else | |
{ | |
chapter=story.chapters[story.chapters.length - 1]; | |
} | |
buildSceneInChapter(); | |
} | |
private function buildPartInStory(story:StoryVO):void | |
{ //complex story | |
trace("EditStoryCommand.buildPartInStory(story) " + story.parts.length); | |
if (story.parts.length == 0) | |
{ | |
part=new PartVO(); | |
story.addPart(part); | |
} | |
else | |
{ | |
part=story.parts[story.parts.length - 1]; | |
} | |
buildChapterInPart(); | |
buildSceneInChapter(); | |
} | |
private function buildChapterInPart():void | |
{ //complex story | |
trace("EditStoryCommand.buildChapterInPart() " + part.chapters.length); | |
if (part.chapters.length == 0) | |
{ | |
chapter=new ChapterVO(); | |
part.addChapter(chapter); | |
} | |
else | |
{ | |
chapter=part.chapters[part.chapters.length - 1]; | |
} | |
} | |
private function buildSceneInChapter():void | |
{ //normal or complex story | |
trace("EditStoryCommand.buildSceneInChapter() " + chapter.scenes.length); | |
if (chapter.scenes.length == 0) | |
{ | |
scene=new SceneVO(); | |
chapter.addScene(scene); | |
} | |
else | |
{ | |
scene=chapter.scenes[chapter.scenes.length - 1]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment