protected override void LoadConfig() { base.LoadConfig(); config = Config.ReadObject <PluginConfig>(); DateTime BlockEnd; if (!DateTime.TryParseExact(config.BlockEndStr, "dd.MM.yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out BlockEnd)) { BlockEnd = SaveRestore.SaveCreatedTime.AddHours(config.HoursOfBlock); PrintWarning($"Unable to parse block end date format, block end set to {BlockEnd.ToString("dd.MM.yyyy HH:mm:ss")}"); config.BlockEndStr = BlockEnd.ToString("dd.MM.yyyy HH:mm:ss"); SaveConfig(); } config.BlockEnd = BlockEnd; permission.RegisterPermission(config.BypassPermission, this); if (!string.IsNullOrEmpty(config.Gui.Image.Image)) { if (!config.Gui.Image.Image.ToLower().Contains("http")) { config.Gui.Image.Image = "file://" + Interface.Oxide.DataDirectory + Path.DirectorySeparatorChar + config.Gui.Image.Image; } } LoadData(); permission.RegisterPermission("itemsblocker.refresh", this); }
private static void FormatCodeBlock(this string text, int indent, List <string> lines) { if (text == null) { throw new ArgumentNullException(nameof(text)); } if (lines == null) { throw new ArgumentNullException(nameof(lines)); } int beginPos = 0; int endPos = 0; void AddCodeLines(string txt, int idt, List <string> list) { string[] items = txt.SplitBlockLine(); list.AddRange(items.Where(l => l.Length > 0) .Select(l => l.SetIndent(idt)) .ToArray()); } if (GetBlockPositions(text, ref beginPos, ref endPos) == true) { AddCodeLines(text.Partialstring(0, beginPos - 1), indent, lines); if (BlockStartPrefix.Equals(Environment.NewLine)) { lines.Add(BlockStart.ToString().SetIndent(indent)); } else { lines[lines.Count - 1] = $"{lines[lines.Count - 1]}{BlockStartPrefix}{BlockStart}"; } text.Partialstring(beginPos + 1, endPos - 1).FormatCodeBlock(indent + 1, lines); if (BlockEndPrefix.Equals(Environment.NewLine)) { lines.Add(BlockEnd.ToString().SetIndent(indent)); } else { lines[lines.Count - 1] = $"{lines[lines.Count - 1]}{BlockEndPrefix}{BlockEnd}"; } text.Partialstring(endPos + 1, text.Length - 1).FormatCodeBlock(indent, lines); } else { AddCodeLines(text, indent, lines); } }
private void readBlockEnd(BlockEnd block) { CadEntityTemplate template = new CadEntityTemplate(block); this.readCommonObjectData(template); this.readMapped <Entity>(block, template); this.readMapped <BlockEnd>(block, template); this._builder.AddTemplate(template); }
public BlockRecord(string name) : base(name) { this.BlockEntity = new Block(this); this.BlockEnd = new BlockEnd(this); this.Entities = new CadObjectCollection <Entity>(this); }
/// <summary> /// ソースコードを解析してトークン列を生成 /// </summary> /// <param name="targets"></param> /// <returns></returns> private static IEnumerable <Token> Analysis(string targets) { if (targets.EndsWith(";") == false || targets.EndsWith("\r\n") == false) { targets += "\r\n"; } while (targets.Length > 0) { //スペースとタブは変換しない if (targets[0] == ' ' || targets[0] == '\t') { targets = targets.Remove(0, 1); continue; } if (targets[0] == '\"') { var literal = targets .Skip(1) .TakeWhile(c => c != '\"') .Aggregate(new StringBuilder(), (sb, c) => sb.Append(c)) .ToString(); targets = targets.Remove(0, literal.Length + 2); yield return(new StringLiteral(literal)); continue; } if (LeftParenthesis.IsMatch(targets[0])) { targets = targets.Remove(0, 1); yield return(new LeftParenthesis()); continue; } if (RightParenthesis.IsMatch(targets[0])) { targets = targets.Remove(0, 1); yield return(new RightParenthesis()); continue; } if (BlockBegin.IsMatch(targets[0])) { targets = targets.Remove(0, 1); yield return(new BlockBegin()); continue; } if (BlockEnd.IsMatch(targets[0])) { targets = targets.Remove(0, 1); yield return(new BlockEnd()); continue; } if (targets.StartsWith("Writeln")) { targets = targets.Remove(0, 7); yield return(new StandardOutput()); continue; } if (targets.StartsWith("Readln()")) { targets = targets.Remove(0, 8); yield return(new StandardInput()); continue; } if (Int32Literal.SpecifiedCollection.Contains(targets[0])) { var value = targets.TakeWhile(c => Int32Literal.SpecifiedCollection.Contains(c)).ToArray(); targets = targets.Remove(0, value.Length); yield return(new Int32Literal(new string(value))); continue; } if (EndOfLine.IsMatch(targets[0].ToString()) || EndOfLine.IsMatch(new string(targets.Take(2).ToArray()))) { var value = targets.TakeWhile(i => i == ';' || i == '\r' || i == '\n').Count(); targets = targets.Remove(0, value); yield return(new EndOfLine()); continue; } if (targets.Length > 1 && Assign.IsMatch(targets[0]) && !Assign.IsMatch(targets[1])) { targets = targets.Remove(0, 1); yield return(new Assign()); continue; } if (targets.Length > 1 && AddAssign.IsMatch(targets[0], targets[1])) { targets = targets.Remove(0, 2); yield return(new AddAssign()); continue; } if (targets.StartsWith("var ")) { var varVariableName = targets.Skip(4) .TakeWhile(c => c != ' ' && c != '\t' && c != '=') .Aggregate(new StringBuilder(), (sb, c) => sb.Append(c)) .ToString(); if (!(JudgeWord(varVariableName) is Identifier)) { throw new Exception("変数にキーワードが使われています。"); } targets = targets.Remove(0, 4 + varVariableName.Length); yield return(new VarDeclaration(varVariableName)); continue; } if (PlusOperator.IsMatch(targets[0])) { targets = targets.Remove(0, 1); yield return(new PlusOperator()); continue; } if (MinusOperator.IsMatch(targets[0])) { targets = targets.Remove(0, 1); yield return(new MinusOperator()); continue; } if (MultiplyOperator.IsMatch(targets[0])) { targets = targets.Remove(0, 1); yield return(new MultiplyOperator()); continue; } if (DivideOperator.IsMatch(targets[0])) { targets = targets.Remove(0, 1); yield return(new DivideOperator()); continue; } if (ModuloOperator.IsMatch(targets[0])) { targets = targets.Remove(0, 1); yield return(new ModuloOperator()); continue; } if (targets.Length > 1 && targets[0] == '=' && targets[1] == '=') { targets = targets.Remove(0, 2); yield return(new EqualOperator()); continue; } if (targets.Length > 1 && targets[0] == '!' && targets[1] == '=') { targets = targets.Remove(0, 2); yield return(new NotEqualOperator()); continue; } if (targets.Length > 1 && targets[0] == '>') { if (targets[1] == '=') { targets = targets.Remove(0, 2); yield return(new GreaterThanOrEqualOperator()); continue; } targets = targets.Remove(0, 1); yield return(new GreaterThanOperator()); continue; } if (targets.Length > 1 && targets[0] == '<') { if (targets[1] == '=') { targets = targets.Remove(0, 2); yield return(new LessThanOrEqualOperator()); continue; } targets = targets.Remove(0, 1); yield return(new LessThanOperator()); continue; } if (targets.Length > 1 && targets[0] == '&' && targets[1] == '&') { targets = targets.Remove(0, 2); yield return(new AndAlsoOperator()); continue; } if (targets.Length > 1 && targets[0] == '|' && targets[1] == '|') { targets = targets.Remove(0, 2); yield return(new OrElseOperator()); continue; } var word = targets.TakeWhile(IdentifierTake) .Aggregate(new StringBuilder(), (sb, c) => sb.Append(c)) .ToString(); if (word.Length == 0) { throw new Exception("変数名なのに文字数がゼロ"); } targets = targets.Remove(0, word.Length); yield return(JudgeWord(word)); } }
public CodeBlock(CodeElement parent) : base(parent) { StartBlock = new BlockDeclaration(this); EndBlock = new BlockEnd(this); }
private void HandlePowerTaskList(Line line) { var match = _gameEntityRegex.Match(line.Text); if (match.Success) { var id = int.Parse(match.Groups["id"].Value); _currentEntity = id; GameStateChange?.Invoke(new FullEntity(new GameEntityData(id), null)); return; } match = _playerEntityRegex.Match(line.Text); if (match.Success) { var entityId = int.Parse(match.Groups["id"].Value); var playerId = int.Parse(match.Groups["playerId"].Value); _currentEntity = entityId; GameStateChange?.Invoke(new FullEntity(new PlayerEntityData(entityId, playerId), null)); return; } match = _fullEntityRegex.Match(line.Text); if (match.Success) { var id = int.Parse(match.Groups["id"].Value); _currentEntity = id; var cardId = match.Groups["cardId"].Value; var zone = GameTagParser.ParseEnum <Zone>(match.Groups["zone"].Value); if (string.IsNullOrEmpty(cardId) && zone != Zone.SETASIDE) { cardId = _currentBlock?.Data.NextPredictedCard() ?? cardId; } GameStateChange?.Invoke(new FullEntity(new EntityData(id, null, cardId, zone), _currentBlock?.Data)); return; } match = _tagChangeRegex.Match(line.Text); if (match.Success) { var entity = ParseEntity(match.Groups["entity"].Value); Enum.TryParse(match.Groups["tag"].Value, out GameTag tag); var value = GameTagParser.ParseTag(tag, match.Groups["value"].Value); var entityId = entity.Id == -1 ? null : (int?)entity.Id; GameStateChange?.Invoke(new TagChange(new TagChangeData(tag, value, false, entityId, entity.Name))); return; } match = _updatingEntityRegex.Match(line.Text); if (match.Success) { var cardId = match.Groups["cardId"].Value; var entity = ParseEntity(match.Groups["entity"].Value); _currentEntity = entity.Id; var type = match.Groups["type"].Value; if (type == "CHANGE_ENTITY") { GameStateChange?.Invoke(new ChangeEntity(new EntityData(entity.Id, entity.Name, cardId, null))); } else { GameStateChange?.Invoke(new ShowEntity(new EntityData(entity.Id, entity.Name, cardId, null), _currentBlock?.Data)); } return; } match = _creationTagRegex.Match(line.Text); if (match.Success && !line.Text.Contains("HIDE_ENTITY")) { var tag = GameTagParser.ParseEnum <GameTag>(match.Groups["tag"].Value); var value = GameTagParser.ParseTag(tag, match.Groups["value"].Value); GameStateChange?.Invoke(new TagChange(new TagChangeData(tag, value, true, _currentEntity, null))); return; } match = _hideEntityRegex.Match(line.Text); if (match.Success) { var id = int.Parse(match.Groups["id"].Value); _currentEntity = id; GameStateChange?.Invoke(new HideEntity(new EntityData(id, "", null, null))); } match = _blockStartRegex.Match(line.Text); if (match.Success) { var type = match.Groups["type"].Value; var entity = ParseEntity(match.Groups["entity"].Value.Trim()); var target = ParseEntity(match.Groups["target"].Value.Trim()); var effectCardId = match.Groups["effectCardId"].Value; var effectIndex = int.Parse(match.Groups["effectIndex"].Value); var rawTriggerKeyword = match.Groups["triggerKeyword"].Value; var triggerKeyword = string.IsNullOrEmpty(rawTriggerKeyword) || rawTriggerKeyword == "0" ? null : (GameTag?)GameTagParser.ParseEnum <GameTag>(rawTriggerKeyword); var blockData = new BlockData(type, entity.Id, entity.CardId, effectCardId, effectIndex, triggerKeyword, target); _currentBlock = _currentBlock?.CreateChild(blockData) ?? new Block(null, blockData); foreach (var card in _blockHelper.GetCreatedCards(blockData)) { blockData.PredictedCards.Add(card); } BlockStart?.Invoke(blockData); return; } match = _debugDumpRegex.Match(line.Text); if (match.Success) { if (int.Parse(match.Groups["id"].Value) == 2) { SetupComplete?.Invoke(); } } if (line.Text.Contains("BLOCK_END")) { BlockEnd?.Invoke(_currentBlock?.Data); _currentBlock = _currentBlock?.Parent; } }