Ejemplo n.º 1
0
 /// <summary>
 /// Returns the object group with the given name.
 /// </summary>
 /// <param name="name">The name of the object group to find.</param>
 /// <returns>The object group with the given name.</returns>
 public ObjectGroup GetObjectGroup(string name)
 {
     try
     {
         return(ObjectGroups.Find(item => item.Name == name));
     }
     catch
     {
         throw new Exception("\nCould not find the given ObjectGroup.");
     }
 }
Ejemplo n.º 2
0
        public TmxMap(string filename)
            : this()
        {
            XDocument xDoc = ReadXml(filename);
            var       xMap = xDoc.Element("map");

            if (xMap == null)
            {
                throw new ArgumentOutOfRangeException("filename", "The given file is ether invalid xml or dos not contain a map element");
            }

            Version     = (string)xMap.Attribute("version");
            Orientation = (EOrientationType)Enum.Parse(typeof(EOrientationType), xMap.Attribute("orientation").Value, true);
            Width       = (int)xMap.Attribute("width");
            Height      = (int)xMap.Attribute("height");
            TileWidth   = (int)xMap.Attribute("tilewidth");
            TileHeight  = (int)xMap.Attribute("tileheight");

            var xBackgroundColor = (string)xMap.Attribute("backgroundcolor");

            if (xBackgroundColor != null)
            {
                xBackgroundColor = xBackgroundColor.TrimStart("#".ToCharArray());
                BackgroundColor  = UInt32.Parse(xBackgroundColor, NumberStyles.HexNumber);
            }

            foreach (var e in xMap.Elements("tileset"))
            {
                Tilesets.Add(new TmxTileset(e, TmxDirectory));
            }

            foreach (var e in xMap.Elements("layer"))
            {
                Layers.Add(new TmxLayer(this, e, Width, Height));
            }

            foreach (var e in xMap.Elements("objectgroup"))
            {
                ObjectGroups.Add(new TmxObjectGroup(e));
            }

            foreach (var e in xMap.Elements("imagelayer"))
            {
                ImageLayers.Add(new TmxImageLayer(this, e, TmxDirectory));
            }

            Properties.AddRange(xMap.Element("properties"));
        }
Ejemplo n.º 3
0
        void ParseObjectGroupElement()
        {
            var objectGroup = new CCTileMapObjectGroup();

            objectGroup.GroupName = currentAttributeDict[ObjectGrpElementName];

            CCPoint positionOffset = CCPoint.Zero;

            if (currentAttributeDict.ContainsKey(ObjectGrpElementXOffset))
            {
                positionOffset.X = CCUtils.CCParseFloat(currentAttributeDict[ObjectGrpElementXOffset]) * TileTexelSize.Width;
            }
            if (currentAttributeDict.ContainsKey(ObjectGrpElementYOffset))
            {
                positionOffset.Y = CCUtils.CCParseFloat(currentAttributeDict[ObjectGrpElementYOffset]) * TileTexelSize.Height;
            }
            objectGroup.PositionOffset = positionOffset;

            ObjectGroups.Add(objectGroup);

            currentParentElement = CCTileMapProperty.ObjectGroup;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// gets the TmxObjectGroup with the given name
 /// </summary>
 /// <returns>The object group.</returns>
 /// <param name="name">Name.</param>
 public TmxObjectGroup GetObjectGroup(string name) => ObjectGroups.Contains(name) ? ObjectGroups[name] : null;
        public List <UUID> ReturnObjects(UGUI returningAgent, List <UUID> objectids)
        {
            var returned = new List <UUID>();

            foreach (UUID objectid in objectids)
            {
                ObjectGroup grp;
                if (!ObjectGroups.TryGetValue(objectid, out grp))
                {
                    if (!CanReturn(returningAgent, grp, grp.Position))
                    {
                        continue;
                    }

                    var  copyItems = new Dictionary <UGUI, List <InventoryItem> >();
                    UUID assetID;
                    bool changePermissions = false;
                    UGUI targetAgent       = grp.Owner;

                    assetID = grp.OriginalAssetID;
                    if (UUID.Zero == assetID)
                    {
                        AssetData asset = grp.Asset(XmlSerializationOptions.WriteOwnerInfo | XmlSerializationOptions.WriteXml2);
                        asset.ID = UUID.Random;
                        AssetService.Store(asset);
                        grp.OriginalAssetID = asset.ID;
                        assetID             = asset.ID;
                    }
                    if (!copyItems.ContainsKey(targetAgent))
                    {
                        copyItems.Add(targetAgent, new List <InventoryItem>());
                    }
                    var newitem = new InventoryItem
                    {
                        AssetID       = assetID,
                        AssetType     = AssetType.Object,
                        InventoryType = InventoryType.Object,
                        Name          = grp.Name,
                        Description   = grp.Description,
                        LastOwner     = grp.Owner,
                        Owner         = targetAgent,
                        Creator       = grp.RootPart.Creator,
                        CreationDate  = grp.RootPart.CreationDate
                    };
                    newitem.Permissions.Base      = changePermissions ? grp.RootPart.NextOwnerMask : grp.RootPart.BaseMask;
                    newitem.Permissions.Current   = newitem.Permissions.Base;
                    newitem.Permissions.Group     = InventoryPermissionsMask.None;
                    newitem.Permissions.NextOwner = grp.RootPart.NextOwnerMask;
                    newitem.Permissions.EveryOne  = InventoryPermissionsMask.None;
                    copyItems[grp.Owner].Add(newitem);

                    foreach (KeyValuePair <UGUI, List <InventoryItem> > kvp in copyItems)
                    {
                        var    assetIDs = new List <UUID>();
                        IAgent toAgent;
                        foreach (InventoryItem item in kvp.Value)
                        {
                            if (!assetIDs.Contains(item.AssetID))
                            {
                                assetIDs.Add(item.AssetID);
                            }
                        }
                        if (Agents.TryGetValue(kvp.Key.ID, out toAgent))
                        {
                            new ObjectTransferItem(toAgent,
                                                   this,
                                                   assetIDs,
                                                   kvp.Value,
                                                   AssetType.LostAndFoundFolder).QueueWorkItem();
                        }
                        else
                        {
                            InventoryServiceInterface agentInventoryService;
                            AssetServiceInterface     agentAssetService;
                            if (TryGetServices(kvp.Key, out agentInventoryService, out agentAssetService))
                            {
                                new ObjectTransferItem(agentInventoryService,
                                                       agentAssetService,
                                                       kvp.Key,
                                                       this,
                                                       assetIDs,
                                                       kvp.Value,
                                                       AssetType.LostAndFoundFolder).QueueWorkItem();
                            }
                        }
                    }

                    grp.Scene.Remove(grp);
                    returned.Add(objectid);
                }
            }

            return(returned);
        }