Esempio n. 1
0
        private void AddBlueprintEntity(BlueprintEntity converted, IEnumerable <WallEntity> itsWalls,
                                        IEnumerable <ColumnEntity> itsColumns, ICollection <Opening> itsOpenings, IEnumerable <SignatureEntity> itsSignatures)
        {
            using (BlueBuilderDBContext context = new BlueBuilderDBContext()) {
                context.Blueprints.Add(converted);
                UserEntity owner = converted.Owner;

                if (context.Users.Any(u => u.UserName.Equals(owner.UserName)))
                {
                    context.Entry(converted.Owner).State = EntityState.Unchanged;
                }

                context.Columns.AddRange(itsColumns);
                context.Walls.AddRange(itsWalls);
                context.Signatures.AddRange(itsSignatures);

                MaterialAndEntityConverter materialTranslator = new MaterialAndEntityConverter();
                foreach (Opening op in itsOpenings)
                {
                    string tempName = op.getTemplateName();
                    OpeningTemplateEntity itsTemplate = context.OpeningTemplates
                                                        .FirstOrDefault(t => t.Name.Equals(tempName));

                    OpeningEntity opRecord = materialTranslator.OpeningToEntity(op, itsTemplate, converted);
                    context.Openings.Add(opRecord);
                }
                context.SaveChanges();
            }
        }
Esempio n. 2
0
 public void SetEntityA(BlueprintEntity a, BlueprintEntityPin anchorA)
 {
     this.a            = a;
     this.anchorA      = anchorA;
     _anchorATransform = anchorA.transform;
     _rectA            = anchorA.GetComponent <RectTransform>();
     _rectParentA      = _anchorATransform.parent.GetComponent <RectTransform>();
 }
Esempio n. 3
0
 public void SetEntityB(BlueprintEntity b, BlueprintEntityPin anchorB)
 {
     this.b            = b;
     this.anchorB      = anchorB;
     _anchorBTransform = anchorB.transform;
     _rectB            = anchorB.GetComponent <RectTransform>();
     _rectParentB      = _anchorBTransform.parent.GetComponent <RectTransform>();
 }
Esempio n. 4
0
        private void ShowEntityDropPown(ImGui imgui, RecipeRow recipe)
        {
            imgui.ShowDropDown((ImGui gui, ref bool closed) =>
            {
                closed = gui.BuildInlineObejctListAndButton(recipe.recipe.crafters, DataUtils.FavouriteCrafter, sel =>
                {
                    if (recipe.entity == sel)
                    {
                        return;
                    }
                    recipe.RecordUndo().entity = sel;
                    if (!sel.energy.fuels.Contains(recipe.fuel))
                    {
                        recipe.fuel = recipe.entity.energy.fuels.AutoSelect(DataUtils.FavouriteFuel);
                    }
                }, "Select crafting entity", extra: x => DataUtils.FormatAmount(x.craftingSpeed, UnitOfMeasure.Percent));

                if (recipe.fixedBuildings > 0f)
                {
                    if (gui.BuildButton("Clear fixed building count") && (closed = true))
                    {
                        recipe.RecordUndo().fixedBuildings = 0f;
                    }
                }
                else
                {
                    if (gui.BuildButton("Set fixed building count") && (closed = true))
                    {
                        recipe.RecordUndo().fixedBuildings = recipe.buildingCount <= 0f ? 1f : recipe.buildingCount;
                    }
                }

                if (recipe.entity != null && gui.BuildButton("Create single building blueprint") && (closed = true))
                {
                    var entity = new BlueprintEntity {
                        index = 1, name = recipe.entity.name
                    };
                    if (!(recipe.recipe is Mechanics))
                    {
                        entity.recipe = recipe.recipe.name;
                    }
                    var modules = recipe.parameters.modules.modules;
                    if (modules != null)
                    {
                        entity.items = new Dictionary <string, int>();
                        foreach (var(module, count) in recipe.parameters.modules.modules)
                        {
                            entity.items[module.name] = count;
                        }
                    }
                    var bp = new BlueprintString {
                        blueprint = { label = recipe.recipe.locName, entities = { entity } }
                    };
                    SDL.SDL_SetClipboardText(bp.ToBpString());
                }
            });
        }
