Пример #1
0
        public BuildingSite(CityLevel cityLevel, JSONTable template) : base(cityLevel, TextureCache.building_site, template.getVector2("pos"), TextureCache.building_site.Size())
        {
            this.price   = template.getInt("price");
            this.canDrag = false;

            JSONArray signatureTemplate = template.getArray("chemical", null);

            if (signatureTemplate != null)
            {
                this.signature = new ChemicalSignature(signatureTemplate);
                this.spawn     = new ChemicalInbox(cityLevel, signature, 0, bounds.XY);
            }
            else
            {
                this.spawn = CityObject.FromTemplate(cityLevel, template.getJSON("built"));
            }

            Init();
        }
Пример #2
0
        public CityLevel(JSONTable template)
        {
            this.name            = template.getString("name");
            this.pos             = template.getVector2("pos");
            this.price           = template.getInt("price");
            this.isTutorial      = template.getBool("isTutorial", false);
            blackboard.cityLevel = this;

            InitUI();

            isNew = true;

            Dictionary <string, CityObject> objectsByName = new Dictionary <string, CityObject>();

            JSONTable unlockTable = template.getJSON("unlocks", null);

            if (unlockTable != null)
            {
                foreach (string unlockName in unlockTable.Keys)
                {
                    JSONTable         unlockTemplates = unlockTable.getJSON(unlockName);
                    List <CityObject> newObjects      = new List <CityObject>();
                    List <UIElement>  newUI           = new List <UIElement>();
                    List <Weapon>     newWeapons      = new List <Weapon>();
                    foreach (string objectName in unlockTemplates.Keys)
                    {
                        /*if(unlockableUI.ContainsKey(objectName))
                         * {
                         *  newUI.Add(unlockableUI[objectName]);
                         * }
                         * else*/
                        if (Game1.instance.inventory.unlockableWeapons.ContainsKey(objectName))
                        {
                            newWeapons.Add(Game1.instance.inventory.unlockableWeapons[objectName]);
                        }
                        else
                        {
                            CityObject newObj = CityObject.FromTemplate(this, unlockTemplates.getJSON(objectName));
                            objectsByName[objectName] = newObj;
                            newObjects.Add(newObj);
                        }
                    }

                    if (unlockName == "start")
                    {
                        foreach (CityObject obj in newObjects)
                        {
                            objects.Add(obj);

                            //tutorial hack
                            if (obj is ChemicalFactory)
                            {
                                blackboard.selectedObject = obj;
                            }
                        }
                        foreach (UIElement element in newUI)
                        {
                            ui.Add(element);
                        }
                        foreach (Weapon w in newWeapons)
                        {
                            Game1.instance.inventory.UnlockWeapon(w);
                        }
                    }
                    else
                    {
                        unlockRules.Add(new UnlockRule_Output(objectsByName[unlockName], newUI, newObjects, newWeapons));
                    }
                }

                // postprocess to add pipes
                foreach (string unlockName in unlockTable.Keys)
                {
                    JSONTable unlockTemplates = unlockTable.getJSON(unlockName);
                    foreach (string objectName in unlockTemplates.Keys)
                    {
                        //if (unlockableUI.ContainsKey(objectName) ||
                        if (Game1.instance.inventory.unlockableWeapons.ContainsKey(objectName))
                        {
                            continue;
                        }

                        JSONTable objectTemplate = unlockTemplates.getJSON(objectName);
                        JSONArray pipeTargets    = objectTemplate.getArray("pipes", null);
                        if (pipeTargets != null)
                        {
                            foreach (string pipeTarget in pipeTargets.asStrings())
                            {
                                CityObject sourceObject = objectsByName[objectName];
                                CityObject targetObject = objectsByName[pipeTarget];
                                OutputPipe pipe         = sourceObject.pipes.Last();
                                pipe.ConnectTo(targetObject.GetNearestSocket(targetObject.bounds.XY));
                                pipe.movable = false;
                            }
                        }
                    }
                }
            }
        }