/// <summary> /// Checks to see if object (obj) is of the specified kind. /// </summary> /// <param name="obj"></param> /// <param name="kind"></param> /// <returns></returns> bool isKind(ZObject obj, ZObject kind) { return ((SparseGraph<ZObject>)relations[__kind]).reachable(obj, kind, delegate(ZObject n) { return ((Dictionary<ZObject, ZObject>)relations[_instance]).ContainsKey(n); }); }
private void AddObjectToIndex(ZObject obj, string physicalPath) { if (obj is Riff.Texture) { return; // Not written for some reason (at least for album art) } AddFileToIndex(obj.FilePath, obj.Type, physicalPath); }
/// <summary> /// This create a "concrete" entity instance rather than abstract kinds /// </summary> /// <param name="name">The internal name</param> /// <returns>The new object</returns> ZObject Instance() { // Create the new object var ret = new ZObject(); // It is an instance ((Dictionary<ZObject, ZObject>)relations[_instance])[ret] = ret; return ret; }
/// <summary> /// Remove a child node from the list of tracked children /// </summary> /// <param name="Child">Child to remove</param> internal void RemoveChild(ZObject Child) { for (int I = 0; I < NumChildren; I++) if ((object) Child == (object) Children[I]) { NumChildren--; Children[I] = Children[NumChildren]; Children[NumChildren] = null; break; } }
/// <summary> /// Transitively links the two space cells togehter /// </summary> /// <param name="direction"></param> /// <param name="a"></param> /// <param name="b"></param> internal void inDirection(ZObject direction, ZObject a, ZObject b) { ((SparseGraph<ZObject>)relations[direction]).After(a, new Edge<ZObject>(b, null)); List<Edge<ZObject>> edges; if (((SparseGraph<ZObject>)relations[opposite]).successors(direction, out edges)) { var opEdge = new Edge<ZObject>(a, null); foreach (var op in edges) ((SparseGraph<ZObject>)relations[op.sink]).After(b, opEdge); } }
public static void Delete(ZObject obj) { var co = GetCycleObjectByObj(obj); if (co == null) { ZLogger.Warning($"{obj.GetType().Name} is not a cycle object"); return; } co.Use = false; }
private TreeViewItem AddNode(TreeViewItem parent, string currentPath, string text, bool folder, Index2Entry entry) { //node.Items.Cast<TreeViewItem>(). string key = CreateKey(currentPath, folder); object needle = TreeView_Archive.FindName(key); if (needle != null) { return(needle as TreeViewItem); } else { //TreeFileEntry temp = new TreeFileEntry(); TreeViewItem child = new TreeViewItem(); child.Header = text; child.Name = key; child.Selected += (sender, e) => { //this.selectedObject = entry; if (!entry.IsZObject()) { selectedObject = null; ListView_Catalog.Items.Clear(); return; } var zObject = manager[entry.FilePath]; if (zObject is Catalog2 catalog2) { ListView_Catalog.ItemsSource = catalog2.Entries; } else { selectedObject = null; ListView_Catalog.ItemsSource = null; } }; //temp.Path = currentPath; TreeView_Archive.RegisterName(key, child); int returnIdx = parent.Items.Add(child); if (!folder) { child.Tag = entry; } SetNodeProperties(child); return(parent.Items[returnIdx] as TreeViewItem); } }
public ObjectViewModel(ZObject obj) { this.obj = obj; var props = new List <PropertyViewModel>(); foreach (var prop in obj.PropertyTable) { props.Add(new PropertyViewModel(prop)); } properties = new ReadOnlyCollection <PropertyViewModel>(props); }
/// <summary> /// Finds the object that best directly matches the phrase. /// /// This naively finds the single best match. Future is to return a list /// </summary> /// <param name="lexer">The text being matched</param> /// <param name="numWordsMatch">The number of words that match [out]</param> /// <returns>The object that matches; null on error</returns> object matchInContext(ZObject addressedTo, Lexer lexer, out int numWordsMatch, ref LexState lexerState) { // A table of already examined objects var seen = new Dictionary<object,object>(); // The score board for the search var score = 0.0; // The score for the best match: 0 if no match numWordsMatch = 1; // The number of words that match: Minimum of 1 object bestMatch = null;// The object that best matches matchInContext(addressedTo, lexer, ref score, ref numWordsMatch, ref bestMatch, ref lexerState, seen); // Return the best match return bestMatch; }
private static CycleObject GetCycleObjectByObj(ZObject obj) { lock (LockObj) { var count = Objects.Count; for (var i = 0; i < count; i++) { var co = Objects[i]; if (co.Obj.Equals(obj)) { return(co); } } return(null); } }
// Constructor is private. Pipe can only be created using // pipepair function. private Pipe(ZObject parent, YPipe<Msg> inpipe, YPipe<Msg> outpipe, int inhwm, int outhwm, bool delay) : base(parent) { m_parent = parent; m_inpipe = inpipe; m_outpipe = outpipe; m_inActive = true; m_outActive = true; m_hwm = outhwm; m_lwm = ComputeLwm (inhwm); m_msgsRead = 0; m_msgsWritten = 0; m_peersMsgsRead = 0; m_peer = null ; m_sink = null ; m_state = State.Active; m_delay = delay; }
private Dictionary <string, ReadJsonDelegate> GetReadJsonDelegates(ZObject obj) { var type = obj.GetType(); var result = new Dictionary <string, ReadJsonDelegate>(); while (type != typeof(ZObject)) { var readJsonMethod = type.GetMethod("ReadJson", readJsonArgumentTypes); if (!(readJsonMethod is null) && readJsonMethod.DeclaringType == type) { result.Add(type.FullName, (ReadJsonDelegate)Delegate.CreateDelegate(typeof(ReadJsonDelegate), obj, readJsonMethod)); } type = type.BaseType; } return(result); }
public void ResolveObjects(Dictionary <long, ZObject> objects) { foreach (var kv in m_createdObjectReferences) { long id = kv.Key; if (objects.ContainsKey(id)) { ZObject obj = objects[id]; foreach (var objRef in kv.Value) { objRef.SetObject(obj); } } else { throw new Exception(); } } }
public Command(ZObject destination, CommandType type) : this(destination, type, null) { }
/// <summary> /// Asserts that the object is of kind "kind" /// </summary> /// <param name="obj">The object</param> /// <param name="kind">It's kind</param> ZObject Kind(ZObject obj, ZObject kind) { // It is a kind ((SparseGraph<ZObject>)relations[__kind]).After(obj, new Edge<ZObject>(kind, null)); return obj; }
bool move(ZObject to, List<object> items, SrcInFile src, Err err) { // Check that we have items that we can move if (null == items || items.Count < 1) { // Didn't specify the items to move // Format an error message err . linkTo(src); err . SB . AppendFormat("What should be moved?"); return false; } // An array to hold the items that we can move var movables = new List<ZObject>(); // Check that the movement is sane foreach (var item in items) { // Check that it is an item that we can move if (!(item is ZObject) || isKind((ZObject)item, cellKind) || isKind((ZObject)item, dirKind)) { // Format an error message err . linkTo(src); err . SB . AppendFormat("That makes no sense.. we can't move that"); return true; } var movable = (ZObject) item; if (movable . Parent == to) { // Format an error message err . linkTo(src); err . SB . AppendFormat("That makes no sense.. that doesn't really move an item anywhere!"); return true; } movables.Add(movable); } // Reparent each of the items now foreach (var item in movables) { item.Parent.RemoveChild(item); to.AddChild(item); } return true; }
// Create a pipepair for bi-directional transfer of messages. // First HWM is for messages passed from first pipe to the second pipe. // Second HWM is for messages passed from second pipe to the first pipe. // Delay specifies how the pipe behaves when the peer terminates. If true // pipe receives all the pending messages before terminating, otherwise it // terminates straight away. public static void Pipepair(ZObject[] parents, Pipe[] pipes, int[] hwms, bool[] delays) { // Creates two pipe objects. These objects are connected by two ypipes, // each to pass messages in one direction. YPipe<Msg> upipe1 = new YPipe<Msg>(Config.MessagePipeGranularity); YPipe<Msg> upipe2 = new YPipe<Msg>(Config.MessagePipeGranularity); pipes [0] = new Pipe(parents [0], upipe1, upipe2, hwms [1], hwms [0], delays [0]); pipes [1] = new Pipe(parents [1], upipe2, upipe1, hwms [0], hwms [1], delays [1]); pipes [0].SetPeer (pipes [1]); pipes [1].SetPeer (pipes [0]); }
/// <summary> /// Creates a new kind /// </summary> /// <param name="name">The name of the kind</param> /// <param name="parentKind">The parent kind (may be null)</param> /// <returns>The new kind</returns> ZObject Kind(string name, ZObject parentKind) { // Create the new object var ret = new ZObject(name); Kind(ret, parentKind); return ret; }
public static void Delete(ZObject obj) { ZObjectPool.Delete(obj); }
/// <summary> /// Create a new Command object for the given destination, type, and optional argument. /// </summary> /// <param name="destination">a ZObject that denotes the destination for this command</param> /// <param name="type">the CommandType of the new command</param> /// <param name="arg">an Object to comprise the argument for the command (optional)</param> public Command( ZObject destination, CommandType type, object arg = null) : this() { Destination = destination; CommandType = type; Arg = arg; }
/// <summary> /// Get the objects, esp root object /// </summary> /// <returns>The root object</returns> internal ZObject Objects(InStory story) { // Go thru an make the ZObjects; var newObjects=new Dictionary<object,object>(); foreach (var item in objects) { var d = (Dictionary<string,object>) item.Value; var n = new ZObject(); object obj; if (d.TryGetValue("shortDescription", out obj)) n.shortDescription = (string) obj; if (d.TryGetValue("nouns", out obj)) n.nouns = (object[]) obj; newObjects[item.Key] = n; } // Go thru and use the internal "special" forms for some objects newObjects[InStory. _instance.name] = InStory. _instance; newObjects[InStory. __kind.name] = InStory. __kind; newObjects[InStory. opposite.name] = InStory. opposite; newObjects[InStory. roomKind.name] = InStory. roomKind; newObjects[InStory. dirKind.name] = InStory. dirKind; newObjects[InStory. cellKind.name] = InStory. cellKind; newObjects[InStory.personKind.name] = InStory.personKind; objects = newObjects; // Go thru and replace references out special one replace(story.east); replace(story.west); replace(story.north); replace(story.south); // Link the table back together // Link each parent to child foreach (var I in children) { var obj = newObjects[I[0]]; var L = I. Length; for (int J = 1; J < L; J++) ((ZObject)obj).AddChild((ZObject) objects[I[J]]); } // And return the root object return (ZObject) objects[rootObject]; }
/// <summary> /// Checks to see if the gate if open or not /// </summary> /// <param name="gate"></param> /// <returns></returns> bool isOpen(ZObject gate) { return true; }
/// <summary> /// Add the given object to the tables. /// This is done before deserialization /// </summary> /// <param name="obj"></param> void add(ZObject obj) { if (null == obj) return; // Skip the object if we already have it if (objects . ContainsKey(obj.name)) return; // Add it to the table of objects objects [obj.name] = obj; // Add it's parent if (null != obj.Parent) add(obj.Parent); // Add each of it's children var zobj = (ZObject) obj; // Get the number of children var L = zobj.NumChildren; if (L > 0) { // Create an array for the object var C = new object[L+1]; // The head of the list is parent object C[0] = zobj.name; // Add each of the children for (int I = 0; I < L; I++) { var child = zobj.Children[I]; // Add it to the table of objects first add(child); // Add it to the parent/child relationship C[I+1]= child.name; } // Add this to the table of parent/children relationships children.Add(C); } }
/// <summary> /// Replace items similarly named to x with x /// </summary> /// <param name="x"></param> void replace(ZObject x) { object it = null; // Scan (this can be slow) foreach (var item in objects) { var y = (ZObject) item.Value; if (x.nouns.Equals(y.nouns) && ((x.modifiers == null && y.modifiers == null) || (x.modifiers != null && x.modifiers.Equals(y.modifiers)))) { it = item.Key; break; } } // Replace the item, if it was found if (null != it) objects[it] = x; }
/// <summary> /// Create the relations /// </summary> void initRelations() { // This tracks which entities are "concrete" instances rather than abstract kinds relations[_instance] = new Dictionary<ZObject, ZObject>(); addRelation2(__kind); addRelation2(opposite); // Define the directions east = Direction(eastWords); west = Direction(westWords); north = Direction(northWords); south = Direction(southWords); ((SparseGraph<ZObject>)relations[opposite]).After(east, new Edge<ZObject>(west, null)); ((SparseGraph<ZObject>)relations[opposite]).After(west, new Edge<ZObject>(east, null)); ((SparseGraph<ZObject>)relations[opposite]).After(north, new Edge<ZObject>(south, null)); ((SparseGraph<ZObject>)relations[opposite]).After(south, new Edge<ZObject>(north, null)); // Define the relations for each direction addRelation2(east); addRelation2(west); addRelation2(north); addRelation2(south); }
/// <summary> /// Create a new Command object for the given destination, type, and optional argument. /// </summary> /// <param name="destination">a ZObject that denotes the destination for this command</param> /// <param name="type">the CommandType of the new command</param> /// <param name="arg">an Object to comprise the argument for the command (optional)</param> public Command(ZObject destination, CommandType type, object arg = null) : this() { Destination = destination; CommandType = type; Arg = arg; }
/// <summary> /// Finds the object that best matches the phrase /// </summary> /// <param name="lexer">The text being matched</param> /// <param name="score">The score for the best match: 0 if no match[out]</param> /// <param name="numWordsMatch">The number of words that match [out]</param> /// <param name="bestMatch">The object that best matches [out]</param> /// <param name="seen">Set of objects already examined</param> void matchInContext(ZObject addressedTo, Lexer lexer, ref double score, ref int numWordsMatch, ref object bestMatch, ref LexState lexerState, Dictionary<object,object> seen) { // Make a note of where we are in the text var state = lexer.Save(); // Search for the best item within the addressedTo object and it's children addressedTo.match(lexer, ref score, ref numWordsMatch, ref bestMatch, ref lexerState, seen); // Check to see if it a reference to the other party of a relationship // a. Make a list of objects; eg connected to this via relationship/2 // i. If the link has a gatekeeper, see if the gate is open or closed // b. See which matches best the noun phrases //TODO: Bump the score to keep things closer to ourselves ? // Scan in each of the directions // We can't traverse the edge though foreach (var pair in relations) { // Go back to the saved point in the text lexer.Restore(state); // Match the relation/direction pair.Key.match(lexer, ref score, ref numWordsMatch, ref bestMatch, ref lexerState, seen); if (!(pair.Value is SparseGraph<ZObject>)) continue; // Get the edge.. if none, then nothing can match List<Edge<ZObject>> edges; if (!((SparseGraph<ZObject>)pair.Value).successors(addressedTo, out edges) || edges.Count < 1) { // There is no specific destination here for this location; // the player could have given an abstract direction without a // concrete direciton. We'll keep the direction as a match, // if it did match. continue; } // If the direction matched, we will keep the edge as it's referrant if (bestMatch == pair.Key) { // We match the direction, so we are referring to the edge bestMatch = edges[0]; } // Go back to the saved point in the text lexer.Restore(state); // Match the room or gating door // Search for the best item within the addressedTo object and it's // children match(edges[0], lexer, ref score, ref numWordsMatch, ref bestMatch, ref lexerState, seen); } // Go back to the saved point in the text lexer.Restore(state); // bump the search to parents and their children if (null != addressedTo.Parent) { //TODO: Bump the score to keep things closer to ourselves ? matchInContext(addressedTo.Parent, lexer, ref score, ref numWordsMatch, ref bestMatch, ref lexerState, seen); } }
/// <summary> /// Gets the objects referred to by each of the noun phrases /// </summary> /// <param name="lexer">The lexer that provides the input</param> /// <param name="addressedTo"></param> /// <param name="err"></param> /// <returns></returns> List<object> getNounPhrases(Lexer lexer, ZObject addressedTo, Err err) { // The list of referred to objects var ret = new List<object>(); lexer.Preprocess(); // Map the rest of the words to nouns while (!lexer.EOF) { int matchLength = 0; LexState lexerState = null; // Match the next noun phrase var t = matchInContext(addressedTo, lexer, out matchLength, ref lexerState); // 5. if no noun was mapped if (null == t) { // Try the main relations (isa) // error could not understand at index err . SB . AppendFormat("The phrase \"{0}\" isn't understood.", lexer.ToEndOfLine().Trim()); return null; } // Save the noun phrase ret.Add(t); // Move past the words in that subphrase if (null != lexerState) lexer.Restore(lexerState); lexer.Preprocess(); } return ret; // couldNotUnderstand(string, startingAt); // isAmbiguous(words); }
/// <summary> /// Creates the underlying structures for the relation /// </summary> /// <param name="name">The relation to create</param> void addRelation2(ZObject name) { if (!relations.ContainsKey(name)) relations[ name] = new SparseGraph<ZObject>(true); }
public Command(ZObject destination, CommandType type, Object arg) { this.Destination = destination; this.CommandType = type; this.Arg = arg; }
/// <summary> /// Adds the pair to the relation /// </summary> /// <param name="relationName"></param> /// <param name="a"></param> /// <param name="b"></param> void add(WordList relationName, ZObject a, ZObject b) { relation2Add[relationName](a,b); }
/// <summary> /// Checks to see if this node is descended from the given node /// </summary> /// <param name="Ancestor">A possible parent, grandparent, etc. node</param> /// <returns>true if this node is a descendent of the ancestor</returns> internal bool isDescendentOf(ZObject Ancestor) { if (Parent == Ancestor) return true; return null != Parent && Parent . isDescendentOf(Ancestor); }