protected virtual void InitData(ObjectType objectType, string[] search_folder = null, InputBuf buf = null) { item_width = base_width; if (buf == null) { buf = new InputBuf(); } this.objectType = objectType; this.search_folder = search_folder; input = buf.input; select_index = buf.select_index; SetStartIndex(buf.start_index); }
public virtual void Clear() { InputBuf.Clear(); ParserInputStrList.Clear(); TokenCommand = null; CurrInputStr = ""; OrigInputStr = ""; DobjNameStr = ""; IobjNameStr = ""; CommandFormatStr = ""; NewCommandStr = ""; Tokens = null; DobjNameTokens = null; NumDobjNameTokens = 0; IobjNameTokens = null; NumIobjNameTokens = 0; CurrToken = 0; StartToken = 0; CurrIndex = 0; RemoveIndex = -1; NameIndex = -1; PrepTokenIndex = -1; LoopCounter = 0; }
public virtual void Clear() { InputBuf.Clear(); Tokens = null; CurrToken = 0; PrepTokenIndex = -1; Prep = null; ActorMonster = null; ActorRoom = null; DobjData = Globals.CreateInstance <IParserData>(); IobjData = Globals.CreateInstance <IParserData>(); ObjData = DobjData; NextState = null; }
protected static T Create <T>(Action <ObejctPicker> callBack = null, ObjectType objectType = ObjectType.None, string[] search_folder = null, InputBuf buf = null) where T : ObejctPicker { string type = objectType == ObjectType.None ? "" : objectType.ToString(); var window = GetWindowWithRect <T>(new Rect(0, 0, base_width, base_height + PATH_VIEW_HEIGHT), true, "Select " + type); window.InitData(objectType, search_folder, buf); window.callBack = callBack; window.DoSearch(); return(window); }
public static ObejctPicker Create(Action <ObejctPicker> callBack = null, ObjectType objectType = ObjectType.None, string[] search_folder = null, InputBuf buf = null) { return(Create <ObejctPicker>(callBack, objectType, search_folder, buf)); }
public virtual void Execute() { Debug.Assert(ActorMonster != null); ActorRoom = ActorMonster.GetInRoom(); Debug.Assert(ActorRoom != null); if (InputBuf.Length == 0) { InputBuf.SetFormat("{0}", LastInputStr); if (InputBuf.Length > 0 && ActorMonster.IsCharacterMonster()) { if (Environment.NewLine.Length == 1 && Globals.CursorPosition.Y > -1 && Globals.CursorPosition.Y + 1 >= gOut.GetBufferHeight()) { Globals.CursorPosition.Y--; } gOut.SetCursorPosition(Globals.CursorPosition); if (Globals.LineWrapUserInput) { gEngine.LineWrap(InputBuf.ToString(), Globals.Buf, Globals.CommandPrompt.Length); } else { Globals.Buf.SetFormat("{0}", InputBuf.ToString()); } gOut.WordWrap = false; gOut.WriteLine(Globals.Buf); gOut.WordWrap = true; } } LastInputStr = InputBuf.ToString(); InputBuf = ReplacePrepositions(InputBuf); Tokens = InputBuf.ToString().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (CurrToken < Tokens.Length) { if (Tokens.Length == 1) { Globals.Buf.SetFormat("{0}", Tokens[CurrToken]); Tokens[CurrToken] = Globals.Buf.TrimEndPunctuationMinusPound().ToString().Trim(); } if (Tokens[CurrToken].Length == 0) { Tokens[CurrToken] = "???"; } else if (string.Equals(Tokens[CurrToken], "at", StringComparison.OrdinalIgnoreCase)) { Tokens[CurrToken] = "a"; } var command = Globals.CommandList.FirstOrDefault(x => x.Verb != null && string.Equals(x.Verb, Tokens[CurrToken], StringComparison.OrdinalIgnoreCase) && x.IsEnabled(ActorMonster)); if (command == null) { command = Globals.CommandList.FirstOrDefault(x => x.Synonyms != null && x.Synonyms.FirstOrDefault(s => string.Equals(s, Tokens[CurrToken], StringComparison.OrdinalIgnoreCase)) != null && x.IsEnabled(ActorMonster)); } if (command == null) { command = Globals.CommandList.FirstOrDefault(x => x.Verb != null && (x.Verb.StartsWith(Tokens[CurrToken], StringComparison.OrdinalIgnoreCase) || x.Verb.EndsWith(Tokens[CurrToken], StringComparison.OrdinalIgnoreCase)) && x.IsEnabled(ActorMonster)); } if (command == null) { command = Globals.CommandList.FirstOrDefault(x => x.Synonyms != null && x.Synonyms.FirstOrDefault(s => s.StartsWith(Tokens[CurrToken], StringComparison.OrdinalIgnoreCase) || s.EndsWith(Tokens[CurrToken], StringComparison.OrdinalIgnoreCase)) != null && x.IsEnabled(ActorMonster)); } if (command != null) { CurrToken++; NextState = Activator.CreateInstance(command.GetType()) as IState; command = NextState as ICommand; Debug.Assert(command != null); command.CommandParser = this; command.ActorMonster = ActorMonster; command.ActorRoom = ActorRoom; command.Dobj = DobjData.Obj; command.Iobj = IobjData.Obj; if (command.ShouldStripTrailingPunctuation() && Tokens.Length > 1) { Globals.Buf.SetFormat("{0}", Tokens[Tokens.Length - 1]); Tokens[Tokens.Length - 1] = Globals.Buf.TrimEndPunctuationMinusPound().ToString().Trim(); } if (ActorMonster.IsCharacterMonster()) { CheckPlayerCommand(command, false); if (NextState == command) { if (ActorRoom.IsLit() || command.IsDarkEnabled) { command.FinishParsing(); if (NextState == command) { CheckPlayerCommand(command, true); } } else { NextState = null; } } } else { command.FinishParsing(); } if (NextState == null) { NextState = Globals.CreateInstance <IStartState>(); } } } }
public virtual void Execute() { if (!gGameState.EnhancedParser) { ParserInputStrList.Add(InputBuf.ToString()); goto Cleanup; } InputBuf.SetFormat("{0}", Regex.Replace(InputBuf.ToString(), @"\s+", " ").Trim()); if (InputBuf.Length == 0) { InputBuf.SetFormat("{0}", LastInputStr); if (InputBuf.Length > 0) { if (Environment.NewLine.Length == 1 && Globals.CursorPosition.Y > -1 && Globals.CursorPosition.Y + 1 >= gOut.GetBufferHeight()) { Globals.CursorPosition.Y--; } gOut.SetCursorPosition(Globals.CursorPosition); if (Globals.LineWrapUserInput) { gEngine.LineWrap(InputBuf.ToString(), Globals.Buf, Globals.CommandPrompt.Length); } else { Globals.Buf.SetFormat("{0}", InputBuf.ToString()); } gOut.WordWrap = false; gOut.WriteLine(Globals.Buf); gOut.WordWrap = true; } } OrigInputStr = InputBuf.ToString(); LastInputStr = InputBuf.ToString(); InputBuf = gEngine.NormalizePlayerInput(InputBuf); Tokens = InputBuf.ToString().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); for (CurrToken = 0; CurrToken < Tokens.Length; CurrToken++) { if (CurrToken == 0) { TokenCommand = gEngine.GetCommandUsingToken(gCharMonster, Tokens[CurrToken]); if (TokenCommand != null && gEngine.IsQuotedStringCommand(TokenCommand)) { ParserInputStrList.Add(OrigInputStr); goto Cleanup; } } else if (Tokens[CurrToken] == "," && CurrToken + 1 < Tokens.Length) { TokenCommand = gEngine.GetCommandUsingToken(gCharMonster, Tokens[CurrToken + 1]); if (TokenCommand != null && IsValidTokenCommandMatch()) { CurrInputStr = string.Join(" ", Tokens.Skip((int)(StartToken)).Take((int)(CurrToken - StartToken))); if (CurrInputStr.Length > 0) { ParserInputStrList.Add(CurrInputStr); } StartToken = CurrToken + 1; } } } if (Tokens.Length > 0) { CurrInputStr = string.Join(" ", Tokens.Skip((int)(StartToken)).Take((int)(Tokens.Length - StartToken))); if (CurrInputStr.Length > 0) { ParserInputStrList.Add(CurrInputStr); } } if (ParserInputStrList.Count > 1) { for (CurrIndex = 0; CurrIndex < ParserInputStrList.Count; CurrIndex++) { CurrInputStr = ParserInputStrList[(int)CurrIndex]; Tokens = CurrInputStr.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (Tokens.Length > 0) { TokenCommand = gEngine.GetCommandUsingToken(gCharMonster, Tokens[0]); if (TokenCommand == null) { RemoveIndex = CurrIndex; break; } else if (!TokenCommand.IsSentenceParserEnabled) { RemoveIndex = CurrIndex > 0 ? CurrIndex : CurrIndex + 1; break; } else if (TokenCommand.Type == CommandType.Movement) { RemoveIndex = CurrIndex + 1; break; } } } while (RemoveIndex >= 0 && ParserInputStrList.Count > RemoveIndex) { gOut.Print("{{Discarding: \"{0}\"}}", ParserInputStrList[(int)RemoveIndex]); ParserInputStrList.RemoveAt((int)RemoveIndex); } } if (ParserInputStrList.Count < 1 && OrigInputStr.Length > 0) { ParserInputStrList.Add(OrigInputStr); } Cleanup: ; }