private void CreateInstalledItemWork(List <Tile> tiles, string localBuild)
        {
            foreach (Tile tile in tiles)
            {
                //tile.placeInstalledObject();
                string localRecipe = InstalledItem.GetRecipeName(localBuild);
                if (World.current.isInstalledItemPositionValid(World.current, build, tile))
                {
                    WorkItem work = WorkItem.MakeWorkItem(tile, "SetInstalledItem", localBuild);
                }
                //  Job j = Job.MakeStandardJob(
                //        tile,
                //        //OnInstalledItemJobComplete, //(theJob) => { OnInstalledItemJobComplete(localBuild, theJob.tile); },
                //        //OnInstalledItemJobCancelled,
                //        JOB_TYPE.BUILD,
                //        1,
                //        localBuild
                //      );
                //  tile.AddJob(j);
                //  j.cbLuaRegisterJobComplete("OnInstalledItemJobComplete");
                //  j.cbLuaRegisterJobCancelled("OnInstalledItemJobCancelled");
                //  World.current.jobQueue.Push(j);

                //  //tile.pendingJob = true;
                //  //Debug.Log("jobs in queue: " +world.jobQueue.Count);

                //}
            }
        }
示例#2
0
        public InstalledModViewModel(InstalledItem installedItem, ProfileItem profileItem)
        {
            InstallInfo   = installedItem;
            ActiveModInfo = profileItem;

            Name        = InstallInfo.CachedDetails.Name;
            Author      = InstallInfo.CachedDetails.Author;
            Version     = InstallInfo.CachedDetails.LatestVersion.Version.ToString();
            ReleaseDate = InstallInfo.CachedDetails.LatestVersion.ReleaseDate.ToString(Sys.Settings.DateTimeStringFormat);

            SortOrder = defaultSortOrder;

            // check active profile for custom category then default to library installed item
            _category = profileItem.Category;
            if (string.IsNullOrWhiteSpace(_category))
            {
                _category = InstallInfo.CachedDetails.Category;
            }

            if (string.IsNullOrWhiteSpace(_category))
            {
                Category = ModCategory.Unknown.ToString();
            }

            BorderThickness = new Thickness(0);
        }
