예제 #1
0
        internal void _updateMap()
        {
            var tempList = new EudiStructList <Type>(0);

            // Get all components (SPAGHETTI CODE!!!)
            var components = Wrapper.GetComponents <Component>();

            for (int i = 0; i < components.Length; i++)
            {
                var component = components[i];

                tempList.Add(component.GetType());
            }

            if (ComponentMap == null)
            {
                ComponentMap = new EudiMap();
            }

            ComponentMap.TuplesItems = new EudiMap.TupleItem[tempList.Length];
            for (int i = 0; i < tempList.Length; i++)
            {
                ComponentMap.TuplesItems[i] = new EudiMap.TupleItem()
                {
                    Type      = tempList[i],
                    Attribute = null
                };
            }

            tempList.Dispose();
        }
예제 #2
0
        /// <summary>
        /// Does this map contains some types that are also contained in this one?
        /// </summary>
        /// <param name="map"></param>
        /// <returns></returns>
        public bool ContainsTypes(EudiMap map, bool attributeCheck = true)
        {
            if (map == null)
            {
                throw new NullReferenceException(nameof(map) + " is null!");
            }

            var itemsChecked = 0;
            var itemsLength  = TuplesItems.Length;

            for (int i = 0; i < itemsLength; i++)
            {
                var item             = TuplesItems[i];
                var otherItemsLength = map.TuplesItems.Length;
                for (int j = 0; j < otherItemsLength; j++)
                {
                    var otherItem = map.TuplesItems[j];
                    if (TuplesInstanceInjector.IsValid(otherItem.Type, item))
                    {
                        itemsChecked++;
                    }
                }
            }

            return(itemsChecked >= itemsLength);
        }
예제 #3
0
        public bool Equals(EudiMap map, bool attributeCheck = true)
        {
            var itemsLength = TuplesItems.Length;

            if (map.TuplesItems.Length != itemsLength)
            {
                return(false);
            }

            var equalTypesIn = 0;

            for (int i = 0; i < itemsLength; i++)
            {
                var item             = TuplesItems[i];
                var otherItemsLength = map.TuplesItems.Length;
                for (int j = 0; j < otherItemsLength; j++)
                {
                    var otherItem = map.TuplesItems[j];
                    if (otherItem.Equals(item, attributeCheck))
                    {
                        equalTypesIn++;
                    }
                }
            }

            return(equalTypesIn == itemsLength);
        }
예제 #4
0
            public EudiStructList <EudiEntity> GetEntities(EudiMap map)
            {
                var otherMap = SearchExisting(map);

                if (otherMap == null)
                {
                    throw new Exception("Couldn't find the map!");
                }

                return(AllMaps[map]);
            }
예제 #5
0
            public EudiMap SearchExisting(EudiMap mapToCheck)
            {
                foreach (var againstMap in AllMaps.Keys)
                {
                    if (againstMap.Equals(mapToCheck))
                    {
                        return(againstMap);
                    }
                }

                return(null);
            }
        public static object AddObjectToNativeArray(object originalObject, EudiMap map)
        {
            //Debug.LogException(new NotImplementedException("Waiting for NativeList<> :)"));

            /*var nativeArrayType = typeof(NativeArray<>).MakeGenericType(originalType);
             *
             * var obj = map.GetAssignedObject(nativeArrayType);
             * if (obj != null)
             * {
             *  var type = obj.GetType();
             *
             * }*/
            return(null);
        }