Esempio n. 5
0
        private IBlueprint TryGetting(Guid id)
        {
            IBlueprint queried;

            using (BlueBuilderDBContext context = new BlueBuilderDBContext())
            {
                BlueprintEntity record = context.Blueprints.Include(bp => bp.Owner).FirstOrDefault(bp => bp.Id.Equals(id));

                queried = BuildBlueprint(record);
            }
            return(queried);
        }
        public IBlueprint EntityToBlueprint(BlueprintEntity toConvert, ICollection <WallEntity> wallEnts, ICollection <OpeningEntity> openEnts, ICollection <ColumnEntity> colEnts)
        {
            UserAndEntityConverter userEntityConverter = new UserAndEntityConverter();

            User convertedUser = userEntityConverter.ToUser(toConvert.Owner);
            ICollection <Signature> convertedSignatures = GetBlueprintSignatures(toConvert);

            MaterialContainer materials = BuildUpContainer(wallEnts, openEnts, colEnts);

            IBlueprint conversion = new Blueprint(toConvert.Length, toConvert.Width, toConvert.Name, convertedUser, materials, convertedSignatures, toConvert.Id);

            return(conversion);
        }
        private ICollection <Signature> GetBlueprintSignatures(BlueprintEntity toConvert)
        {
            ICollection <Signature> signatures = new List <Signature>();

            using (BlueBuilderDBContext context = new BlueBuilderDBContext()) {
                IEnumerable <SignatureEntity> queriedSignatures = context.Signatures.Where(se => se.BlueprintSigned.Id == toConvert.Id);
                foreach (SignatureEntity se in queriedSignatures)
                {
                    signatures.Add(EntityToSignature(se));
                }
            }
            return(signatures);
        }
Esempio n. 8
0
        private bool TryAskingIfExists(IBlueprint asked)
        {
            bool exists;
            BlueprintAndEntityConverter translator = new BlueprintAndEntityConverter();
            BlueprintEntity             toAsk      = translator.BlueprintToEntiy(asked);

            using (BlueBuilderDBContext context = new BlueBuilderDBContext())
            {
                Guid askedId = asked.GetId();
                exists = context.Blueprints.Any(bp => bp.Id == askedId);
            }
            return(exists);
        }
Esempio n. 9
0
        public ColumnEntity ColumnToEntity(Column toConvert, BlueprintEntity blueprint)
        {
            ColumnEntity conversion = new ColumnEntity()
            {
                Width           = toConvert.Width(),
                Height          = toConvert.Height(),
                Length          = toConvert.Length(),
                CoordX          = toConvert.GetPosition().CoordX,
                CoordY          = toConvert.GetPosition().CoordY,
                BearerBlueprint = blueprint
            };

            return(conversion);
        }
        public BlueprintEntity BlueprintToEntiy(IBlueprint toConvert)
        {
            UserAndEntityConverter userEntityConverter = new UserAndEntityConverter();
            BlueprintEntity        conversion          = new BlueprintEntity()
            {
                Name   = toConvert.Name,
                Length = toConvert.Length,
                Width  = toConvert.Width,
                Owner  = userEntityConverter.ToEntity(toConvert.Owner),
                Id     = toConvert.GetId()
            };

            return(conversion);
        }
        public SignatureEntity SignatureToEntity(Signature toConvert, BlueprintEntity bearer)
        {
            UserAndEntityConverter userEntityConverter = new UserAndEntityConverter();

            SignatureEntity conversion = new SignatureEntity()
            {
                SignerName      = toConvert.ArchitectName,
                SignerSurname   = toConvert.ArchitectSurname,
                SignerUserName  = toConvert.ArchitectUserName,
                SignatureDate   = toConvert.Date,
                BlueprintSigned = bearer
            };

            return(conversion);
        }
