internal static GenerateResults Generate(Type baseType, SortedSet <string> namespaces, NameGenerator generator, MethodInformationBuilder builder) { var requiresObsoleteSuppression = false; var generatedEvents = new List <string>(); foreach (var @event in baseType.GetMockableEvents(generator)) { var eventHandlerType = @event.EventHandlerType; var eventHandlerTypeInfo = eventHandlerType; namespaces.Add(eventHandlerType.Namespace); var eventMethod = @event.AddMethod; var methodInformation = builder.Build(new MockableResult <MethodInfo>( eventMethod, RequiresExplicitInterfaceImplementation.No)); var @override = methodInformation.DescriptionWithOverride.Contains("override", StringComparison.Ordinal) ? "override " : string.Empty; if (eventMethod.IsPublic) { generatedEvents.Add(EventTemplates.GetEvent(@override, eventHandlerType.GetFullName(namespaces), @event.Name)); } else if (!eventMethod.IsPrivate && eventMethod.IsAbstract) { var visibility = CodeTemplates.GetVisibility(eventMethod.IsFamily, eventMethod.IsFamilyOrAssembly); generatedEvents.Add(EventTemplates.GetNonPublicEvent(visibility, eventHandlerType.GetFullName(namespaces), @event.Name)); } requiresObsoleteSuppression |= @event.GetCustomAttribute <ObsoleteAttribute>() != null; } var result = generatedEvents.Count > 0 ? EventTemplates.GetEvents(generatedEvents.AsReadOnly()) : string.Empty; return(new GenerateResults(result, requiresObsoleteSuppression, false)); }
public override void InitObjects(Unity_Level level) { // Hard-code event animations for the different Rayman types Unity_ObjGraphics rayDes = null; var rayEvent = (Unity_Object_R1)level.Rayman ?? level.EventData.Cast <Unity_Object_R1>().FirstOrDefault(x => x.EventData.Type == R1_EventType.TYPE_RAY_POS); if (rayEvent != null) { rayDes = DES.ElementAtOrDefault(rayEvent.DESIndex)?.Data.Graphics; } if (rayDes == null) { return; } var miniRay = level.EventData.Cast <Unity_Object_R1>().FirstOrDefault(x => x.EventData.Type == R1_EventType.TYPE_DEMI_RAYMAN); var miniRayDESIndex = miniRay?.DESIndex; if (miniRayDESIndex == null && EventTemplates.ContainsKey(WldObjType.RayLittle)) { miniRayDESIndex = UsesPointers ? DESLookup.TryGetItem(EventTemplates[WldObjType.RayLittle].ImageDescriptorsPointer?.AbsoluteOffset ?? 0, -1) : (int)EventTemplates[WldObjType.RayLittle].PC_ImageDescriptorsIndex; } if (miniRayDESIndex != null) { var miniRayDes = DES.ElementAtOrDefault(miniRayDESIndex.Value)?.Data.Graphics; if (miniRayDes != null) { miniRayDes.Animations = rayDes.Animations.Select(anim => { var newAnim = new Unity_ObjAnimation { Frames = anim.Frames.Select(x => new Unity_ObjAnimationFrame(x.SpriteLayers.Select(l => new Unity_ObjAnimationPart() { ImageIndex = l.ImageIndex, XPosition = l.XPosition / 2, YPosition = l.YPosition / 2, IsFlippedHorizontally = l.IsFlippedHorizontally, IsFlippedVertically = l.IsFlippedVertically, }).ToArray())).ToArray() }; return(newAnim); }).ToList(); } } var badRay = level.EventData.Cast <Unity_Object_R1>().FirstOrDefault(x => x.EventData.Type == R1_EventType.TYPE_BLACK_RAY); if (badRay != null) { var badRayDes = DES.ElementAtOrDefault(badRay.DESIndex)?.Data.Graphics; if (badRayDes != null) { badRayDes.Animations = rayDes.Animations; } } // Set frames for linked events for (int i = 0; i < level.EventData.Count; i++) { // Recreated from allocateOtherPosts var baseEvent = (Unity_Object_R1)level.EventData[i]; var linkedIndex = LinkTable[i]; if (baseEvent.EventData.Type.UsesRandomFrameLinks() && i != linkedIndex) { var index = 0; do { index++; var e = (Unity_Object_R1)level.EventData[linkedIndex]; e.ForceFrame = (byte)((baseEvent.ForceFrame + index) % (e.CurrentAnimation?.Frames.Length ?? 1)); e.XPosition = (short)(baseEvent.EventData.XPosition + 32 * index * (baseEvent.EventData.HitPoints - 2)); e.YPosition = baseEvent.YPosition; linkedIndex = LinkTable[linkedIndex]; } while (i != linkedIndex); } } // Set DES and ETA for worldmap if (Context.Settings.R1_World == R1_World.Menu) { var mapObj = EventTemplates[WldObjType.MapObj]; var rayman = level.Rayman as Unity_Object_R1; // Change Rayman to small Rayman if (miniRayDESIndex != null && rayman != null) { rayman.DESIndex = miniRayDESIndex.Value; rayman.EventData.OffsetBX = (byte)(rayman.EventData.OffsetBX / 2); rayman.EventData.OffsetBY = (byte)(rayman.EventData.OffsetBY / 2); } // Set Rayman's properties if (rayman != null) { rayman.EventData.Etat = rayman.EventData.InitialEtat = 0; rayman.EventData.SubEtat = rayman.EventData.InitialSubEtat = 0; if (Context.Settings.EngineVersion == EngineVersion.R1_PC_Kit) { // ? rayman.XPosition = (short)(level.EventData[0].XPosition + 42 - rayman.EventData.OffsetBX); rayman.YPosition = (short)(level.EventData[0].YPosition + 48 - rayman.EventData.OffsetBY); } else if (Context.Settings.EngineVersion == EngineVersion.R1_PC_Edu || Context.Settings.EngineVersion == EngineVersion.R1_PS1_Edu) { // ? rayman.XPosition = (short)(level.EventData[0].XPosition + 42 + 44 - rayman.EventData.OffsetBX); rayman.YPosition = (short)(level.EventData[0].YPosition + 48 + 24 - rayman.EventData.OffsetBY); rayman.EventData.PC_Flags |= R1_EventData.PC_EventFlags.IsFlipped; } else { rayman.XPosition = (short)(level.EventData[0].XPosition + 70 - rayman.EventData.OffsetBX + 9); // The game does +4 instead of 9 - why? rayman.YPosition = (short)(level.EventData[0].YPosition + 64 - rayman.EventData.OffsetBY + 8); // Is this correct? } } foreach (var e in level.EventData.Cast <Unity_Object_R1>().Select(x => x.EventData)) { e.ImageDescriptorsPointer = mapObj.ImageDescriptorsPointer; e.ImageBufferPointer = mapObj.ImageBufferPointer; e.AnimDescriptorsPointer = mapObj.AnimDescriptorsPointer; e.ETAPointer = mapObj.ETAPointer; e.PC_ImageDescriptorsIndex = mapObj.PC_ImageDescriptorsIndex; e.PC_ImageBufferIndex = mapObj.PC_ImageBufferIndex; e.PC_AnimationDescriptorsIndex = mapObj.PC_AnimationDescriptorsIndex; e.PC_ETAIndex = mapObj.PC_ETAIndex; } } }
public static void GetEvent() => Assert.That(EventTemplates.GetEvent("a", "b", "c"), Is.EqualTo("public a event b? c;"));
public static void GetNonPublicEvent() => Assert.That(EventTemplates.GetNonPublicEvent("a", "b", "c"), Is.EqualTo("a override event b? c;"));