Skip to content

Instantly share code, notes, and snippets.

@Ondina
Created December 29, 2011 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ondina/1533524 to your computer and use it in GitHub Desktop.
Save Ondina/1533524 to your computer and use it in GitHub Desktop.
package com.futurescale.sa.controller.command.story
{
import com.futurescale.sa.controller.constant.AppConstants;
import com.futurescale.sa.model.proxy.StoryProxy;
import com.futurescale.sa.model.vo.ChapterVO;
import com.futurescale.sa.model.vo.PartVO;
import com.futurescale.sa.model.vo.SceneVO;
import com.futurescale.sa.model.vo.StoryVO;
import com.futurescale.sa.view.context.SelectionContext;
import org.puremvc.as3.interfaces.INotification;
import org.puremvc.as3.interfaces.IProxy;
import org.puremvc.as3.patterns.command.SimpleCommand;
/**
* Prepare a story for editing.
*/
public class EditStoryCommand extends SimpleCommand
{
private var chapter:ChapterVO;
private var part:PartVO;
private var scene:SceneVO;
private var story:StoryVO;
override public function execute(note:INotification):void
{
// Get the story from the note body.
story=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();
}
else if (story.useChapters)
{
trace("EditStoryCommand.execute(note) story.useChapters ");
buildChapterInStory();
context.selectChapter(chapter);
}
else if (story.useParts)
{
trace("EditStoryCommand.execute(note) story.useParts ");
buildPartInStory();
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(); //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():void
{ //simple story
trace("EditStoryCommand.buildSceneInStory(story) " + story.scenes.length);
if (story.scenes.length == 0)
{
scene=story.getNewScene();
buildDraftInScene();
}
else
{
scene=story.scenes[story.scenes.length - 1];
}
}
private function buildChapterInStory():void
{ //normal story
trace("EditStoryCommand.buildChapterInStory(story) " + story.chapters.length);
if (story.chapters.length == 0)
chapter=story.getNewChapter();
else
chapter=story.chapters[story.chapters.length - 1];
buildSceneInChapter();
}
private function buildPartInStory():void
{ //complex story
trace("EditStoryCommand.buildPartInStory(story) " + story.parts.length);
if (story.parts.length == 0)
part=story.getNewPart();
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=part.getNewChapter();
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=chapter.getNewScene();
buildDraftInScene();
}
else
{
scene=chapter.scenes[chapter.scenes.length - 1];
}
}
private function buildDraftInScene():void
{ //all stories
trace("EditStoryCommand.buildDraftInScene() " + scene.drafts.length);
if (scene.drafts.length == 0)
scene.currentDraft=scene.getNewDraft();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment