Exemplo n.º 1
0
        /// <summary>キャラ名によってキャラをロードします。</summary>
        /// <param name="characterName">読み込み対象のキャラ名</param>
        private void LoadCharacter(string characterName)
        {
            string errorMessage = string.Empty;

            try
            {
                Character = IronPythonCharacterLoader.LoadCharacter(characterName);
            }
            catch (Exception ex1)
            {
                errorMessage += "IronPython: " + ex1.Message + "\n\n";
                try
                {
                    Character = MEFCharacterLoader.Load(characterName);
                }
                catch (Exception ex2)
                {
                    errorMessage += "MEF: " + ex2.Message + "\n\n";
                    MessageBox.Show(
                        "キャラクターのロードに失敗したためアプリケーションが起動できません。アプリケーションを終了します。\n" + errorMessage,
                        "Harriet キャラクターの初期化に失敗しました",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error
                        );
                    Environment.Exit(1);
                }
            }

            SyncSizeSetting(_setting);
        }
Exemplo n.º 2
0
        /// <summary>APIの処理を実際に担当できるサブモジュールを用いてインスタンスを初期化します。</summary>
        /// <param name="window">キャラ表示ウィンドウ</param>
        /// <param name="character">実際のキャラクター</param>
        /// <param name="voiceOperator">発声処理器</param>
        /// <param name="chatWindow">チャット枠</param>
        /// <param name="requestor">スクリプト実行要求器</param>
        /// <param name="setting">設定事項</param>
        /// <param name="characterName">キャラクター名</param>
        public ScriptApi(
            IMainWindow window,
            IHarrietCharacter character,
            IVoiceOperator voiceOperator,
            IChatWindowModel chatWindow,
            IScriptRequestor requestor,
            CharacterSetting setting,
            IScriptApiSetting scriptApiSetting,
            string characterName
            )
        {
            this.Window = window;
            this.Character = character;
            this._voiceOperater = voiceOperator;
            this.ChatWindow = chatWindow;
            this.CharacterName = characterName;
            this.Setting = new SettingWindowViewModel(setting);
            this.ScriptRequest = requestor;

            _keyboardHook = new KeyboardHook(OnKeyboardUpDown);

            ////プラグインがあったら拾い、無かったら無視
            //try
            //{
            //    TextConverter = TextToPronounceConverterLoader.Load().FirstOrDefault() ??
            //                    new ImeTextConverter(); 
            //}
            //catch(Exception)
            //{
            //    TextConverter = new ImeTextConverter();
            //}

            _scriptApiSetting = scriptApiSetting;
        }
Exemplo n.º 3
0
        /// <summary>キャラ名によってキャラをロードします。</summary>
        /// <param name="characterName">読み込み対象のキャラ名</param>
        private void LoadCharacter(string characterName)
        {
            string errorMessage = string.Empty;
            try
            {
                Character = IronPythonCharacterLoader.LoadCharacter(characterName);
            }
            catch (Exception ex1)
            {
                errorMessage += "IronPython: " + ex1.Message + "\n\n";
                try
                {
                    Character = MEFCharacterLoader.Load(characterName);
                }
                catch(Exception ex2)
                {
                    errorMessage += "MEF: " + ex2.Message + "\n\n";
                    MessageBox.Show(
                        "キャラクターのロードに失敗したためアプリケーションが起動できません。アプリケーションを終了します。\n" + errorMessage,
                        "Harriet キャラクターの初期化に失敗しました",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error
                        );
                    Environment.Exit(1);
                }
            }

            SyncSizeSetting(_setting);
        }
Exemplo n.º 4
0
        /// <summary>APIの処理を実際に担当できるサブモジュールを用いてインスタンスを初期化します。</summary>
        /// <param name="window">キャラ表示ウィンドウ</param>
        /// <param name="character">実際のキャラクター</param>
        /// <param name="voiceOperator">発声処理器</param>
        /// <param name="chatWindow">チャット枠</param>
        /// <param name="requestor">スクリプト実行要求器</param>
        /// <param name="setting">設定事項</param>
        /// <param name="characterName">キャラクター名</param>
        public ScriptApi(
            IMainWindow window,
            IHarrietCharacter character,
            IVoiceOperator voiceOperator,
            IChatWindowModel chatWindow,
            IScriptRequestor requestor,
            CharacterSetting setting,
            IScriptApiSetting scriptApiSetting,
            string characterName
            )
        {
            this.Window         = window;
            this.Character      = character;
            this._voiceOperater = voiceOperator;
            this.ChatWindow     = chatWindow;
            this.CharacterName  = characterName;
            this.Setting        = new SettingWindowViewModel(setting);
            this.ScriptRequest  = requestor;

            _keyboardHook = new KeyboardHook(OnKeyboardUpDown);

            ////プラグインがあったら拾い、無かったら無視
            //try
            //{
            //    TextConverter = TextToPronounceConverterLoader.Load().FirstOrDefault() ??
            //                    new ImeTextConverter();
            //}
            //catch(Exception)
            //{
            //    TextConverter = new ImeTextConverter();
            //}

            _scriptApiSetting = scriptApiSetting;
        }
Exemplo n.º 5
0
        public ScriptingOperator(
            string characterName,
            IMainWindow mainWindow,
            IHarrietCharacter character, 
            CharacterSetting setting)
        {
            _characterName = characterName;
            _mainWindow = mainWindow;
            _character = character;
            _setting = setting;

            Initialize();
        }
Exemplo n.º 6
0
        public ScriptingOperator(
            string characterName,
            IMainWindow mainWindow,
            IHarrietCharacter character,
            CharacterSetting setting)
        {
            _characterName = characterName;
            _mainWindow    = mainWindow;
            _character     = character;
            _setting       = setting;

            Initialize();
        }
        /// <summary>キャラを定められた仕様にもとづいてロードする。失敗すると例外が飛んでくる</summary>
        public static IHarrietCharacter LoadCharacter(string characterName)
        {
            var engine = Python.CreateEngine();
            //名前参照にexeのディレクトリとキャラのディレクトリを追加
            var paths = engine.GetSearchPaths();

            paths.Add(Environment.CurrentDirectory);
            paths.Add(DirectoryNames.GetCharacterScriptDirectory(characterName));
            paths.Add(DirectoryNames.GetCharacterLoadedDirectory(characterName));
            engine.SetSearchPaths(paths);

            string path = GetInitializeScriptPath(characterName);

            if (!File.Exists(path))
            {
                throw new FileNotFoundException($"file '{path}' was not found: this is needed to load character data");
            }
            engine.ExecuteFile(path, engine.Runtime.Globals);

            dynamic loadFunction;
            bool    result = engine.Runtime.Globals.TryGetVariable(CharacterLoadFunction, out loadFunction);

            if (!result)
            {
                throw new InvalidOperationException($"'{CharacterLoadFunction}' function does not exist in '{path}'");
            }
            PythonFunction function = loadFunction as PythonFunction;

            if (function == null)
            {
                throw new InvalidOperationException($"'{CharacterLoadFunction}' defined in '{path}' is not function");
            }

            IHarrietCharacter character = loadFunction() as IHarrietCharacter;

            if (character == null)
            {
                throw new InvalidOperationException($"{CharacterLoadFunction} result does not implements IHarrietCharacter");
            }

            return(character);
        }