예제 #7
0
        protected internal override void InternalSystemAwake()
        {
            List <EudiMap.TupleItem> tempItems         = new List <EudiMap.TupleItem>();
            List <FieldInfo>         tempCorrectFields = new List <FieldInfo>();

            var type        = GetType();
            var fields      = type.GetFields();
            var fieldsCount = fields.Length;

            for (int i = 0; i < fieldsCount; i++)
            {
                var field             = fields[i];
                var hasTupleAttribute = Attribute.IsDefined(field, typeof(InjectTuplesAttribute));
                if (hasTupleAttribute)
                {
                    var item = new EudiMap.TupleItem();
                    item.Attribute = (InjectTuplesAttribute)Attribute.GetCustomAttribute(field, typeof(InjectTuplesAttribute));
                    item.Type      = field.FieldType;
                    tempItems.Add(item);
                    tempCorrectFields.Add(field);
                }
            }

            _linkedMap    = Eudi.EntitiesManager.MapManager.GetMap(tempItems.ToArray());
            MatchEntities = Eudi.EntitiesManager.MapManager.GetEntities(_linkedMap);

            // Set fields value from the map
            foreach (var field in tempCorrectFields)
            {
                var isGeneric  = field.FieldType.IsGenericType;
                var wantedType = field.FieldType;

                var obj = _linkedMap.GetAssignedObject(wantedType);
                if (obj == null)
                {
                    Debug.LogError(new Exception($"Field {field.Name} (c:{field.DeclaringType?.Name}) was set to null!"));
                }
                field.SetValue(this, obj);
            }

            if (_linkedMap == null || tempItems.Count == 0)
            {
                Debug.LogWarning($"!!! System {GetType().FullName} got no `InjectTuple` attribute.");
                tempItems?.Clear();
                tempItems = null; //< remove reference
            }
        }
예제 #8
0
            public EudiMap GetMap(EudiMap.TupleItem[] items)
            {
                var map = new EudiMap {
                    TuplesItems = items
                };
                var existingMap = SearchExisting(map);

                if (existingMap != null)
                {
                    return(existingMap);
                }

                map._createObjects();

                AllMaps.Add(map, new EudiStructList <EudiEntity>(0));
                return(map);
            }
        public static object AddObjectToDataArray(object originalObject, EudiMap map)
        {
            var originalObjectType = originalObject.GetType();

            if (!originalObjectType.IsValueType)
            {
                return(null);
            }

            var dataArrayType = typeof(EudiModuleDataArray <>).MakeGenericType(originalObjectType);

            var obj = map.GetAssignedObject(dataArrayType);

            if (obj != null)
            {
                var castedObj = (IEudiModuleDataArray)obj;
                castedObj.AddModule(originalObject);
            }

            return(null);
        }
        public static void RemoveObjectFromDataArray(object originalObject, EudiMap map)
        {
            var originalObjectType = originalObject.GetType();

            if (!originalObjectType.IsValueType)
            {
                return;
            }

            var dataArrayType = typeof(EudiModuleDataArray <>).MakeGenericType(originalObjectType);

            var obj = map.GetAssignedObject(dataArrayType);

            if (obj != null)
            {
                var castedObj = (IEudiModuleDataArray)obj;
                if (castedObj.Contains(originalObject))
                {
                    castedObj.RemoveModule(originalObject);
                }
            }
        }
예제 #11
0
        internal bool _isValidForMapping(GameObject go, EudiMap map)
        {
            var entity    = go.GetComponent <WrapperEudiEntity>().Instance;
            var entityMap = entity.ComponentMap;

            /*var validCount = 0;
             *
             * // we have a transform, so add it
             * validCount++;
             *
             * foreach (var item in map.TuplesItems)
             * {
             *  if (entity == null)
             *  {
             *      if (typeof(Component).IsAssignableFrom(item.Type)
             *          && go.GetComponent(item.Type) != null)
             *          validCount++;
             *  }
             *  else
             *  {
             *      if (typeof(Component).IsAssignableFrom(item.Type)
             *          && entity.GetComponent(item.Type) != null)
             *          validCount++;
             *      foreach (var module in entity.SharedModules)
             *      {
             *          if (TuplesInstanceInjector.IsValid(module, item))
             *              validCount++;
             *      }
             *  }
             * }
             *
             * return validCount == map.TuplesItems.Length;*/
            var isValid = map.ContainsTypes(entityMap, false);

            return(isValid);
        }
예제 #12
0
 public bool Contains(EudiMap mapToCheck) => SearchExisting(mapToCheck) != null;