// @Brief : Start void Start() { m_pLogContainer = new KrCharagekiLogContainer(); m_pScenarioContainer = new KrCharagekiScenarioContainer(); KrCharagekiScript pScript = LoadScript(); //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // RESOURCE DOWNLOAD List <string> pResourcePaths = pScript.GetResourcesPaths(); for (int sIndex = 0; sIndex < pResourcePaths.Count; sIndex++) { // TODO : Add asset download KrDebug.Log("Download => " + pResourcePaths[sIndex], typeof(KrCharagekiManager)); } //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // INITILIZE COMMAND List <KrCharagekiCommand> pInitializeCommands = pScript.GetInitializeCommands(); KrDebug.Log("Initialize charageki", typeof(KrCharagekiManager)); for (int sIndex = 0; sIndex < pInitializeCommands.Count; sIndex++) { pInitializeCommands[sIndex].Exec(this); } //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // SET MAIN SECTION m_pMainCharagekiSections = pScript.GetMainSections(); KrDebug.Log("Get main sections : count = " + m_pMainCharagekiSections.Count, typeof(KrCharagekiManager)); m_sSectionIndex = 0; ScriptUpdate(); }
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // PROTECTED FUNCTION //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // @Brief : Add initialize command // @Param : pReader => Stream reader // : pScript => Script container // : pStr => String of one line protected override void Add(StreamReader pReader, KrCharagekiScript pScript, string pStr) { if (pStr.Equals(c_pSECTION + ":")) { KrDebug.Log("New section", typeof(KrCharagekiMain)); KrCharagekiSection pSection = new KrCharagekiSection(); pSection.Add(pReader, pScript); c_pSectionScripts.Add(pSection); } }
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // PROTECTED FUNCTION //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // @Brief : Add const // @Param : pReader => Stream reader // : pScript => Script container // : pStr => String of one line protected override void Add(StreamReader pReader, KrCharagekiScript pScript, string pStr) { string[] pSplit = pStr.Split(new char[] { '=', ' ' }, System.StringSplitOptions.RemoveEmptyEntries); KrDebug.Log("Add const variable => " + pSplit[0] + " : " + pSplit[1], typeof(KrCharagekiConst)); if (!m_pConstDic.ContainsKey(pSplit[0])) { m_pConstDic.Add(pSplit[0], pSplit[1]); } else { KrDebug.Warning(false, "Duplicate key defined by Const. " + pSplit[0] + " = " + pSplit[1], typeof(KrCharagekiConst)); } }
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // PUBLIC FUNCTION //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // @Brief : Load command // @Param : pScript => Script container // : pCommand => String of command public void Load(KrCharagekiScript pScript, string pCommand) { string[] pSplit = pCommand.Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries); KrDebug.Log("Add command => " + pSplit[0], typeof(KrCharagekiCommand)); // Since array 0 is the command name, it starts from the first for (int sIndex = 1; sIndex < pSplit.Length; sIndex++) { KrDebug.Log(" option => " + pSplit[sIndex], typeof(KrCharagekiCommand)); string[] pKeyValue = pSplit[sIndex].Split(new char[] { '=' }); KrCharagekiCommandOption pOption = new KrCharagekiCommandOption(pKeyValue[0], pScript.ConvertConstVariable(pKeyValue[1])); m_pOptions.Add(pOption); } }
// @Brief : Compile script private void Compile() { StreamReader pReader = KrResources.LoadText(m_pFilePath); KrCharagekiScript pScript = new KrCharagekiScript(); try { pScript.LoadScript(pReader); } finally { if (pReader != null) { pReader.Close(); } } }
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // PROTECTED FUNCTION //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // @Brief : Add initialize command // @Param : pReader => Stream reader // : pScript => Script container // : pStr => String of one line protected override void Add(StreamReader pReader, KrCharagekiScript pScript, string pStr) { KrCharagekiCommand pCommand = null; // Create initialize comannd //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // LOAD SCENARIO if (pStr.IndexOf("load_scenario") == 0) { pCommand = new KrCharagekiCommandLoadScenario(); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // LOAD BGM else if (pStr.IndexOf("load_bgm") == 0) { pCommand = null; } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // LOAD SPRITE else if (pStr.IndexOf("load_bg") == 0) { pCommand = new KrCharagekiCommandLoadBg(); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // LOAD CHARACTER else if (pStr.IndexOf("load_chara") == 0) { pCommand = new KrCharagekiCommandLoadCharacter(); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // NOT SUPPORTED else { KrDebug.Assert(false, "Not Supported initialize command => " + pStr, typeof(KrCharagekiInitialize)); } if (pCommand != null) { KrDebug.Log("Add initialize command => " + pStr, typeof(KrCharagekiInitialize)); pCommand.Load(pScript, pStr); m_pCommands.Add(pCommand); } }
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // PRIVATE FUNCTION //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // @Brief : Load script // @Return : KrCharagekiScript instance private KrCharagekiScript LoadScript() { KrCharagekiScript pScript = new KrCharagekiScript(); for (int sIndex = 0; sIndex < m_pScriptPaths.Length; sIndex++) { StreamReader pReader = KrResources.LoadText(KrCharagekiDef.s_pASSET_BASE_PATH + m_pScriptPaths[sIndex], KrCharagekiDef.IsLoadingFromResources()); try { pScript.LoadScript(pReader); } finally { if (pReader != null) { pReader.Close(); } } } return(pScript); }
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // PUBLIC FUNCTION //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // @Brief : Add // @Param : pReader => Stream reader // : pScript => Script container public void Add(StreamReader pReader, KrCharagekiScript pScript) { while (pReader.Peek() > -1) { string pLineStr = pReader.ReadLine(); // Trim unwanted tabs pLineStr = pLineStr.Trim(); pLineStr = pLineStr.Replace("\"", ""); // In the case of "end", the function terminates if (pLineStr.Equals(c_pEND_FUNC)) { break; } if (!(pLineStr.IndexOf(c_pCOMMENT) == 0) && !string.IsNullOrEmpty(pLineStr)) { Add(pReader, pScript, pLineStr); } } }
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // PROTECTED FUNCTION //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // @Brief : Add // @Param : pReader => Stream reader // : pScript => Script container // : pStr => String of one line protected abstract void Add(StreamReader pReader, KrCharagekiScript pScriptContainer, string pStr);
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // PROTECTED FUNCTION //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // @Brief : Add resource // @Param : pReader => Stream reader // : pScript => Script container // : pStr => String of one line protected override void Add(StreamReader pReader, KrCharagekiScript pScript, string pStr) { pStr = pScript.ConvertConstVariable(pStr); KrDebug.Log("Add resource path => " + pStr, typeof(KrCharagekiResource)); m_pResourceFilePaths.Add(pStr); }
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // PROTECTED FUNCTION //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // @Brief : Add initialize command // @Param : pReader => Stream reader // : pScript => Script container // : pStr => String of one line protected override void Add(StreamReader pReader, KrCharagekiScript pScript, string pStr) { KrCharagekiCommand pCommand = null; // Create initialize comannd //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // SET COMMENT if (pStr.IndexOf("set_text") == 0) { pCommand = new KrCharagekiCommandSetText(); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // SHOW TEXT else if (pStr.IndexOf("show_text") == 0) { pCommand = new KrCharagekiCommandShowText(); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // SET SCENARIO else if (pStr.IndexOf("set_scenario") == 0) { pCommand = new KrCharagekiCommandSetScenario(); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // SET BACK GROUND else if (pStr.IndexOf("set_bg") == 0) { pCommand = new KrCharagekiCommandSetSpriteBg(); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // SHOW BACK GROUND else if (pStr.IndexOf("show_bg") == 0) { pCommand = new KrCharagekiCommandShowBg(); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // HIDE BACK GROUND else if (pStr.IndexOf("hide_bg") == 0) { pCommand = new KrCharagekiCommandHideBg(); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // SET TITLE NAME else if (pStr.IndexOf("set_title") == 0) { pCommand = new KrCharagekiCommandSetTitle(); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // SHOW TITLE else if (pStr.IndexOf("show_title") == 0) { pCommand = new KrCharagekiCommandShowTitle(); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // HIDE TITLE else if (pStr.IndexOf("hide_title") == 0) { pCommand = new KrCharagekiCommandHideTitle(); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // FADE OUT else if (pStr.IndexOf("fade_out") == 0) { pCommand = new KrCharagekiCommandFadeOut(); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // FADE IN else if (pStr.IndexOf("fade_in") == 0) { pCommand = new KrCharagekiCommandFadeIn(); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // SET WAIT INPUT else if (pStr.IndexOf("wait_input") == 0) { pCommand = new KrCharagekiCommandWaitInput(); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // SET WAIT TIME else if (pStr.IndexOf("wait_time") == 0) { pCommand = new KrCharagekiCommandWaitTime(); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // SHOW CHARACTER else if (pStr.IndexOf("show_chara") == 0) { pCommand = new KrCharagekiCommandShowCharacter(); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // HIDE CHARACTER else if (pStr.IndexOf("hide_chara") == 0) { pCommand = new KrCharagekiCommandHideCharacter(); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // CHARACTER ACTION else if (pStr.IndexOf("chara_action") == 0) { pCommand = new KrCharagekiCommandCharacterAction(); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // SET CHARACTER POSITION else if (pStr.IndexOf("chara_position") == 0) { pCommand = new KrCharagekiCommandSetCharacterPosition(); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // PLAY SE else if (pStr.IndexOf("play_se") == 0) { pCommand = new KrCharagekiCommandPlaySe(); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // PLAY BGM else if (pStr.IndexOf("play_bgm") == 0) { pCommand = new KrCharagekiCommandPlayBgm(); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // NOT SUPPORTED else { KrDebug.Assert(false, "Not Supported section command => " + pStr, typeof(KrCharagekiInitialize)); } if (pCommand != null) { KrDebug.Log(" Add Section command => " + pStr, typeof(KrCharagekiSection)); pCommand.Load(pScript, pStr); m_pCommands.Add(pCommand); } }