Esempio n. 12
0
        public WallEntity WallToEntity(Wall toConvert, BlueprintEntity bearer)
        {
            WallEntity conversion = new WallEntity()
            {
                BeginningX      = toConvert.Beginning().CoordX,
                BeginningY      = toConvert.Beginning().CoordY,
                EndX            = toConvert.End().CoordX,
                EndY            = toConvert.End().CoordY,
                Height          = toConvert.Height(),
                Width           = toConvert.Width(),
                BearerBlueprint = bearer
            };

            return(conversion);
        }
Esempio n. 13
0
        private void TryToDelete(IBlueprint toRemove)
        {
            if (Exists(toRemove))
            {
                BlueprintAndEntityConverter translator = new BlueprintAndEntityConverter();
                BlueprintEntity             converted  = translator.BlueprintToEntiy(toRemove);

                using (BlueBuilderDBContext context = new BlueBuilderDBContext())
                {
                    Guid            removeId = toRemove.GetId();
                    BlueprintEntity record   = context.Blueprints.FirstOrDefault(be => be.Id == removeId);
                    context.Blueprints.Remove(record);
                    context.SaveChanges();
                }
            }
        }
Esempio n. 14
0
        private IBlueprint BuildBlueprint(BlueprintEntity blueprint)
        {
            BlueprintAndEntityConverter converter = new BlueprintAndEntityConverter();
            ICollection <WallEntity>    wallEnts;
            ICollection <OpeningEntity> openEnts;
            ICollection <ColumnEntity>  colEnts;

            using (BlueBuilderDBContext context = new BlueBuilderDBContext())
            {
                wallEnts = context.Walls.Where(we => we.BearerBlueprint.Id == blueprint.Id).ToList();
                openEnts = context.Openings.Include(o => o.Template).Where(we => we.BearerBlueprint.Id == blueprint.Id).ToList();
                colEnts  = context.Columns.Where(ce => ce.BearerBlueprint.Id == blueprint.Id).ToList();
            }
            IBlueprint builtBlueprint = converter.EntityToBlueprint(blueprint, wallEnts, openEnts, colEnts);

            return(builtBlueprint);
        }
Esempio n. 15
0
        public void Add(IBlueprint toStore)
        {
            BlueprintAndEntityConverter   blueprintTranslator = new BlueprintAndEntityConverter();
            MaterialAndEntityConverter    materialTranslator  = new MaterialAndEntityConverter();
            BlueprintEntity               converted           = blueprintTranslator.BlueprintToEntiy(toStore);
            IEnumerable <ColumnEntity>    convertedColumns    = toStore.GetColumns().Select(c => materialTranslator.ColumnToEntity((Column)c, converted));
            IEnumerable <WallEntity>      convertedWalls      = toStore.GetWalls().Select(w => materialTranslator.WallToEntity(w, converted));
            IEnumerable <SignatureEntity> convertedSignatures = toStore.GetSignatures().Select(s => blueprintTranslator.SignatureToEntity(s, converted));
            ICollection <Opening>         itsOpenings         = toStore.GetOpenings();

            try
            {
                AddBlueprintEntity(converted, convertedWalls, convertedColumns, itsOpenings, convertedSignatures);
            }
            catch (DbException) {
                throw new InaccessibleDataException();
            }
        }
 protected override void Start()
 {
     base.Start();
     _entity = GetComponent <BlueprintEntity>();
 }
Esempio n. 17
0
        public OpeningEntity OpeningToEntity(Opening toConvert, OpeningTemplateEntity itsTemplate, BlueprintEntity bearer)
        {
            OpeningEntity conversion = new OpeningEntity()
            {
                CoordX          = toConvert.GetPosition().CoordX,
                CoordY          = toConvert.GetPosition().CoordY,
                Template        = itsTemplate,
                BearerBlueprint = bearer
            };

            return(conversion);
        }