void Init() { if (initialized) { return; } else { initialized = true; } InitializeCommands(); InitializeListUi(); tokenizer = new Tokenizer(); CodeConvert.TryParse(dialogAsset.text, out dialogs, GetScriptScope(), tokenizer); if (tokenizer.errors.Count > 0) { Debug.LogError(tokenizer.errors.Join("\n")); } //Debug.Log(tokenizer.DebugPrint()); //Debug.Log(NonStandard.Show.Stringify(dialogs, true)); if (dialogs == null) { dialogs = new List <Dialog>(); } if (dialogs.Count > 0) { SetDialog(dialogs[0], UiPolicy.StartOver); } }
public Dialog[] Generate() { Dictionary <string, object> parametersForTemplate; Tokenizer tokenizer = new Tokenizer(); string dialogData = DialogManager.Instance.GetAsset(parameters), dialogTemplate = DialogManager.Instance.GetAsset(template); if (dialogData == null || dialogTemplate == null) { Show.Error("failed to find components of templated script " + template + "<" + parameters + ">"); return(null); } CodeConvert.TryParse(dialogData, out parametersForTemplate, null, tokenizer); if (tokenizer.ShowErrorTo(Show.Error)) { return(null); } //Show.Log(parametersForTemplate.Stringify(pretty: true)); Dialog[] templatedDialogs; CodeConvert.TryParse(dialogTemplate, out templatedDialogs, parametersForTemplate, tokenizer); if (tokenizer.ShowErrorTo(Show.Error)) { return(null); } //Show.Log(templatedDialogs.Stringify(pretty: true)); return(templatedDialogs); }
public void Init() { Tokenizer tokenizer = new Tokenizer(); CodeConvert.TryParse(resourceNamesText.text, out resourceNames, null, tokenizer); GenerateAdvancementSequence(); }
void Start() { if (dialogView == null) { dialogView = FindObjectOfType <DialogViewer>(); } if (dict == null) { dict = GetComponentInChildren <ScriptedDictionary>(); } Dialog[] dialogs; //NonStandard.Show.Log(knownAssets.JoinToString(", ", ta => ta.name)); //NonStandard.Show.Log(root.name+":" + root.text.Length); Tokenizer tokenizer = new Tokenizer(); if (dict != null) { Global.GetComponent <ScriptedDictionaryManager>().SetMainDicionary(dict); } try { CodeConvert.TryParse(root.text, out dialogs, dict.Dictionary, tokenizer); tokenizer.ShowErrorTo(NonStandard.Show.Error); if (dialogs == null) { return; } //NonStandard.Show.Log("dialogs: [" + d.Stringify(pretty:true)+"]"); this.dialogs.AddRange(dialogs); ResolveTemplatedDialogs(this.dialogs); } catch (System.Exception e) { NonStandard.Show.Log("~~~#@Start " + e); } //NonStandard.Show.Log("finished initializing " + this); //NonStandard.Show.Log(this.dialogs.JoinToString(", ", dialog => dialog.name)); // execute all "__init__" dialogs ScriptedDictionaryManager m = Global.Get <ScriptedDictionaryManager>(); object standardScope = m.Main; //Commander.Instance.GetScope(); for (int i = 0; i < this.dialogs.Count; ++i) { Dialog dialog = this.dialogs[i]; if (!dialog.name.StartsWith("__init__")) { continue; } //NonStandard.Show.Log("initializing "+dialog.name); Tokenizer tok = new Tokenizer(); dialog.ExecuteCommands(tok, standardScope); if (tok.HasError()) { tok.ShowErrorTo(NonStandard.Show.Warning); } } //NonStandard.Show.Log(standardScope.Stringify(pretty: true)); }
static void Main(string[] args) { string testData = "name\"the player\"i-2 f3testing12\"3\"2.99"; SensitiveHashTable_stringfloat dict; Tokenizer tok = new Tokenizer(); CodeConvert.TryParse(testData, out dict, null, tok); if (tok.errors.Count > 0) { Show.Log(tok.errors.Join("\n")); } Show.Log(tok.DebugPrint()); Show.Log("result: " + Show.Stringify(dict, true)); }
void InitColumnSettings(string columnSetup) { //Show.Log(columnSetup); Tokenizer tokenizer = new Tokenizer(); CodeConvert.TryParse(columnSetup, out UnityColumnData[] columns, null, tokenizer); if (tokenizer.HasError()) { Show.Error("error parsing column structure: " + tokenizer.GetErrorString()); return; } int index = 0; //data.AddRange(list, tokenizer); for (int i = 0; i < columns.Length; ++i) { UnityColumnData c = columns[i]; c.typeOfValue = c.defaultValue != null?c.defaultValue.GetType() : null; Udash.ColumnSetting columnSetting = new Udash.ColumnSetting(data) { //fieldToken = c.valueScript, data = new UnityColumnData { label = c.label, columnUi = c.columnUi, headerUi = c.headerUi, widthOfColumn = -1, onClick = c.onClick, alwaysLast = c.alwaysLast }, type = c.typeOfValue, defaultValue = c.defaultValue }; columnSetting.SetFieldToken(c.valueScript, tokenizer); data.SetColumn(index, columnSetting); if (c.widthOfColumn > 0) { data.columnSettings[index].data.widthOfColumn = c.widthOfColumn; } ++index; } RefreshHeaders(); }
bool AddArg(Argument arg, ref int i, List <Token> tokens, Tokenizer tokenizer, object scriptVariables) { if (arg.flag) { namedValues[arg.id] = true; return(true); } if (++i >= tokens.Count) { return(false); } Token tValue = tokens[i]; CodeConvert.TryParse(tokens[i], out object result, scriptVariables, tokenizer); Type type = arg.valueType; //Show.Log(resultType + " : " + result.StringifySmall()); bool goodArgument = false; if (result != null) { if (!(goodArgument = result.GetType() == type)) { goodArgument = CodeConvert.TryConvert(ref result, type); } if (goodArgument) { namedValues[arg.id] = result; } } if (!goodArgument) { tokenizer.AddError(tValue.index, "Could not cast (" + type.Name + ") from (" + (result?.GetType().ToString() ?? "null") + ")"); } return(goodArgument); }
public void LevelGenerate(LevelState lvl) { Team team = Global.GetComponent <Team>(); EventBind checkGoal = new EventBind(this, nameof(GoalCheck)); if (lvl == null) { lvl = new LevelState(); lvl.stage = maze.stage; lvl.seed = random.Seed; lvl.idolsDistributed = idolCreator.idolsDistributed; if (inventory.GetItems() != null) { lvl.idolInventory = CodeConvert.Stringify(inventory.GetItems().ConvertAll(go => { Idol t = go.GetComponent <Idol>(); return(t ? t.intMetaData : null); })); } else { lvl.idolInventory = ""; } lvl.variables = CodeConvert.Stringify(mainDictionaryKeeper.Dictionary); lvl.allies = CodeConvert.Stringify(team.members.ConvertAll(m => npcCreator.npcs.FindIndex(n => n.gameObject == m))); levels.Add(lvl); } else { Tokenizer tokenizer = new Tokenizer(); // check if level is valid if (levels.IndexOf(lvl) < 0) { throw new Exception("TODO validate the level plz!"); } // set allies int[] allies; CodeConvert.TryParse(lvl.allies, out allies, null, tokenizer); team.Clear(); team.AddMember(firstPlayer); for (int i = 0; i < allies.Length; ++i) { int index = allies[i]; if (index < 0) { continue; } team.AddMember(npcCreator.npcs[index].gameObject); } // clear existing idols idolCreator.Clear(); // reset inventory to match start state inventory.RemoveAllItems(); int[][] invToLoad; CodeConvert.TryParse(lvl.idolInventory, out invToLoad, null, tokenizer); //Debug.Log(Show.Stringify(invToLoad,false)); Vector3 playerLoc = Global.GetComponent <CharacterControlManager>().localPlayerInterfaceObject.transform.position; for (int i = 0; i < invToLoad.Length; ++i) { int[] t = invToLoad[i]; if (t == null || t.Length == 0) { continue; } GameObject idol = idolCreator.CreateIdol(t[0], t[1], checkGoal); idol.transform.position = playerLoc + Vector3.forward; inventory.AddItem(idol); } // set stage maze.stage = lvl.stage; // set seed random.Seed = lvl.seed; // set variables HashTable_stringobject d = mainDictionaryKeeper.Dictionary; CodeConvert.TryParse(lvl.variables, out d, null, tokenizer); // set } MarkTouchdown.ClearMarkers(); clickToMove.ClearAllWaypoints(); seedLabel.text = "level " + maze.stage + "." + Convert.ToBase64String(BitConverter.GetBytes(random.Seed)); maze.Generate(random); Discovery.ResetAll(); idolCreator.Generate(checkGoal); int len = Mathf.Min(maze.floorTileNeighborHistogram[2], idolCreator.idolMaterials.Count); npcCreator.GenerateMore(len); if (testingPickups) { idolCreator.GenerateMoreIdols(checkGoal); } // TODO maze should have a list of unfilled tiles sorted by weight for (int i = 0; i < npcCreator.npcs.Count; ++i) { maze.PlaceObjectOverTile(npcCreator.npcs[i].transform, maze.floorTiles[maze.floorTileNeighborHistogram[1] + i]); } team.AddMember(firstPlayer); maze.PlaceObjectOverTile(team.members[0].transform, maze.floorTiles[maze.floorTiles.Count - 1]); Vector3 pos = team.members[0].transform.position; for (int i = 0; i < team.members.Count; ++i) { team.members[i].transform.position = pos; CharacterMove cm = team.members[i].GetComponent <CharacterMove>(); if (cm != null) { cm.SetAutoMovePosition(pos); cm.MoveForwardMovement = 0; cm.StrafeRightMovement = 0; } } UiText.SetColor(timer.gameObject, Color.white); timer.Start(); GoalCheck(null); nextLevelButton.SetActive(false); bestTimeLabel.gameObject.SetActive(false); }
public void Init() { Tokenizer tokenizer = new Tokenizer(); CodeConvert.TryParse(npcNamesText.text, out npcNames, null, tokenizer); }
protected bool TryGetValue() { memberValue = null; Token token = Current.GetToken(); object meta = token.meta; if (SkipStructuredDelimiters(meta as Delim)) { return(true); } Context.Entry context = meta as Context.Entry; if (context != null) { bool subContextUsingSameList = context.tokens == Current.tokens; if (context.IsText()) { memberValue = context.GetText(); } else { int index = Current.tokenIndex; List <Token> parseNext = subContextUsingSameList ? Current.tokens.GetRange(index, context.tokenCount) : context.tokens; if (memberType == typeof(Expression)) { memberValue = new Expression(parseNext); } else { if (CodeConvert.IsConvertable(memberType) && !subContextUsingSameList) { memberValue = context.Resolve(tok, scope); } else { if (!CodeConvert.TryParse(memberType, parseNext, ref memberValue, scope, tok)) { return(false); } } } } if (subContextUsingSameList) { Current.tokenIndex += context.tokenCount - 1; // -1 because increment happens after this method } return(true); } string s = meta as string; if (s != null) { memberValue = token.ToString(s); if (!CodeConvert.TryConvert(ref memberValue, memberType)) { AddError("unable to convert (" + memberValue + ") to type '" + memberType + "'"); return(false); } return(true); } TokenSubstitution sub = meta as TokenSubstitution; if (sub != null) { memberValue = sub.value; if (!CodeConvert.TryConvert(ref memberValue, memberType)) { AddError("unable to convert substitution (" + memberValue + ") to type '" + memberType + "'"); return(false); } return(true); } AddError("unable to parse token with meta data " + meta); return(false); }