private IdQuantity <TEntity> GetIdQuantityForId(int id)
        {
            if (!this._initialized)
            {
                this.RefreshMap();
                this._initialized = true;
            }

            if (!this._idMap.ContainsKey(id))
            {
                DTEntity entity = IdList <TEntity> .Instance.LoadById(id);

                if (entity == null)
                {
                    Debug.LogWarning("GetIdQuantityForId - called with invalid " + typeof(TEntity).Name + " id: " + id + "!");
                    return(null);
                }

                IdQuantity <TEntity> idQuantity = new IdQuantity <TEntity>(id, quantity: 0);
                this._idList.Add(idQuantity);
                this._idMap[id] = idQuantity;
            }

            return(this._idMap[id]);
        }
示例#2
0
        // PRAGMA MARK - Public Interface
        public void SetupWithIdQuantity <TEntity>(IdQuantity <TEntity> idQuantity) where TEntity : DTEntity
        {
            IViewIdQuantity viewIdQuantity = new ViewIdQuantity <TEntity>(idQuantity);

            DTEntity         entity           = viewIdQuantity.Entity;
            DisplayComponent displayComponent = entity.GetComponent <DisplayComponent>();

            if (displayComponent != null)
            {
                this._image.sprite = displayComponent.displaySprite;
            }

            if (viewIdQuantity.Quantity <= 0)
            {
                Debug.LogWarning("IdQuantityView - don't know how to show a quantity less than or equal to zero!");
            }

            if (viewIdQuantity.Quantity > 1)
            {
                this._textContainer.SetActive(true);
                this._text.SetText(string.Format("x{0}", viewIdQuantity.Quantity));
            }
            else
            {
                this._textContainer.SetActive(false);
            }
        }
示例#3
0
        public static void PopulateSpriteRenderer(this DTEntity entity, SpriteRenderer spriteRenderer)
        {
            DisplayComponent displayComponent = entity.GetComponent <DisplayComponent>();

            if (displayComponent == null)
            {
                Debug.LogError("PopulateSpriteRenderer - failed to get display component!");
                return;
            }

            spriteRenderer.sprite = displayComponent.displaySprite;
        }
示例#4
0
        public static void PopulateNameOutlet(this DTEntity entity, TextOutlet textOutlet)
        {
            DisplayComponent displayComponent = entity.GetComponent <DisplayComponent>();

            if (displayComponent == null)
            {
                Debug.LogError("PopulateNameOutlet - failed to get display component!");
                return;
            }

            textOutlet.Text = displayComponent.displayName;
        }
示例#5
0
        public static void PopulateImage(this DTEntity entity, Image image)
        {
            DisplayComponent displayComponent = entity.GetComponent <DisplayComponent>();

            if (displayComponent == null)
            {
                Debug.LogError("PopulateImage - failed to get display component!");
                return;
            }

            image.sprite = displayComponent.displaySprite;
        }
        // PRAGMA MARK - Public Interface
        public void SetupWithViewIdQuantity(IViewIdQuantity viewIdQuantity)
        {
            this._viewIdQuantity = viewIdQuantity;

            DTEntity         entity           = this._viewIdQuantity.Entity;
            DisplayComponent displayComponent = entity.GetComponent <DisplayComponent>();

            if (displayComponent != null)
            {
                this._renderer.sprite = displayComponent.displaySprite;
            }

            this._autoTapCoroutine = CoroutineWrapper.StartCoroutine(this.AutoTapCoroutine());
        }
示例#7
0
        private static int GetWeightForEntity(DTEntity entity)
        {
            if (entity == null)
            {
                return(0);
            }

            WeightComponent weightComponent = entity.GetComponent <WeightComponent>();

            if (weightComponent == null)
            {
                return(0);
            }

            return(weightComponent.weight);
        }
        public static void Initialize(Type entityType, DTEntity entity)
        {
            if (entity.Initialized)
            {
                return;
            }

            FieldInfo[] componentFields = DTEntityInitializer.GetComponentFields(entityType);
            foreach (FieldInfo componentField in componentFields)
            {
                object component = componentField.GetValue(entity);
                entity.AddComponent(componentField.FieldType, component);
            }

            entity.FinishInitializing();
        }
        // PRAGMA MARK - Public Interface
        public void SetupWithRequiredIdQuantity <TEntity>(IdQuantity <TEntity> requiredIdQuantity) where TEntity : DTEntity
        {
            IViewIdQuantity requiredViewIdQuantity = new ViewIdQuantity <TEntity>(requiredIdQuantity);

            this._requiredViewIdQuantity = requiredViewIdQuantity;
            this._requiredViewIdQuantity.OnUserInventoryUpdated += this.HandleInventoryUpdated;

            DTEntity         entity           = this._requiredViewIdQuantity.Entity;
            DisplayComponent displayComponent = entity.GetComponent <DisplayComponent>();

            if (displayComponent != null)
            {
                this._requiredImage.sprite = displayComponent.displaySprite;
            }

            this.UpdateUserCount();
        }
示例#10
0
 public static Sprite DisplaySprite(this DTEntity entity)
 {
     return(entity.GetComponent <DisplayComponent>().displaySprite);
 }
示例#11
0
 public static string DisplayName(this DTEntity entity)
 {
     return(entity.GetComponent <DisplayComponent>().displayName);
 }
示例#12
0
 private EntityQuantity(DTEntity entity, int quantity = 1)
 {
     this.entity   = entity;
     this.quantity = quantity;
 }