示例#3
0
        public bool placeInstalledItem(InstalledItem instobj)
        {
            if (instobj == null)
            {
                this.installedItem = null;
                return(true);
            }
            if (this.installedItem == null)
            {
                this.installedItem = instobj;
                for (int xx = world_x; xx < world_x + instobj.width; xx += 1)
                {
                    for (int yy = world_y; yy < world_y + instobj.height; yy += 1)
                    {
                        Tile t = world.GetTileAt(xx, yy);
                        t.ForceInstalledItem(instobj);
                    }
                }


                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#4
0
    private Button MakeButton(InstalledItem proto)
    {
        Button btn = MakeButton("btnBuild::" + proto.type, proto.niceName, proto.spriteName + NYDISpriteManager.ICON_SUFFIX);

        btn.onClick.AddListener(delegate { WorldController.Instance.SetBuildType_InstalledItem(proto.type); });

        return(btn);
    }
示例#5
0
 void OnInstalledItemDestroyed(InstalledItem item)
 {
     if (InstalledItems_GO_Map.ContainsKey(item))
     {
         GameObject instgo = InstalledItems_GO_Map[item];
         Destroy(instgo);
         InstalledItems_GO_Map.Remove(item);
     }
 }
示例#6
0
        //public GameObject GetGameObjectFromTile(Tile t) {
        //  if (Tiles_GO_Map.ContainsKey(t)) {
        //    return Tiles_GO_Map[t];
        //  } else {
        //    return null;
        //  }
        //}

        public GameObject GetGameObjectFromInstalledItem(InstalledItem item)
        {
            if (InstalledItems_GO_Map.ContainsKey(item))
            {
                return(InstalledItems_GO_Map[item]);
            }
            else
            {
                return(null);
            }
        }
 private bool hasMatchingNeighbour(Tile t, InstalledItem item)
 {
     if (t == null || t.installedItem == null || !item.neighbourTypes.Contains(t.installedItem.type))
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
示例#8
0
        public void OnInstalledItemCreated(InstalledItem inst)
        {
            //create a visible game object

            if (InstalledItems_GO_Map.ContainsKey(inst))
            {
                return;
            }
            GameObject go = CreateGameObject(inst.type + "_" + inst.tile.world_x + "_" + inst.tile.world_y, inst.tile.world_x, inst.tile.world_y);

            InstalledItems_GO_Map.Add(inst, go);
            SpriteRenderer spr = go.GetComponent <SpriteRenderer>();
            float          xt = 0, yt = 0;

            if (inst.width > 1)
            {
                xt = ((float)(inst.width) / 2.0f) - 0.5f;
            }

            if (inst.height > 1)
            {
                yt = ((float)(inst.height) / 2.0f) - 0.5f;
            }
            spr.transform.Translate(xt, yt, 0);

            SpriteHolder sh = spriteController.GetSprite(inst);

            if (inst.type == "installed::door")
            {
                spriteController.GetDoorSprite(inst, sh);
            }
            if (sh.r != 0)
            {
                spr.transform.Rotate(0, 0, sh.r);
            }
            //Debug.Log(sh.s + " @ r:" + sh.r);

            spr.sprite        = sh.s; // sprites[inst.spriteName];
            spr.sortingOrder += 1;
            go.transform.SetParent(this.transform, true);
            spr.sortingLayerName = "Objects";

            //world.RegisterInstalledItemCB(inst);
            inst.CBRegisterChanged(OnInstalledItemChanged);
            inst.CBRegisterDestroyed(OnInstalledItemDestroyed);
        }
示例#9
0
        void OnInstalledItemChanged(InstalledItem item)
        {
            //Debug.LogError("OnInstalledItemChanged " + item + " NOT IMPLEMENTED");

            if (InstalledItems_GO_Map.ContainsKey(item))
            {
                GameObject     go  = InstalledItems_GO_Map[item];
                SpriteRenderer spr = go.GetComponent <SpriteRenderer>();

                SpriteHolder sh = spriteController.GetSprite(item);
                if (item.type == "installed::door")
                {
                    spriteController.GetDoorSprite(item, sh);
                }

                spr.sprite             = sh.s;
                spr.transform.rotation = Quaternion.identity;
                spr.transform.Rotate(0, 0, sh.r);
            }
        }
        //public Sprite GetSprite(Character c) {
        //  return GetSprite(c.spriteName);
        //}

        public SpriteHolder GetDoorSprite(InstalledItem door, SpriteHolder sh)
        {
            float openness = door.itemParameters.GetFloat("openness");

            int index = (int)(openness / (1.0f / 7.0f));

            sh.s = GetSprite("installed_items::door_" + index);
            //if (openness > 0.75) {
            //  sh.s = GetSprite("installed_door_25");
            //} else if (openness > 0.5 && openness <= 0.75) {
            //  sh.s = GetSprite("installed_door_50");
            //} else if (openness > 0.1 && openness <= 0.5) {
            //  sh.s = GetSprite("installed_door_75");
            //} else {

            //}


            return(sh);
        }
        // Update is called once per frame
        void Update()
        {
            if (WorldController.Instance.buildController.buildMode == BuildController.BUILD_MODE.INSTALLEDITEM)
            {
                string installedItemName = WorldController.Instance.buildController.build;
                if (goBuildTemplate == null)
                {
                    goBuildTemplate = Instantiate(WorldController.Instance.genericSpritePrefab, Vector2.zero, Quaternion.identity);
                    goBuildTemplate.SetActive(false);
                    SpriteRenderer spr = goBuildTemplate.GetComponent <SpriteRenderer>();
                    spr.color = whiteTransparent;
                }

                Tile t = WorldController.Instance.inputController.mouseOverTile;
                if (t != null)
                {
                    InstalledItem proto = InstalledItem.prototypes[installedItemName];

                    goBuildTemplate.SetActive(true);
                    SpriteRenderer spr = goBuildTemplate.GetComponent <SpriteRenderer>();
                    spr.sprite             = WorldController.Instance.spriteController.GetSprite(proto.spriteName);
                    spr.transform.position = Vector2.zero;
                    spr.color = whiteTransparent;
                    if (!proto.funcPositionValid(World.current, t.world_x, t.world_y))
                    {
                        spr.color = redTransparent;
                    }

                    goBuildTemplate.transform.position = Vector2.zero;
                    goBuildTemplate.transform.Translate(t.world_x, t.world_y, 0);
                    spr.transform.Translate(Funcs.GetInstalledItemSpriteOffset(proto.width, proto.height));
                }
            }
            else if (goBuildTemplate != null)
            {
                goBuildTemplate.SetActive(false);
            }
        }
示例#12
0
        //public InventoryItem RemoveInventoryItem(int qty) {

        //  if ()
        //  return null;

        //}


        //private void OnInventoryItemPlaced(Tile t) {

        //}



        //public bool PlaceInventoryItem(InventoryItem inv) {

        //  if (inv == null) {
        //    Debug.LogError("cannot place null inventory item");

        //    return false;
        //  }

        //  if (inventoryItem != null) {
        //    //something here already... combine?
        //    if (inv.type == inventoryItem.type) {
        //      if (inventoryItem.currentStack + inv.currentStack > inv.maxStackSize) {
        //        inv.currentStack -= inv.maxStackSize - inventoryItem.currentStack;
        //        inventoryItem.currentStack = inventoryItem.maxStackSize;
        //      } else {
        //        inventoryItem.currentStack += inv.currentStack;
        //        inv.currentStack = 0;

        //      }
        //      if (cbInventoryItemChanged != null) {
        //        cbInventoryItemChanged(this);
        //      }
        //      return true;
        //    } else {
        //      Debug.LogError("cannot add " + inv.type + " to a stack of " + inventoryItem.type);

        //    }
        //  } else {
        //    inventoryItem = inv.Copy();
        //    inv.currentStack = 0;
        //    inventoryItem.SetTile(this);
        //    if (cbInventoryItemChanged != null) {
        //      cbInventoryItemChanged(this);
        //    }
        //    return true;
        //  }

        //  return false;
        //}

        public void ForceInstalledItem(InstalledItem item)
        {
            this.installedItem = item;
        }
示例#13
0
        public void Import(string source, string name, bool iroMode, bool noCopy)
        {
            Mod m = ParseModXmlFromSource(source); // this will increment the progress changed value up to 50%

            if (string.IsNullOrWhiteSpace(m.Name))
            {
                m.Name = name;
            }

            // validate mod with same ID doesn't exist in library
            // ... if it already exists then check if it's newer version to update to
            InstalledItem existingItem = Sys.Library.GetItem(m.ID);

            if (existingItem != null)
            {
                if (existingItem.LatestInstalled.VersionDetails.Version >= m.LatestVersion.Version)
                {
                    throw new DuplicateModException($"A mod ({existingItem.CachedDetails.Name} v{existingItem.LatestInstalled.VersionDetails.Version}) with the same ID already exists in your library.");
                }
                else
                {
                    // mod is being updated so uninstall current version
                    Install.Uninstall(existingItem);
                    Sys.ActiveProfile.RemoveDeletedItems();
                }
            }


            string copyLocation;

            if (noCopy)
            {
                copyLocation = Path.GetFileName(source);
            }
            else
            {
                copyLocation = String.Format("{0}_{1}", m.ID, name);
            }

            if (!iroMode)
            {
                if (!noCopy)
                {
                    int      i        = 1;
                    string[] allFiles = Directory.GetFiles(source, "*", SearchOption.AllDirectories);
                    foreach (string file in allFiles)
                    {
                        string part = file.Substring(source.Length).Trim('\\', '/');
                        string dest = Path.Combine(Sys.Settings.LibraryLocation, copyLocation, part);
                        Directory.CreateDirectory(Path.GetDirectoryName(dest));
                        File.Copy(file, dest, true);

                        double newProgress = 50.0 + (((double)i / allFiles.Length) * 40); // start at 50 and eventually increment to 90 (i.e. 50 + 40 = 90)
                        RaiseProgressChanged($"Copying files from folder {i} / {allFiles.Length}", newProgress);
                        i++;
                    }
                }
            }
            else
            {
                if (!noCopy)
                {
                    RaiseProgressChanged("Copying .iro file to library", 75);
                    copyLocation += ".iro";
                    File.Copy(source, Path.Combine(Sys.Settings.LibraryLocation, copyLocation), true);
                }
            }

            RaiseProgressChanged("Finalizing import", 95);

            Sys.Library.AddInstall(new InstalledItem()
            {
                CachedDetails = m,
                CachePreview  = String.Empty,
                ModID         = m.ID,
                UpdateType    = Sys.Library.DefaultUpdate,
                Versions      = new List <InstalledVersion>()
                {
                    new InstalledVersion()
                    {
                        VersionDetails = m.LatestVersion, InstalledLocation = copyLocation
                    }
                },
            });

            Sys.ActiveProfile.AddItem(new ProfileItem()
            {
                ModID = m.ID, Name = m.Name, Settings = new List <ProfileSetting>(), IsModActive = false
            });
            RaiseProgressChanged("Import complete", 100);
        }
        public SpriteHolder GetSprite(InstalledItem item)
        {
            SpriteHolder sp = new SpriteHolder();

            if (item.growthStage >= 0)
            {
                Growth g = item.growthStages[item.growthStage];
                sp.s = GetSprite(g.sprite);
            }
            else
            {
                sp.s = GetSprite(item.getRandomSpriteName());
            }



            if (item.randomRotation)
            {
                int r = Random.Range(0, 4);
                sp.r = 90 * r;
            }



            if (item.linksToNeighbour)
            {
                int  x = item.tile.world_x;
                int  y = item.tile.world_y;
                bool northMatches, eastMatches, southMatches, westMatches;
                int  countOfNeighbours = 0;
                //Dictionary<string, Tile> ngbrs = WorldController.Instance.world.GetNeighbours(item);
                Tile north             = item.tile.GetNeighbour(World.NORTH);
                Tile east              = item.tile.GetNeighbour(World.EAST);
                Tile south             = item.tile.GetNeighbour(World.SOUTH);
                Tile west              = item.tile.GetNeighbour(World.WEST);

                northMatches = hasMatchingNeighbour(north, item);
                if (northMatches)
                {
                    countOfNeighbours += 1;
                }
                eastMatches = hasMatchingNeighbour(east, item);
                if (eastMatches)
                {
                    countOfNeighbours += 1;
                }
                southMatches = hasMatchingNeighbour(south, item);
                if (southMatches)
                {
                    countOfNeighbours += 1;
                }
                westMatches = hasMatchingNeighbour(west, item);
                if (westMatches)
                {
                    countOfNeighbours += 1;
                }

                switch (countOfNeighbours)
                {
                case 0:

                    break;

                case 1:
                    sp.s = GetSprite(item.sprite_s);
                    if (northMatches)
                    {
                        sp.r = 180;
                    }
                    else if (eastMatches)
                    {
                        sp.r = 90;
                    }
                    else if (westMatches)
                    {
                        sp.r = -90;
                    }
                    break;

                case 2:
                    sp.s = GetSprite(item.sprite_ns);
                    if (eastMatches && westMatches)
                    {
                        sp.r = 90;
                    }
                    else if (northMatches && southMatches)
                    {
                        sp.r = 0;
                    }
                    else
                    {
                        sp.s = GetSprite(item.sprite_sw);
                        if (southMatches && westMatches)
                        {
                        }
                        else if (northMatches && eastMatches)
                        {
                            sp.r = -180;
                        }
                        else if (northMatches && westMatches)
                        {
                            sp.r = -90;
                        }
                        else if (eastMatches && southMatches)
                        {
                            sp.r = 90;
                        }
                    }
                    break;

                case 3:
                    sp.s = GetSprite(item.sprite_nsw);

                    if (northMatches && southMatches && westMatches)
                    {
                    }
                    else if (northMatches && eastMatches && westMatches)
                    {
                        sp.r = -90;
                    }
                    else if (eastMatches && southMatches && westMatches)
                    {
                        sp.r = 90;
                    }
                    else if (northMatches && eastMatches && southMatches)
                    {
                        sp.r = 180;
                    }

                    break;

                case 4:
                    sp.s = GetSprite(item.sprite_nesw);
                    break;
                }
            }
            else
            {
            }
            return(sp);
        }
示例#15
0
        public void UpdateCurrentTile(SelectionInfo info)
        {
            Text   txt = currentTileText.GetComponent <Text>();
            Tile   t   = info.tile;
            object o   = info.contents[info.subSelect];

            int pw = 38;

            string displayMe = "";


            displayMe += Funcs.PadPair(pw, "chunk x", t.chunk.x.ToString(), '.');
            displayMe += "\n" + Funcs.PadPair(pw, "chunk y", t.chunk.y.ToString(), '.');
            displayMe += "\n" + Funcs.PadPair(pw, "world x", t.world_x.ToString(), '.');
            displayMe += "\n" + Funcs.PadPair(pw, "world y", t.world_y.ToString(), '.');



            displayMe += "\n";
            if (o.GetType() == typeof(Tile))
            {
                Tile tile = (Tile)o;
                displayMe += Funcs.PadPair(pw, "tile type", tile.type.name, '.');

                displayMe += "\n" + tile.JobsToString(pw);
            }
            else if (o.GetType() == typeof(Entity))
            {
                Entity to = (Entity)o;
                displayMe += Funcs.PadPair(pw, "type", to.typeName);
                displayMe += "\n" + Funcs.PadPair(pw, "name", to.name);
                displayMe += "\n" + Funcs.PadPair(pw, "state", to.state);

                //if (to.animator.valid) {
                //  displayMe += "\n" + Funcs.PadPair(pw, "animation", to.animator.currentAnimation.name);
                //  displayMe += "\n" + Funcs.PadPair(pw, "running", to.animator.running.ToString());
                //  //displayMe += "\n" + Funcs.PadPair(pw, "timer", to.animator.timer.ToString());
                //  //displayMe += "\n" + Funcs.PadPair(pw, "index", to.animator.index.ToString());
                //}
            }
            else if (o.GetType() == typeof(InstalledItem))
            {
                InstalledItem item = (InstalledItem)o;
                displayMe += Funcs.PadPair(pw, "installed item", item.niceName, '.');

                if (item.itemParameters.HasProperty("socialMediaName"))
                {
                    displayMe += "\n" + Funcs.PadPair(pw, "social media", item.itemParameters.GetString("socialMediaName"), '.');
                }

                if (item.editOnClick)
                {
                    this.prfInstalledItemOptionsInScene.GetComponent <prfInstalledItemScript>().Set(item);
                }
            }
            else if (o.GetType() == typeof(string))
            {
                string invname = t.GetFirstInventoryItem();
                if (invname != null)
                {
                    string nicename = InventoryItem.GetPrototype(invname).niceName;
                    displayMe += Funcs.PadPair(pw, nicename, t.InventoryTotal(invname).ToString());
                    displayMe += "\n" + Funcs.PadPair(pw, "allocated", t.InventoryTotalAllocated(invname).ToString());
                }
                //displayMe += InventoryItem.GetPrototype(t.GetFirstInventoryItem()).niceName + ": " + t.InventoryTotal(((string)o));
            }
            //displayMe += "\nNeighbours:" + t.neighbours.Count + ", " + t.edges.Count;
            //displayMe += "\nRoom:" + t.room.id;
            //displayMe += "\nInstalled:" + (t.installedItem == null ? "" : t.installedItem.niceName);
            //displayMe += "\nJobs: " + t.JobsToString();
            //displayMe += "\nItems:" + t.GetContents();//(t.inventoryItem == null ? "" : t.inventoryItem.niceName + " " + t.inventoryItem.currentStack + "/" + t.inventoryItem.maxStackSize);
            //displayMe += "\n" + t.WhoIsHere();



            txt.text = displayMe;
        }
        public void Init()
        {
            Rect    rect  = new Rect(0, 0, CHUNK_WIDTH * 32, CHUNK_HEIGHT * 32);
            Vector2 pivot = new Vector2(0, 0);

            texture            = new Texture2D(CHUNK_WIDTH * 32, CHUNK_HEIGHT * 32, NYDISpriteManager.DEFAULT_TEXTURE_FORMAT, false);
            texture.filterMode = FilterMode.Point;

            sprite      = Sprite.Create(texture, rect, pivot, 32);
            sprite.name = "sprite::chunk_" + x + "_" + y;

            for (int xx = 0; xx < CHUNK_WIDTH; xx += 1)
            {
                for (int yy = 0; yy < CHUNK_HEIGHT; yy += 1)
                {
                    Tile t = new Tile(world, this, TileType.TYPES["empty"], xx, yy);
                    tiles[xx, yy] = t;
                    t.cbRegisterOnChanged(OnTileChanged);
                    t.cbRegisterOnChanged(world.OnTileChanged);
                    t.cbRegisterOnItemChanged(world.OnInventoryItemChangedOnTile);
                    t.cbRegisterOnItemChanged(OnInventoryItemChangedOnTile);
                    //tiles[x, y].room = rooms[0];
                    world.outside.AssignTile(t);

                    //float xf = ((float)t.world_x + world.xSeed) * world.noiseFactor;
                    //float yf = ((float)t.world_y + world.ySeed) * world.noiseFactor;
                    RMTile rm = World.current.citymap.GetTile(t.world_x, t.world_y);
                    int    n  = rm.h;
                    //float n2 = World.current.SimplexNoise(((float)t.world_x), ((float)t.world_y),World.current.oreZ);
                    //float n = (n1 + n2) / 2;
                    //int j = Mathf.FloorToInt(n * (float)TileType.countNatural);

                    if (rm.showsAs == TYPE.BUILDING)
                    {
                        t.SetType(TileType.TYPES["concrete"]);
                        if (rm.btype == BUILDING_TYPE.EDGE)
                        {
                            t.SetType(TileType.TYPES["building_edge"]);
                        }
                        else if (rm.btype == BUILDING_TYPE.INSIDE)
                        {
                            t.SetType(TileType.TYPES["building_interior"]);
                        }
                    }
                    else if (rm.showsAs == TYPE.ROAD)
                    {
                        t.SetType(TileType.TYPES["concrete"]);
                    }
                    else if (rm.showsAs == TYPE.WATER)
                    {
                        t.SetType(TileType.TYPES["water"]);
                    }
                    else
                    {
                        foreach (string k in TileType.TYPES.Keys)
                        {
                            TileType tempT = TileType.TYPES[k];



                            if (tempT.name != "empty")
                            {
                                if (n == tempT.heightIndex)
                                {
                                    t.SetType(tempT);

                                    if (tempT.varieties.Count == 0)
                                    {
                                    }
                                    else
                                    {
                                        foreach (string variety in tempT.varieties.Keys)
                                        {
                                            TileType vt   = TileType.TYPES[variety];
                                            float    A    = tempT.varieties[variety].Item1;
                                            float    B    = tempT.varieties[variety].Item2;
                                            float    na   = World.current.SimplexNoise(((float)t.world_x), ((float)t.world_y), A);
                                            float    nb   = World.current.SimplexNoise(((float)t.world_x), ((float)t.world_y), B);
                                            float    navg = (na + nb) / 2f;
                                            if ((navg >= 0.95f && navg <= 1f) || (navg >= 0.05f && navg <= 0.1f))
                                            {
                                                t.SetType(vt);
                                                break;
                                            }
                                        }
                                    }



                                    break;
                                }
                            }
                        }
                    }
                }
            }

            for (int xx = 0; xx < CHUNK_WIDTH; xx += 1)
            {
                for (int yy = 0; yy < CHUNK_HEIGHT; yy += 1)
                {
                    tiles[xx, yy].SetNeighbours(true);

                    Tile t = tiles[xx, yy];
                    if (t.type.name != "empty" && t.type.name != "water")
                    {
                        if (Funcs.Chance100(1))
                        {
                            if (InstalledItem.trashPrototypes.Count > 0)
                            {
                                string        trashItemName = InstalledItem.GetRandomTrashItemName();
                                InstalledItem proto         = InstalledItem.GetPrototype(trashItemName);

                                if (proto != null)
                                {
                                    if (proto.canSpawnOnTileTypeList.Count > 0)
                                    {
                                        if (!proto.canSpawnOnTileTypeList.Contains(t.type.name))
                                        {
                                            continue;
                                        }
                                    }

                                    //Debug.Log("I will spawn a " + (trashItemName == null ? "null" : trashItemName));
                                    world.PlaceInstalledItem(trashItemName, t, true);
                                }
                            }
                        }
                        else if (Funcs.fChance(0.08f))
                        {
                            InventoryItem item = InventoryItem.GetRandomSpawnItem();
                            if (item != null)
                            {
                                string type = item.type;
                                int    qty  = UnityEngine.Random.Range(1, InventoryItem.GetStackSize(type) + 1);
                                if (Funcs.fChance(item.spawnsOnChunkGenchance * 100))
                                {
                                    world.PlaceTileInventoryItem(type, t, qty);
                                }
                            }
                        }
                        else if (Funcs.fChance(0.05f))
                        {
                            World.current.CreateEntityAtTile(t, "entities::chicken");
                        }
                    }
                }
            }
            SetNeighbourChunks();
        }
示例#17
0
        /// <summary>
        /// Imports and applies patch file to installed mod.
        /// </summary>
        /// <param name="sourcePatchFile"> absolute path to .irop file</param>
        /// <returns> true if applied patch. </returns>
        public bool ImportModPatch(string sourcePatchFile)
        {
            XmlDocument doc = null;

            if (!File.Exists(sourcePatchFile))
            {
                RaiseProgressChanged($"Patch file does not exist at {sourcePatchFile}", 0);
                return(false);
            }

            // check for mod.xml in .irop file and load xml to get mod id
            RaiseProgressChanged($"Getting mod info from .irop file", 25);
            using (var patch = new IrosArc(sourcePatchFile))
            {
                if (!patch.HasFile("mod.xml"))
                {
                    RaiseProgressChanged($"Failed to apply patch due to missing mod.xml file in .irop patch", 0);
                    return(false); // no mod.xml found in patch
                }

                doc = new XmlDocument();
                doc.Load(patch.GetData("mod.xml"));
            }

            if (doc == null)
            {
                RaiseProgressChanged($"Failed to load mod.xml file from patch", 0);
                return(false);
            }


            Mod parsedMod = new Mod();

            if (!TryParseIDFromXmlDoc(parsedMod, doc))
            {
                RaiseProgressChanged($"Failed to apply patch due to Mod ID is missing from mod.xml in patch", 0);
                return(false);
            }

            if (!TryParseVersionFromXmlDoc(parsedMod, doc))
            {
                RaiseProgressChanged($"Failed to apply patch due to Mod Version is missing from mod.xml in patch", 0);
                return(false);
            }


            // if no mod id or mod not installed then error
            InstalledItem installedMod = Sys.Library.GetItem(parsedMod.ID);

            if (installedMod == null)
            {
                RaiseProgressChanged($"No mod is installed with the ID {parsedMod.ID}", 0);
                return(false); // mod is not installed
            }

            // stop patching if patch is older than already installed version
            if (installedMod.LatestInstalled.VersionDetails.Version >= parsedMod.LatestVersion.Version)
            {
                throw new DuplicateModException($"A mod ({installedMod.CachedDetails.Name} v{installedMod.LatestInstalled.VersionDetails.Version}) with the same ID already exists in your library.");
            }


            // open .iro for patching and apply patch
            RaiseProgressChanged($"Applying patch to '{installedMod.CachedDetails.Name}'", 50);

            string sourceFileName = installedMod.LatestInstalled.InstalledLocation;
            string sourceIro      = Path.Combine(Sys.Settings.LibraryLocation, sourceFileName);

            using (var iro = new IrosArc(sourceIro, true))
            {
                using (var patch = new IrosArc(sourcePatchFile))
                {
                    iro.ApplyPatch(patch, (d, msg) =>
                    {
                        RaiseProgressChanged(msg, 50);
                    });
                }
            }

            // update the cached mod details by re-reading the mod.xml
            RaiseProgressChanged($"Updating cached details of '{installedMod.CachedDetails.Name}'", 75);

            Mod updatedMod = ParseModXmlFromSource(sourceIro, installedMod.CachedDetails);

            installedMod.CachedDetails = updatedMod;
            installedMod.Versions.Clear();
            installedMod.Versions.Add(new InstalledVersion()
            {
                VersionDetails = updatedMod.LatestVersion, InstalledLocation = sourceFileName
            });

            return(true);
        }
示例#18
0
        /// <summary>
        /// Imports a mod from file/folder into the Library
        /// </summary>
        /// <param name="source"> absolute path to .iro or folder to import</param>
        /// <param name="name"> name to give mod </param>
        /// <param name="iroMode"> true if importing .iro </param>
        /// <param name="noCopy"> does not copy the file/folder to the mods Library folder</param>
        /// <returns>Parsed and imported mod</returns>
        public Mod Import(string source, string name, bool iroMode, bool noCopy)
        {
            Mod m = ParseModXmlFromSource(source); // this will increment the progress changed value up to 50%

            if (string.IsNullOrWhiteSpace(m.Name))
            {
                m.Name = name;
            }

            // validate mod with same ID doesn't exist in library
            // ... if it already exists then check if it's newer version to update to
            InstalledItem existingItem = Sys.Library.GetItem(m.ID);

            if (existingItem != null)
            {
                if (existingItem.LatestInstalled.VersionDetails.Version >= m.LatestVersion.Version)
                {
                    throw new DuplicateModException($"A mod ({existingItem.CachedDetails.Name} v{existingItem.LatestInstalled.VersionDetails.Version}) with the same ID already exists in your library.");
                }
                else
                {
                    // mod is being updated so uninstall current versions
                    Sys.Library.DeleteAndRemoveInstall(existingItem, existingItem.Versions
                                                       .Where(v => Path.Combine(Sys.Settings.LibraryLocation, v.InstalledLocation) != source)                           // ensure we are not deleting the mod file we are trying to import (in the case that the new file is already copied to mods library location)
                                                       .Select(v => v.InstalledLocation));
                }
            }


            string destFileName = Path.GetFileName(source);

            if (!noCopy)
            {
                // copy .iro or mod files to library location
                destFileName = String.Format("{0}_{1}", m.ID, name);

                if (iroMode)
                {
                    RaiseProgressChanged("Copying .iro file to library", 75);
                    destFileName += ".iro";
                    File.Copy(source, Path.Combine(Sys.Settings.LibraryLocation, destFileName), true);
                }
                else
                {
                    int      i        = 1;
                    string[] allFiles = Directory.GetFiles(source, "*", SearchOption.AllDirectories);
                    foreach (string file in allFiles)
                    {
                        string part = file.Substring(source.Length).Trim('\\', '/');
                        string absoluteDestinationPath = Path.Combine(Sys.Settings.LibraryLocation, destFileName, part);

                        Directory.CreateDirectory(Path.GetDirectoryName(absoluteDestinationPath));
                        File.Copy(file, absoluteDestinationPath, true);

                        double newProgress = 50.0 + (((double)i / allFiles.Length) * 40); // start at 50 and eventually increment to 90 (i.e. 50 + 40 = 90)
                        RaiseProgressChanged($"Copying files from folder {i} / {allFiles.Length}", newProgress);
                        i++;
                    }
                }
            }

            RaiseProgressChanged("Finalizing import", 95);

            Sys.Library.AddInstall(new InstalledItem()
            {
                CachedDetails = m,
                CachePreview  = String.Empty,
                ModID         = m.ID,
                UpdateType    = Sys.Library.DefaultUpdate,
                Versions      = new List <InstalledVersion>()
                {
                    new InstalledVersion()
                    {
                        VersionDetails = m.LatestVersion, InstalledLocation = destFileName
                    }
                },
            });

            if (!Sys.ActiveProfile.HasItem(m.ID))
            {
                Sys.ActiveProfile.AddItem(new Iros._7th.Workshop.ProfileItem()
                {
                    ModID = m.ID, Name = m.Name, Settings = new List <ProfileSetting>(), IsModActive = false
                });
            }

            RaiseProgressChanged("Import complete", 100);
            return(m);
        }
示例#19
0
    public void Set(InstalledItem item)
    {
        ok                 = false;
        kvpGo              = new List <GameObject>();
        this.item          = item;
        this.itemName      = item.niceName;
        this.workCondition = item.workCondition == null ? "" : item.workCondition;
        txtItemName.text   = item.niceName;
        tmpInputField.text = this.workCondition;
        gameObject.SetActive(true);
        WorldController.Instance.inputController.SetInputMode(INPUT_MODE.SHOWING_DIALOGUE);
        WorldController.Instance.gameState = GAME_STATE.PAUSE;
        Dictionary <string, string> kvps = item.itemParameters.GetItems();

        tglActive.isOn = item.active;

        currentRecipeText.text = "";
        if (item.workRecipeName != null)
        {
            currentRecipeText.text  = Funcs.PadPair(46, "current recipe", Recipe.GetNiceName(item.workRecipeName));
            currentRecipeText.text += "\n" + Funcs.PadPair(46, ".", ".");
            //Debug.Log(currentRecipeText.textBounds.max.x);
            currentRecipeText.text += Recipe.GetRecipe(item.workRecipeName).ToString(46);
            currentRecipeText.text += "\n" + Funcs.PadPair(46, ".", ".");
        }


        //currentRecipeText.text += "\n" + Funcs.PadPair(46, ".", ".");
        //currentRecipeText.text += "\n" + Funcs.PadPair(46, ".", ".");



        foreach (string k in kvps.Keys)
        {
            CreateKVPControl(k, kvps[k]);
        }
        availableRecipes.Clear();
        niceNames.Clear();
        chooseRecipeDrop.ClearOptions();
        //Debug.Log("avaiable recipes: " + item.availableRecipes.Count);
        //item.itemParameters.SetInt("num recipes", item.availableRecipes.Count);

        if (item.canChangeRecipe)
        {
            foreach (string r in item.availableRecipes)
            {
                string niceName = Recipe.GetNiceName(r);
                if (niceName == null)
                {
                }
                else
                {
                    availableRecipes[niceName] = r;
                    TMP_Dropdown.OptionData da = new TMP_Dropdown.OptionData(niceName);
                    niceNames.Add(da);
                }
            }


            chooseRecipeDrop.AddOptions(niceNames);
            chooseRecipeDrop.interactable = true;
            chooseRecipeDrop.value        = chooseRecipeDrop.options.IndexOf(niceNames.Find(e => e.text == Recipe.GetNiceName(item.workRecipeName)));
        }
        else
        {
            chooseRecipeDrop.interactable = false;
        }
    }
示例#20
0
        //
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static DataTable Get()
        {
            List <InstalledItem> installedItems = new List <InstalledItem>();

            foreach (CMWinRegistry.WinRegPath uninstallPath in CMWinRegistry.GetUninstallKeys())
            {
                foreach (string appKeyName in CMWinRegistry.RegKeyFromString(uninstallPath.RegPath).GetSubKeyNames())
                {
                    InstalledItem installedItem = new InstalledItem()
                    {
                        Scope = uninstallPath.Scope, RegValues = CMWinRegistry.GetRegValues(CMWinRegistry.RegKeyFromString(uninstallPath.RegPath + "\\" + appKeyName))
                    };
                    installedItems.Add(installedItem);
                }
            }

            List <string> columnNames = new List <string>();

            foreach (InstalledItem installedItem in installedItems)
            {
                foreach (CMWinRegistry.RegValue regValue in installedItem.RegValues)
                {
                    if (regValue.Name != "")
                    {
                        columnNames.Add(regValue.Name);
                    }
                    else
                    {
                        columnNames.Add("WindowsKB");
                    }
                }
            }

            columnNames = columnNames.Distinct().ToList();

            DataTable result = new DataTable("InstalledPrograms");

            result.Columns.Add("Scope", typeof(String));
            foreach (string columnName in columnNames)
            {
                result.Columns.Add(columnName, typeof(String));
            }

            foreach (InstalledItem installedItem in installedItems)
            {
                DataRow row = result.NewRow();
                row["Scope"] = installedItem.Scope;
                foreach (CMWinRegistry.RegValue regValue in installedItem.RegValues)
                {
                    if (regValue.Name != "")
                    {
                        row[regValue.Name] = regValue.Data;
                    }
                    else
                    {
                        row["WindowsKB"] = regValue.Data;
                    }
                }
                result.Rows.Add(row);
            }

            return(result);
        }
 public void OnInstalledItemCreated(InstalledItem item)
 {
     //Debug.Log("play item created sound");
 }