private object ResolveEntityReference(string askingChunkFourCC, DataDescriptorField templateProperty, int index, Scene scene) { switch (templateProperty.ReferenceType) { case ReferenceTypes.Room: // Some things will specify a Room index of 255 for "This isn't Used", so we're going to special-case handle that. if (index == 0xFF) return null; if (index < m_map.Rooms.Count) { return m_map.Rooms[index]; } else { WLog.Warning(LogCategory.EntityLoading, null, "Chunk {0} requested reference for room but index is out of range. (Property Name: {1}, Index: {2})", askingChunkFourCC, templateProperty.FieldName, index); } return null; case ReferenceTypes.FourCC: // Get an (ordered) list of all chunks of that type. List<RawMapEntity> potentialRefs = new List<RawMapEntity>(); foreach (var entity in m_entityData[scene]) { if (entity.FourCC == templateProperty.ReferenceFourCCType) potentialRefs.Add(entity); } // There's an edge-case here where some maps omit an entity (such as Fairy01 not having a Virt chunk) but use index 0 (Fairy01's Pale chunk) // and so it was finding no potentialRefs if (index < potentialRefs.Count) { return potentialRefs[index]; } else { WLog.Warning(LogCategory.EntityLoading, null, "Chunk {0} requested reference for property {1} but index ({2}) is out of range.", askingChunkFourCC, templateProperty.FieldName, index); } return null; } return null; }
private object GetDefaultValue(DataDescriptorField templateProperty) { if(templateProperty.DefaultValue == null) { switch (templateProperty.FieldType) { case PropertyType.Byte: return (byte)0; case PropertyType.Short: return (short)0; case PropertyType.Int32: return (int)0; case PropertyType.Float: return (float)0; case PropertyType.Bool: return (bool)false; case PropertyType.FixedLengthString: return (string)""; case PropertyType.String: return (string)""; case PropertyType.Vector2: return Vector2.Zero; case PropertyType.Vector3: return Vector3.Zero; case PropertyType.Color24: return new Color24(0, 0, 0); case PropertyType.Color32: return new Color32(0, 0, 0, 0); case PropertyType.Int32BitField: return (int)0; case PropertyType.Bits: case PropertyType.ObjectReferenceArray: case PropertyType.Quaternion: case PropertyType.Vector3Byte: case PropertyType.ObjectReferenceShort: case PropertyType.ObjectReference: case PropertyType.XYZRotation: case PropertyType.XYRotation: case PropertyType.YRotation: case PropertyType.Enum: case PropertyType.None: default: return null; } } switch (templateProperty.FieldType) { case PropertyType.Byte: return (byte)templateProperty.DefaultValue; case PropertyType.Short: return (short)templateProperty.DefaultValue; case PropertyType.Int32: return (int)templateProperty.DefaultValue; case PropertyType.Float: return (float)templateProperty.DefaultValue; case PropertyType.Bool: return (bool)templateProperty.DefaultValue; case PropertyType.FixedLengthString: return (string)templateProperty.DefaultValue; case PropertyType.String: return (string)templateProperty.DefaultValue; case PropertyType.Vector2: return (Vector2)templateProperty.DefaultValue; case PropertyType.Vector3: return (Vector3)templateProperty.DefaultValue; case PropertyType.Color24: return (Color24)templateProperty.DefaultValue; case PropertyType.Color32: return (Color32)templateProperty.DefaultValue; case PropertyType.Int32BitField: return (int)templateProperty.DefaultValue; case PropertyType.Bits: case PropertyType.ObjectReferenceArray: case PropertyType.Quaternion: case PropertyType.Vector3Byte: case PropertyType.ObjectReferenceShort: case PropertyType.ObjectReference: case PropertyType.XYZRotation: case PropertyType.XYRotation: case PropertyType.YRotation: case PropertyType.Enum: case PropertyType.None: default: return (object)templateProperty.DefaultValue; } }