示例#1
0
文件: Config.cs 项目: Nayuki749/Rein
        private void SetPattern(SoundConfig parent)
        {
            switch (this.Type)
            {
            case PatternType.String:
                StringPattern = StrPattern;
                break;

            case PatternType.Regex:
                RegexPattern = new Regex(StrPattern);
                break;

            case PatternType.Function:
                var file = Config.LoadFile(this.FunctionFile, parent.ConfigFileDir);
                if (file.Length > 0)
                {
                    this.StrPattern = file;
                }
                if (FunctionName.Length == 0 || StrPattern.Length == 0)
                {
                    // TRANSLATORS: Log message. SoundEffectCommand plugin.
                    Logger.Log(T._("Could not set function."));
                    break;
                }
                JSWrapper.Instance.SetFunction(FunctionName, StrPattern);
                FunctionPattern = (JSArgument arg) => {
                    try {
                        var r = JSWrapper.Instance.ExecuteFunction(FunctionName, arg);
                        return(r as ReplaceResult);
                    } catch (System.Exception e) {
                        // TRANSLATORS: Log message. SoundEffectCommand plugin.
                        Logger.Log(T._("Could not get JS result."));
                        Logger.DebugLog(e.ToString());
                        return(null);
                    }
                };
                break;

            default:
                break;
            }
        }
示例#2
0
文件: Config.cs 项目: Nayuki749/Rein
 public void Initialize(SoundConfig parent)
 {
     SetType();
     SetPattern(parent);
 }