Пример #1
0
        protected FieldUI GetField(FieldSetup field, DataProvider?dataProvider)
        {
            return(field switch
            {
                CustomExpressionFieldSetup x => new CustomExpressionFieldUI(x),
                ExpressionFieldSetup x => new ExpressionFieldUI(x),

                CustomPropertyFieldSetup x => new CustomPropertyFieldUI(x, dataProvider),
                PropertyFieldSetup x => new PropertyFieldUI(x, dataProvider),

                _ => default !
Пример #2
0
 internal FieldUI(FieldSetup field) : base(field.IsVisible, field.IsDisabled)
 {
     Description       = field.Description;
     Details           = field.Details;
     Name              = field.Name;
     Placeholder       = field.Placeholder;
     Expression        = field.Expression;
     Property          = field.Property;
     OrderByExpression = field.OrderByExpression;
     SortDescending    = field.DefaultOrder;
 }
Пример #3
0
        public FormDataProvider?GetDataProvider(FieldSetup field)
        {
            if (!(field is PropertyFieldSetup propertyField && propertyField.Relation != null))
            {
                return(null);
            }

            switch (propertyField.Relation)
            {
            case RepositoryRelationSetup collectionRelation:

                var repo = collectionRelation.RepositoryAlias != null
                            ? _repositoryResolver.GetRepository(collectionRelation.RepositoryAlias)
                            : collectionRelation.CollectionAlias != null
                                ? _repositoryResolver.GetRepository(_collectionSetupResolver.ResolveSetup(collectionRelation.CollectionAlias))
                                : default;

                if (repo == null)
                {
                    throw new InvalidOperationException($"Field {propertyField.Property!.PropertyName} has incorrectly configure relation, cannot find repository for alias {(collectionRelation.CollectionAlias ?? collectionRelation.RepositoryAlias)}.");
                }

                var provider = new CollectionDataProvider(
                    repo,
                    collectionRelation.RelatedEntityType,

                    propertyField.Property !,
                    collectionRelation.RelatedElementsGetter,

                    collectionRelation.RepositoryParentSelector,
                    collectionRelation.EntityAsParent,
                    collectionRelation.IdProperty,
                    collectionRelation.DisplayProperties,

                    _memoryCache);

                var validator = new RelationValidationAttributeValidator(propertyField.Property !);

                return(new FormDataProvider(
                           propertyField.Property !,
                           provider,
                           validator));

            case DataProviderRelationSetup dataProviderRelation:

                return(new FormDataProvider(propertyField.Property !, _serviceProvider.GetService <IDataCollection>(dataProviderRelation.DataCollectionType), default));

            default:
                throw new InvalidOperationException();
            }
            ;
        }
Пример #4
0
        private void AdjustCameraHeight(FieldSetup setup)
        {
            Vector2Int fieldSize = setup.size;

            if (_mainCamera == null)
            {
                _mainCamera = Camera.main;
            }

            // Fit from inside
            float fieldAspectRatio = fieldSize.x / (float)fieldSize.y;

            if (fieldAspectRatio > _mainCamera.aspect)
            {
                var ratioOverRatio = fieldAspectRatio / _mainCamera.aspect;
                _mainCamera.orthographicSize = (((fieldSize.x * marginOffsetPercentage) / fieldAspectRatio) / 2f) * ratioOverRatio;
            }
            else
            {
                _mainCamera.orthographicSize = fieldSize.y / 2f * marginOffsetPercentage;
            }
        }
Пример #5
0
 protected static FieldUI GetField(FieldSetup field, FormDataProvider?dataProvider)
 => field switch
 {
Пример #6
0
 private static void HandleFieldSetupClicked(FieldSetup _fieldsetup)
 {
     OnFieldSetupClicked?.Invoke(_fieldsetup);
 }
Пример #7
0
 private void HandleFieldSetupClicked(FieldSetup fieldsetup)
 {
     GameManager.Instance.CurrentFieldSetup = fieldsetup;
     StateManager.SetState(GamePlay.Instance);
 }
Пример #8
0
 public void Init(FieldSetup _fieldSetup)
 {
     fieldSetup      = _fieldSetup;
     buttonText.text = $"{_fieldSetup.size.x.ToString()}x{_fieldSetup.size.y.ToString()}\n{_fieldSetup.configName}";
 }
Пример #9
0
        public async Task <FormDataProvider?> GetDataProviderAsync(FieldSetup field)
        {
            if (!(field is PropertyFieldSetup propertyField && propertyField.Relation != null))
            {
                return(null);
            }

            switch (propertyField.Relation)
            {
            case RepositoryRelationSetup collectionRelation:

                var collectionSetup = collectionRelation.CollectionAlias == null
                        ? default
                        : await _collectionSetupResolver.ResolveSetupAsync(collectionRelation.CollectionAlias);

                var repo = collectionRelation.RepositoryAlias != null
                            ? _repositoryResolver.GetRepository(collectionRelation.RepositoryAlias)
                            : collectionSetup != null
                                ? _repositoryResolver.GetRepository(collectionSetup)
                                : default;

                if (repo == null)
                {
                    throw new InvalidOperationException($"Field {propertyField.Property!.PropertyName} has incorrectly configure relation, cannot find repository for alias {(collectionRelation.CollectionAlias ?? collectionRelation.RepositoryAlias)}.");
                }

                // TODO: investigate whether this can be moved to Setup to allow for better caching
                var idProperty = collectionRelation.IdProperty
                                 ?? collectionSetup?.ElementSetup?.IdProperty
                                 ?? throw new InvalidOperationException($"Field {propertyField.Property!.PropertyName} has incorrect Id property metadata.");

                var displayProperties = collectionRelation.DisplayProperties
                                        ?? collectionSetup?.ElementSetup?.DisplayProperties
                                        ?? throw new InvalidOperationException($"Field {propertyField.Property!.PropertyName} has incorrect display properties metadata.");

                var relatedElementGetter = collectionRelation.RelatedElementsGetter
                                           ?? ((collectionRelation.IsRelationToMany && propertyField.Property != null && propertyField.Property.PropertyType.IsAssignableTo(typeof(IEnumerable <IEntity>)))
                            ? PropertyMetadataHelper.GetPropertyMetadata <IEnumerable <IEntity>, IEnumerable <object?> >(x => x.Select(idProperty.Getter))
                            : default);

                var provider = new CollectionDataProvider(
                    repo,
                    _concurrencyService,
                    collectionRelation.RepositoryAlias,
                    collectionRelation.CollectionAlias,
                    relatedElementGetter,
                    collectionRelation.EntityAsParent,
                    collectionRelation.RepositoryParentSelector,
                    idProperty,
                    displayProperties,
                    collectionRelation.RelatedEntityType ?? collectionSetup?.EntityVariant.Type ?? typeof(object),
                    propertyField.Property !,
                    _mediator);

                return(new FormDataProvider(
                           propertyField.Property !,
                           provider));

            case DataProviderRelationSetup dataProviderRelation:

                var dataCollection = _serviceProvider.GetService <IDataCollection>(dataProviderRelation.DataCollectionType);
                if (dataProviderRelation.Configuration != null)
                {
                    dataCollection.Configure(dataProviderRelation.Configuration);
                }

                return(new FormDataProvider(propertyField.Property !, dataCollection));

            case ConcreteDataProviderRelationSetup concreteDataProvider:

                return(new FormDataProvider(propertyField.Property !, concreteDataProvider.DataCollection));

            default:
                throw new InvalidOperationException();
            }
            ;
        }