Beispiel #1
0
        /// <summary>
        /// Gets the block asynchronous.
        /// </summary>
        /// <param name="blockReadModel">The block read model.</param>
        /// <param name="blockName">Name of the block.</param>
        /// <returns></returns>
        private static async Task <BlockJsonModel> GetBlockAsync(BlockReadModel blockReadModel, string blockName)
        {
            var jsonModel = new BlockJsonModel()
            {
                Type = blockName
            };

            if (blockReadModel?.Arguments != null && blockReadModel.Arguments.Any())
            {
                var args = blockReadModel.Arguments.Select((data, index) => new NetworkArgumentReadModel
                {
                    Id          = index,
                    Name        = data.Name,
                    Label       = data.Label,
                    Description = data.Description,
                    DataType    = data.Type,
                    Min         = data.Min,
                    Max         = data.Max,
                    Value       = string.IsNullOrWhiteSpace(data.Value) ? string.Empty : data.Value
                }).ToList();

                jsonModel.Args.AddRange(args);
            }

            return(await Task.FromResult(jsonModel));
        }
Beispiel #2
0
        public MapJsonModel Map2JsonModel(Map map)
        {
            MapJsonModel mjson = new MapJsonModel();

            mjson.GameOverCondition = map.GameOverCondition;
            mjson.Name        = map.Name;
            mjson.Description = map.Description;
            mjson.PlayerOwnedChemicalsDescription = SemanticObjectController.GenerateChemicals2Text(map.PlayerOwnedChemicals);
            foreach (var b in map.Blocks.FindAll(m => m.IsActive))
            {
                BlockJsonModel bbj = new BlockJsonModel();
                bbj.StrainsInfo = b.Strains == null ? "" : new StrainController().Strains2Text(b.Strains);
                // b.Strains = null;
                bbj.ChemicalNamesInfo = SemanticObjectController.GenerateChemicals2Text(b.PublicChemicals);
                // b.PublicChemicals = null;

                bbj.BlockType       = b.BlockType;
                bbj.Capacity        = b.Capacity;
                bbj.HexCoor         = ObjectHelper.Clone(b.HexCoor);
                bbj.IsActive        = b.IsActive;
                bbj.StandardCoor    = ObjectHelper.Clone(b.StandardCoor);
                bbj.TotalPopulation = b.TotalPopulation;
                mjson.Blocks.Add(bbj);
            }
            return(mjson);
        }