/// <summary>
        /// Constructor
        /// </summary>
        public CreateFormSectionPartialTemplate(Screen screen, ScreenSection screenSection)
        {
            Screen        = screen;
            ScreenSection = screenSection;

            Evaluate();
        }
Exemplo n.º 2
0
        private GameObject SpawnAnEnemy(ScreenSection sectionToSpawn, GameObject enemyToSpawn)
        {
            // Get position based on 'sectionToSpawn'
            Vector2 screenPos = SpecMath.GetScreenEdgePosition(sectionToSpawn, UnityEngine.Random.Range(-1f, 1f));
            Vector3 worldPos  = new Vector3(screenPos.x, 0.02f, screenPos.y);

            worldPos = Camera.main.ScreenToWorldPoint(worldPos);
            //worldPos.z = spawnPositionZ;

            // Move the position slightly offscreen
            worldPos += (worldPos - player.position) * 0.1f;

            // Spawn enemy
            GameObject newEnemy = Instantiate(enemyToSpawn, worldPos, Quaternion.identity);

            return(newEnemy);
        }
        /// <summary>
        /// Get model templates
        /// </summary>
        public IEnumerable <ITemplate> GetTemplates()
        {
            var templates            = new List <ITemplate>();
            var defaultScreenSection = new ScreenSection();

            var groupedFormScreenSections = (from ss in Screen.ScreenSections
                                             where ss.ScreenSectionType == ScreenSectionType.Form
                                             select ss)
                                            .GroupBy(ss => new
            {
                ParentSection = ss.ParentScreenSection,
                ss.Entity
            })
                                            .Select(a => new { a.Key.ParentSection, Values = a.ToArray() });

            foreach (var group in groupedFormScreenSections)
            {
                var children = new List <ScreenSection>();


                foreach (var item in group.Values)
                {
                    var childSections = (from child in groupedFormScreenSections
                                         where child.ParentSection == item
                                         select child.Values).ToList();
                    if (childSections.Any())
                    {
                        childSections.ForEach(cs => children.AddRange(cs));
                        break;
                    }
                }

                templates.Add(new ModelFormResponseTemplate(Project, Screen, group.Values, children));
                templates.Add(new ModelFormRequestTemplate(Project, Screen, group.Values, children));
            }

            return(templates);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Constructor
 /// </summary>
 public FormPartialTemplate(Project project, Screen screen, ScreenSection screenSection)
 {
     Project       = project;
     Screen        = screen;
     ScreenSection = screenSection;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Evaluate
        /// </summary>
        internal static string Evaluate(Project project, Entity entity, Screen screen, ScreenSection screenSection)
        {
            string actionName = null;

            if (entity.Id != screen.EntityId)
            {
                actionName = $"{screen.InternalName}{screenSection.InternalName}";
            }

            return($@"
        /// <summary>
        /// {screenSection.Title} Search
        /// </summary>
        Task<{screenSection.SearchSection.SearchResponseClass}> Search{actionName}Async({screenSection.SearchSection.SearchRequestClass} request);");
        }
Exemplo n.º 6
0
        /// <summary>
        /// Get file content
        /// </summary>
        public string GetFileContent()
        {
            var imports = new List <string> {
                "Edit", "SimpleForm", "Create"
            };

            var screenSections   = new List <string>();
            var componentImports = new List <string>();
            var constants        = new List <string>();

            ScreenSection rootScreenSection = null;

            foreach (var section in Screen.ScreenSections)
            {
                switch (section.ScreenSectionType)
                {
                case ScreenSectionType.Form:
                    if (rootScreenSection == null)
                    {
                        rootScreenSection = section;
                        var formSection = new CreateFormSectionPartialTemplate(Screen, section);
                        imports.AddRange(formSection.Imports);
                        constants.AddRange(formSection.Constants);
                        if (!formSection.Blank)
                        {
                            screenSections.Add(formSection.Content);
                        }
                    }
                    else
                    {
                        var formSection = new CreateFormSectionPartialTemplate(Screen, section);
                        constants.AddRange(formSection.Constants);
                        if (formSection.Blank)
                        {
                            continue;
                        }
                        if (section.VisibilityExpression == null)
                        {
                            screenSections.Add($@"<{section.InternalName} {{...props}} />");
                        }
                        else
                        {
                            var expressionHelper = new Helpers.ExpressionHelper(Screen);
                            var expression       = expressionHelper.GetExpression(section.VisibilityExpression, "formData");
                            screenSections.Add($@"<FormDataConsumer>
    {{({{ formData, ...rest }}) => 
        {expression} &&
            <{section.InternalName} {{...props}} {{...rest}} />
    }}
</FormDataConsumer>");
                            imports.Add("FormDataConsumer");
                        }
                        componentImports.Add($@"import {section.InternalName} from './{section.InternalName}';");
                    }
                    break;

                case ScreenSectionType.Search:
                {
                    var expression = "formData.id";
                    if (section.VisibilityExpression != null)
                    {
                        var expressionHelper = new Helpers.ExpressionHelper(Screen);
                        expression = string.Concat(expression, " && ", expressionHelper.GetExpression(section.VisibilityExpression, "formData"));
                    }

                    screenSections.Add($@"<FormDataConsumer>
    {{({{ formData, ...rest }}) => 
        {expression} &&
            <{section.InternalName} {{...props}} {{...rest}} />
    }}
</FormDataConsumer>");
                    imports.Add("FormDataConsumer");

                    componentImports.Add($@"import {section.InternalName} from './{section.InternalName}';");
                }
                break;

                case ScreenSectionType.MenuList:
                    break;

                case ScreenSectionType.Html:
                    break;

                default:
                    break;
                }
            }

            return($@"import React from 'react';
import {{ {string.Join(", ", imports.Distinct().OrderBy(a => a))} }} from 'react-admin';
{string.Join(Environment.NewLine, componentImports)}

{string.Join(Environment.NewLine, constants)}
const DynamicTitle = ({{ record }}) => {{
    return <span>{Screen.Title} {{record ? ` - ${{record.title}}` : ''}}</span>;
}};

const {Screen.Entity.InternalName}Edit = (props) => (
    <Edit undoable={{ false }} {{...props}} title={{< DynamicTitle />}}>
        <SimpleForm>
{screenSections.IndentLines(3)}
        </SimpleForm>
    </Edit>
);

const {Screen.Entity.InternalName}Create = (props) => (
    <Create {{...props}} title=""Create {Screen.Title}"">
        <SimpleForm redirect=""list"">
{screenSections.IndentLines(3)}
        </SimpleForm>
    </Create>
);

export {{ {Screen.Entity.InternalName}Edit, {Screen.Entity.InternalName}Create }};");
        }
Exemplo n.º 7
0
        /// <summary>
        /// Evaluate
        /// </summary>
        internal static string Evaluate(Project project, Entity entity, Screen screen, ScreenSection screenSection)
        {
            string actionName      = null;
            var    propertyMapping = new List <string>();

            foreach (var searchColumn in screenSection.SearchSection.SearchColumns)
            {
                switch (searchColumn.PropertyType)
                {
                case PropertyType.ParentRelationshipOneToMany:
                case PropertyType.ParentRelationshipOneToOne:
                    break;

                case PropertyType.ReferenceRelationship:
                    propertyMapping.Add($"                        {searchColumn.InternalNameCSharp} = (item.{searchColumn.Property.InternalName} != null ? item.{searchColumn.Property.InternalName}.Title : null)");
                    break;

                default:
                    propertyMapping.Add($"                        {searchColumn.InternalNameCSharp} = item.{searchColumn.Property.InternalName}");
                    break;
                }
            }

            string parentPropertyWhereString = null;
            Entity parentEntity = null;

            var parentProperty = (from p in screenSection.SearchSection.Entity.Properties
                                  where p.PropertyType == PropertyType.ParentRelationshipOneToMany
                                  select p).SingleOrDefault();

            if (parentProperty != null)
            {
                parentEntity = (from s in project.Entities
                                where s.Id == parentProperty.ReferenceEntityId
                                select s).SingleOrDefault();
                parentPropertyWhereString = $"where request.{parentEntity.InternalName}Id == item.{parentEntity.InternalName}Id";
            }

            if (entity.Id != screen.EntityId)
            {
                actionName = $"{screen.InternalName}{screenSection.InternalName}";
            }

            return($@"
        /// <summary>
        /// {screenSection.Title} Search
        /// </summary>
        [HttpGet]
        [ProducesResponseType(typeof(IEnumerable<{screenSection.SearchSection.SearchItemClass}>), 200)]
        [ProducesResponseType(typeof(Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary), 400)]
        public async Task<IActionResult> Search{actionName}Async([FromServices] I{screenSection.Entity.InternalName}Service {screenSection.Entity.InternalName.Camelize()}Service, [FromQuery]{screenSection.SearchSection.SearchRequestClass} request)
        {{
            if (request == null)
            {{
                return BadRequest();
            }}
            
            if (!ModelState.IsValid)
            {{
                return new BadRequestObjectResult(ModelState);
            }}

            var response = await {screenSection.Entity.InternalName.Camelize()}Service.Search{actionName}Async(request);
            
            Response.Headers.Add(""Content-Range"", $@""{screenSection.Entity.InternalNamePlural} {{request.start}}-{{request.start + response.Items.Count()}}/{{response.TotalItems}}"");
            Response.Headers.Add(""X-Total-Count"", response.TotalItems.ToString());
            return Ok(response.Items);
        }}");
        }
Exemplo n.º 8
0
        public static Vector2 GetScreenEdgePosition(ScreenSection screenSect, float percentFromCentre)
        {
            float xPosition = 0, zPosition = 0;
            float screenWidth      = Screen.width;
            float screenHeight     = Screen.height;
            float halfScreenWidth  = Screen.width / 2;
            float halfScreenHeight = Screen.height / 2;
            float verticalOverflow = Screen.height / 4;

            //for calculations
            float totalHalfLength, widthPercent, heightPercent;

            switch (screenSect)
            {
            case ScreenSection.Top:
                zPosition  = screenHeight;
                xPosition  = halfScreenWidth * percentFromCentre;
                xPosition += halfScreenWidth;
                break;

            case ScreenSection.Bottom:
                zPosition  = 0;
                xPosition  = halfScreenWidth * percentFromCentre;
                xPosition += halfScreenWidth;
                break;

            case ScreenSection.Right:
                zPosition  = halfScreenHeight * percentFromCentre;
                zPosition += halfScreenHeight;
                xPosition  = screenWidth;
                break;

            case ScreenSection.Left:
                zPosition  = halfScreenHeight * percentFromCentre;
                zPosition += halfScreenHeight;
                xPosition  = 0;
                break;

            case ScreenSection.TopOverflow:
                totalHalfLength = halfScreenWidth + verticalOverflow;
                widthPercent    = halfScreenWidth / totalHalfLength;

                if (Mathf.Abs(percentFromCentre) <= widthPercent)
                {
                    xPosition  = percentFromCentre * totalHalfLength;
                    xPosition += halfScreenWidth;
                    zPosition  = screenHeight;
                }
                else
                {
                    xPosition  = halfScreenWidth * (percentFromCentre / Mathf.Abs(percentFromCentre));
                    xPosition += halfScreenWidth;
                    zPosition  = screenHeight - ((Mathf.Abs(percentFromCentre) * totalHalfLength) - halfScreenWidth);
                }
                break;

            case ScreenSection.BottomOverflow:
                totalHalfLength = halfScreenWidth + verticalOverflow;
                widthPercent    = halfScreenWidth / totalHalfLength;

                if (Mathf.Abs(percentFromCentre) <= widthPercent)
                {
                    xPosition  = percentFromCentre * totalHalfLength;
                    xPosition += halfScreenWidth;
                    zPosition  = 0;
                }
                else
                {
                    xPosition  = halfScreenWidth * (percentFromCentre / Mathf.Abs(percentFromCentre));
                    xPosition += halfScreenWidth;
                    zPosition  = ((Mathf.Abs(percentFromCentre) * totalHalfLength) - halfScreenWidth);
                }
                break;

            case ScreenSection.All:
                // In this case, 'percentFromCentre' will be considered the bottom-right of the screen
                totalHalfLength = Screen.width + Screen.height;
                widthPercent    = screenWidth / totalHalfLength;
                heightPercent   = screenHeight / totalHalfLength;
                if (percentFromCentre < -heightPercent)         // top of screen
                {
                    xPosition  = (percentFromCentre * totalHalfLength) + screenHeight;
                    xPosition += screenWidth;
                    zPosition  = screenHeight;
                }
                else if (percentFromCentre < 0)                 // right of screen
                {
                    xPosition = screenWidth;
                    zPosition = Mathf.Abs(percentFromCentre) * totalHalfLength;
                }
                else if (percentFromCentre < widthPercent)      // bottom of screen
                {
                    xPosition = screenWidth - (percentFromCentre * totalHalfLength);
                    zPosition = 0;
                }
                else                                            // left of screen
                {
                    xPosition = 0;
                    zPosition = (percentFromCentre * totalHalfLength) - screenWidth;
                }
                break;
            }

            return(new Vector2(xPosition, zPosition));
        }
Exemplo n.º 9
0
 /// <summary>
 /// Constructor
 /// </summary>
 public ModelSearchRequestTemplate(Project project, Screen screen, ScreenSection screenSection)
 {
     Project       = project;
     Screen        = screen;
     ScreenSection = screenSection;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Constructor
 /// </summary>
 public MenuListTemplate(Project project, Screen screen, ScreenSection screenSection)
 {
     Project       = project;
     Screen        = screen;
     ScreenSection = screenSection;
 }
Exemplo n.º 11
0
        /// <summary>
        /// Evaluate
        /// </summary>
        internal static string Evaluate(Project project, Entity entity, Screen screen, ScreenSection screenSection)
        {
            string actionName      = null;
            var    propertyMapping = new List <string>();

            foreach (var searchColumn in screenSection.SearchSection.SearchColumns)
            {
                switch (searchColumn.PropertyType)
                {
                case PropertyType.ParentRelationshipOneToMany:
                case PropertyType.ParentRelationshipOneToOne:
                    break;

                case PropertyType.ReferenceRelationship:
                    propertyMapping.Add($"                        {searchColumn.InternalNameCSharp} = (item.{searchColumn.Property.InternalName} != null ? item.{searchColumn.Property.InternalName}.Title : null)");
                    break;

                case PropertyType.PrimaryKey:
                    propertyMapping.Add($"                        {searchColumn.InternalNameCSharp} = item.{searchColumn.Property.InternalName}");
                    break;

                default:
                    propertyMapping.Add($"                        {searchColumn.InternalNameCSharp} = item.{searchColumn.Property.InternalName}");
                    break;
                }
            }

            string parentPropertyWhereString = null;
            Entity parentEntity = null;

            var parentProperty = (from p in screenSection.SearchSection.Entity.Properties
                                  where p.PropertyType == PropertyType.ParentRelationshipOneToMany
                                  select p).SingleOrDefault();

            if (parentProperty != null)
            {
                parentEntity = (from s in project.Entities
                                where s.Id == parentProperty.ReferenceEntityId
                                select s).SingleOrDefault();
                parentPropertyWhereString = $"where request.{parentEntity.InternalName}Id == item.{parentEntity.InternalName}Id";
            }

            if (entity.Id != screen.EntityId)
            {
                actionName = $"{screen.InternalName}{screenSection.InternalName}";
            }

            return($@"
        /// <summary>
        /// {screenSection.Title} Search
        /// </summary>
        public virtual async Task<{screenSection.SearchSection.SearchResponseClass}> Search{actionName}Async({screenSection.SearchSection.SearchRequestClass} request)
        {{
            if (request == null)
            {{
                throw new NullReferenceException(); 
            }}

            var query = from item in _context.{screenSection.SearchSection.Entity.InternalNamePlural}.AsQueryable()
            {parentPropertyWhereString}
                        select item;

            var totalItems = query.Count();
            var items = new List<{screenSection.SearchSection.SearchItemClass}>();

            if (totalItems != 0 && request.end != 0)
            {{
                items = await query
                    .OrderBy(p => p.{screenSection.SearchSection.OrderBy})
                    .Skip(request.start)
                    .Take(request.end - request.start)
                    .Select(item => new {screenSection.SearchSection.SearchItemClass}
                    {{
{string.Join(string.Concat(",", Environment.NewLine), propertyMapping)}
                    }})
                    .ToListAsync();
            }}
            
            return new {screenSection.SearchSection.SearchResponseClass} {{
                TotalItems = totalItems,
                Items = items.ToArray(),
            }};
        }}");
        }