public void GenLookupContextTest() { var d = SetUpLookupContextData(); var f = d.GenDataDef; var r = new GenProfileFragment(new GenProfileParams(GenData.GenDataDef)); var b = new GenBlock(new GenFragmentParams(f, r)); var p0 = new GenPlaceholderFragment(new GenPlaceholderFragmentParams(f, b, f.GetId("Parent.Name"))); var t0 = new GenTextFragment(new GenTextFragmentParams(f, b, ",")); b.Body.Add(p0); b.Body.Add(t0); var g = new GenLookup(new GenLookupParams(f, b, "Lookup.Name=Child.Lookup")); var p1 = new GenPlaceholderFragment(new GenPlaceholderFragmentParams(f, g, f.GetId("Lookup.Name"))); var t1 = new GenTextFragment(new GenTextFragmentParams(f, g, ",")); Assert.IsFalse(g.NoMatch); b.Body.Add(g); g.Body.Add(p1); g.Body.Add(t1); var parent = GenObject.GetContext(d.Root, "Parent"); var child = GetFirstObjectOfSubClass(parent, "Child"); b.GenObject = child; VerifyFragment(d, b, "GenBlock", FragmentType.Block, "Block", "`{`Parent.Name`,`%Lookup.Name=Child.Lookup:`Lookup.Name`,`]`]", "Parent,Valid,", false, null, r.Profile.GenDataBase.GenDataDef); child = GetLastObjectInSubClass(child); b.GenObject = child; VerifyFragment(d, b, "GenBlock", FragmentType.Block, "Block", "`{`Parent.Name`,`%Lookup.Name=Child.Lookup:`Lookup.Name`,`]`]", "Parent,", false, null, r.Profile.GenDataBase.GenDataDef); }
public GenBlock EnterBlock() { var b = new GenBlock(); b.parent = this.cur_block; this.cur_block = b; return(b); }
private void OutputText(GenContainerFragmentBase parentContainer, bool isPrimary, string text) { GenFragment frag = new GenBlock(new GenFragmentParams(GenDataDef, parentContainer)); ((GenBlock)frag).Body.Add( new GenTextFragment(new GenTextFragmentParams(GenDataDef, parentContainer, text, isPrimary))); }
public void LeaveBlock() { // todo@om 这儿如果抛异常了,就难受了。 foreach (var obj in cur_block.scope_objs) { obj.Dispose(); } this.cur_block = this.cur_block.parent !; }
private GenBlock ScanBlock(int classId, GenContainerFragmentBase parentContainer, bool isPrimary = true) { var frag = new GenBlock(new GenFragmentParams(GenDataDef, parentContainer, isPrimary)); if (Scan.CheckChar('{')) { Scan.SkipChar(); } ScanBody(classId, frag.Body, frag, frag.Block); return(frag); }
// Finds directions for the recursive search, only for rooms that haven't already been visited private List <GenBlockSpacialProperties> GetViableDirections(GenBlock block) { List <GenBlockSpacialProperties> directions = new List <GenBlockSpacialProperties>(); foreach (var pair in block.mSpacialData.mNeighbours) { if (!pair.Value.mSpacialData.mVisited && !pair.Value.mSpacialData.mDeadEnd) { directions.Add(pair.Key); } } return(directions); }
public override void OnInspectorGUI() { // Get our block serializedObject.Update(); GenBlock myBlock = (GenBlock)target; // Set up our label fonts GUIStyle header = new GUIStyle(); header.fontStyle = FontStyle.Bold; header.fontSize = 12; header.alignment = TextAnchor.UpperCenter; header.wordWrap = true; GUIStyle body = new GUIStyle(); body.fontSize = 11; body.wordWrap = true; // Start our layout GUILayout.Space(10); GUILayout.Label("GenBlock Settings", header); GUILayout.Space(5); GUILayout.Label("This script is used to set the specifics of this current GenBlock. Wider options can be found in the Generation Manager script.", body); GUILayout.Space(5); // Lock Bool GUI.backgroundColor = serializedObject.FindProperty("mLock").boolValue ? Color.red : Color.green; // Set the colour depending on our locked status if (GUILayout.Button(serializedObject.FindProperty("mLock").boolValue ? "Unlock GenBlock Terrain" : "Lock Genblock Terrain")) { serializedObject.FindProperty("mLock").boolValue = !serializedObject.FindProperty("mLock").boolValue; } // Gizmo Bool GUI.backgroundColor = serializedObject.FindProperty("mDrawSpacialDataGizmos").boolValue ? Color.red : Color.green; // Set the colour depending on our locked status if (GUILayout.Button(serializedObject.FindProperty("mDrawSpacialDataGizmos").boolValue ? "Hide Spacial Data Gizmos" : "Draw Spacial Data Gizmos")) { serializedObject.FindProperty("mDrawSpacialDataGizmos").boolValue = !serializedObject.FindProperty("mDrawSpacialDataGizmos").boolValue; } GUI.backgroundColor = Color.white; // Reset the GUI Colour serializedObject.ApplyModifiedProperties(); }
private void GenerateBlockTerrain(GenBlock block) { block.transform.SetParent(mFloorParents[block.mCurrentFloorLevel].transform); RoomAndRotation room = block.GetRandomRoom(); if (room.mRoom != null) { GameObject roomObject = Instantiate(room.mRoom); roomObject.transform.parent = block.transform; roomObject.transform.localPosition = Vector3.zero; if (room.mRotateOnY != 0) { roomObject.transform.rotation *= Quaternion.Euler(0, room.mRotateOnY, 0); } } }
// Generate our terrain using a backwards recursive search to define the paths. private void GenerateMaze(GenBlock startBlock) { // Begin Recursive Backtracking Stack <GenBlock> blockStack = new Stack <GenBlock>(); blockStack.Push(startBlock); while (blockStack.Count > 0) { // Pop our current block and process its spacial data GenBlock block = blockStack.Pop(); if (!block.mSpacialData.mDeadEnd) { // Now that the block is popped, we have visited here block.mSpacialData.mVisited = true; // Check for available directions var candidatesDirections = GetViableDirections(block); if (candidatesDirections.Count > 0) { // Get a random Direction var direction = candidatesDirections[Random.Range(0, candidatesDirections.Count - 1)]; // Set our used path in this direction block.mSpacialData.mUsedPaths |= direction; // Set our new rooms used path in the opposite direction block.mSpacialData.mNeighbours[direction].mSpacialData.mUsedPaths |= GetOppositeDirection(direction); // Add our current block and then our next block to the stack blockStack.Push(block); blockStack.Push(block.mSpacialData.mNeighbours[direction]); } else { // We have nowhere to go, so we are a dead end block.mSpacialData.mDeadEnd = true; } } // We're a dead end, so generate our terrain if (block.mSpacialData.mDeadEnd) { GenerateBlockTerrain(block); } } }
public void GenBlockTest() { var r = new GenProfileFragment(new GenProfileParams(GenData.GenDataDef)); var g = new GenBlock(new GenFragmentParams(GenDataDef, r)); r.Body.Add(g); var p = new GenPlaceholderFragment(new GenPlaceholderFragmentParams(GenDataDef, g, GenDataDef.GetId("Property.Name"))); var t = new GenTextFragment(new GenTextFragmentParams(GenData.GenDataDef, g, ",")); g.Body.Add(p); g.Body.Add(t); g.GenObject = GetNextObjectInSubClass(GetFirstObjectOfSubClass(GetFirstObject(GenData), "Property")); VerifyFragment(GenData, g, "GenBlock", FragmentType.Block, "Block", "`{`Property.Name`,`]", "Property2,", false, null, r.Profile.GenDataBase.GenDataDef); }
public LocalValue GetName(string name, out bool is_global) { GenBlock b = this.cur_block; LocalValue ret = null; while (b != null) { if (b.values.TryGetValue(name, out ret)) { is_global = true; return(ret); } b = b.parent; } is_global = this.func.upvalues.TryGetValue(name, out ret); return(ret); }
private bool GenerateMap() { // Find a GenBlock on the lowest level GenBlock startBlock = null; foreach (GenBlock block in mGenBlocks) { // Don't generate the terrain for Isolated GenBlocks if (block.mSpacialData.mIsolated) { mGenBlocks.Remove(block); DestroyImmediate(block); continue; } // Reset each blocks data block.mSpacialData.mDeadEnd = false; block.mSpacialData.mVisited = false; block.mSpacialData.mUsedPaths = 0; // Find if we're the start block if (!startBlock) { startBlock = block; } else if (block.transform.position.y < startBlock.transform.position.y) { startBlock = block; } } if (mUseMaze) { GenerateMaze(startBlock); } else { GenerateOpenPlan(); } return(true); }
public static GenericBlockConstructor BlockConstructor(GenBlock newBlock) { return(new GenericBlockConstructor(newBlock)); }
private static void ClassProfile(GenDataDef genDataDef, int classId, GenContainerFragmentBase profile, GenContainerFragmentBase parentContainer) { GenSegment classProfile = null; if (classId != 0) { GenTextBlock textBlock = null; var sb = new StringBuilder(); classProfile = new GenSegment( new GenSegmentParams(genDataDef, parentContainer, genDataDef.GetClassName(classId), genDataDef.GetClassIsInherited(classId) ? GenCardinality.Inheritance : GenCardinality.All)); if (!genDataDef.GetClassIsAbstract(classId)) { sb.Append(genDataDef.GetClassName(classId)); } if (genDataDef.GetClassProperties(classId).Count > 0 && !genDataDef.GetClassDef(classId).IsAbstract) { var j = 0; if ( String.Compare(genDataDef.GetClassProperties(classId)[0], "Name", StringComparison.OrdinalIgnoreCase) == 0) { sb.Append("="); AddText(genDataDef, ref textBlock, classProfile, sb); AddText(genDataDef, ref textBlock, classProfile, genDataDef.GetId(genDataDef.GetClassName(classId), "Name")); j = 1; } else { AddText(genDataDef, ref textBlock, classProfile, sb); } if (genDataDef.GetClassProperties(classId).Count > j) { AddText(genDataDef, ref textBlock, classProfile, "["); textBlock = null; var sep = ""; for (var i = j; i < genDataDef.GetClassProperties(classId).Count; i++) { var condExists = new GenCondition(new GenConditionParams(genDataDef, classProfile, new ConditionParameters { GenComparison = GenComparison.Exists, Var1 = genDataDef.GetId(genDataDef.GetClassName(classId), genDataDef.GetClassProperties(classId)[i]) })); condExists.Body.Add( new GenTextFragment(new GenTextFragmentParams(genDataDef, condExists, sep + genDataDef.GetClassProperties(classId)[i]))); var condNotTrue = new GenCondition(new GenConditionParams(genDataDef, condExists, new ConditionParameters { GenComparison = GenComparison.Ne, Var1 = genDataDef.GetId(genDataDef.GetClassName(classId), genDataDef.GetClassProperties(classId)[i]), Lit = "True", UseLit = true })); condNotTrue.Body.Add( new GenTextFragment(new GenTextFragmentParams(genDataDef, condNotTrue, "="))); var functionQuote = new GenFunction(new GenFunctionParams(genDataDef, condNotTrue, "StringOrName")); var param = new GenBlock(new GenFragmentParams(genDataDef, functionQuote)); param.Body.Add( new GenPlaceholderFragment(new GenPlaceholderFragmentParams(genDataDef, param, genDataDef.GetId(genDataDef.GetClassName(classId), genDataDef.GetClassProperties(classId)[i])))); functionQuote.Body.Add(param); condNotTrue.Body.Add(functionQuote); condExists.Body.Add(condNotTrue); classProfile.Body.Add(condExists); sep = ","; } AddText(genDataDef, ref textBlock, classProfile, "]\r\n"); } else { AddText(genDataDef, ref textBlock, classProfile, "\r\n"); } } profile.Body.Add(classProfile); } foreach (var inheritor in genDataDef.GetClassInheritors(classId)) { ClassProfile(genDataDef, inheritor.ClassId, classProfile ?? profile, classProfile); } if (!genDataDef.GetClassIsAbstract(classId)) { SubClassProfiles(genDataDef, classId, profile, classProfile ?? profile, classProfile); } if (genDataDef.GetClassIsInherited(classId)) { SubClassProfiles(genDataDef, genDataDef.GetClassParent(classId).ClassId, profile, classProfile ?? profile, classProfile); } }
public Frame(MyFunction func) { this.func = func; this.cur_block = new GenBlock(); }
private void ScanBlockParams(GenSegBody body, GenContainerFragmentBase parentContainer, Function function, FragmentBody fragmentBody) { Scan.ScanWhile(ScanReader.WhiteSpace); if (Scan.CheckChar(Scan.Delimiter)) { Scan.SkipChar(); } var t = Scan.ScanTokenType(); while (t != TokenType.Close) { string s; if (t != TokenType.Unknown && t != TokenType.Name) { // Parameter starts with a delimiter if (t != TokenType.Close && t != TokenType.Unknown) { // Scan contained block GenTextBlock textBlock = null; var frag = ScanFragment(GenDataDef.CurrentClassId, ref t, out s, parentContainer, fragmentBody, ref textBlock, true); body.Add(frag ?? textBlock); // Skip blank parameter separators s = s.TrimStart(); if (s != "") { body.Add( new GenTextFragment(new GenTextFragmentParams(GenDataDef, parentContainer, s))); } t = Scan.ScanTokenType(); } } else { // Parameter starts without a delimiter var block = new GenBlock(new GenFragmentParams(GenDataDef, parentContainer)); s = Scan.CheckChar('\'') ? Scan.ScanQuotedString() : Scan.ScanUntil(_parameterSeparator); while (Scan.CheckChar(' ')) { Scan.SkipChar(); } // Scan for Text and Placeholders var i = s.IndexOf(Scan.Delimiter); while (i != -1) { var w = s.Substring(0, i - 1); // Text up to first delimiter s = s.Substring(i + 1); // Text after first delimeter if (s != "") { // Some text after the first delimiter i = s.IndexOf(Scan.Delimiter); // Position of next delimiter if (i != -1) { if (w != "") { // Add Text up to first delimiter block.Body.Add( new GenTextFragment(new GenTextFragmentParams(GenDataDef, parentContainer, w))); } w = s.Substring(0, i - 1); // Text between initial two delimiters block.Body.Add( new GenPlaceholderFragment(new GenPlaceholderFragmentParams(GenDataDef, parentContainer, GenDataDef.GetId(w)))); s = s.Substring(i + 1); i = s.IndexOf(Scan.Delimiter); } else { // No matching delimiter: output delimiter with text block.Body.Add( new GenTextFragment(new GenTextFragmentParams(GenDataDef, parentContainer, w + Scan.Delimiter + s))); s = ""; } } else { // No text after initial delimiter: output delimiter with text block.Body.Add( new GenTextFragment(new GenTextFragmentParams(GenDataDef, parentContainer, w + Scan.Delimiter))); i = -1; } } if (s != "" || block.Body.Count == 0) { // Text without placeholders block.Body.Add( new GenTextFragment(new GenTextFragmentParams(GenDataDef, block, s))); } body.Add(block); if (Scan.CheckChar(Scan.Delimiter)) { Scan.SkipChar(); } t = Scan.ScanTokenType(); } } if (t == TokenType.Close) { Scan.SkipChar(); } }
public void LeaveBlock() { this.cur_block = this.cur_block.parent; }