Пример #1
0
        public void BothTableTypesInInAssemblyPopulatesCorrectly()
        {
            var assembly = new FakeAssembly
            {
                TypesToReturn = new[]
                {
                    typeof(DateTime),
                    typeof(StubDataTableOne),
                    typeof(StubDataTableTwo),
                    typeof(StubDataTableThree),
                    typeof(StubMetadataTableOne),
                    typeof(StubMetadataTableTwo),
                    typeof(Exception),
                }
            };

            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubDataTableOne),
                    serializer,
                    out TableDescriptor expectedDescriptor1));
            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubDataTableTwo),
                    serializer,
                    out TableDescriptor expectedDescriptor2));
            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubDataTableThree),
                    serializer,
                    out TableDescriptor expectedDescriptor3));

            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubMetadataTableOne),
                    serializer,
                    out TableDescriptor expectedDescriptor4));
            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubMetadataTableTwo),
                    serializer,
                    out TableDescriptor expectedDescriptor5));

            StubDataSource.Assembly = assembly;

            var sut = new StubDataSource();

            sut.SetApplicationEnvironment(applicationEnvironment);

            Assert.AreEqual(3, sut.DataTables.Count());
            Assert.IsTrue(sut.DataTables.Contains(expectedDescriptor1));
            Assert.IsTrue(sut.DataTables.Contains(expectedDescriptor2));
            Assert.IsTrue(sut.DataTables.Contains(expectedDescriptor3));

            Assert.AreEqual(2, sut.MetadataTables.Count());
            Assert.IsTrue(sut.MetadataTables.Contains(expectedDescriptor4));
            Assert.IsTrue(sut.MetadataTables.Contains(expectedDescriptor5));
        }
Пример #2
0
        private static void Initialize()
        {
            conquerorBeamType = FakeAssembly.GetFakeEntryAssembly().GetType("Celeste.Mod.ricky06ModPack.Entities.ConquerorBeam");

            if (conquerorBeamType != null)
            {
                On.Monocle.Entity.DebugRender += ModHitbox;
            }
        }
 private static void Initialize()
 {
     groupedTriggerSpikesType      = FakeAssembly.GetFakeEntryAssembly().GetType("Celeste.Mod.MaxHelpingHand.Entities.GroupedTriggerSpikes");
     groupedTriggerSpikesTriggered = groupedTriggerSpikesType?.CreateDelegate_Get <object, bool>("Triggered");
     groupedTriggerSpikesLerp      = groupedTriggerSpikesType?.CreateDelegate_Get <object, float>("Lerp");
     if (groupedTriggerSpikesType != null && groupedTriggerSpikesTriggered != null && groupedTriggerSpikesLerp != null)
     {
         On.Monocle.Entity.DebugRender += ShowGroupedTriggerSpikesHitboxes;
     }
 }
Пример #4
0
        public static List <Type> GetSubClasses(this Type type)
        {
            List <Type> list = new List <Type>();

            foreach (Type type2 in FakeAssembly.GetFakeEntryAssembly().GetTypes())
            {
                if (type != type2 && type.IsAssignableFrom(type2))
                {
                    list.Add(type2);
                }
            }
            return(list);
        }
Пример #5
0
#pragma warning restore CS0626

        public new static void Initialize()
        {
            orig_Initialize();

            // search for entities with [TrackedAs]
            Type[] types = FakeAssembly.GetFakeEntryAssembly().GetTypes();
            foreach (Type type in types)
            {
                object[] customAttributes = type.GetCustomAttributes(typeof(TrackedAsAttribute), inherit: false);
                foreach (object customAttribute in customAttributes)
                {
                    Type trackedAsType = (customAttribute as TrackedAsAttribute).TrackedAsType;
                    if (typeof(Entity).IsAssignableFrom(type))
                    {
                        if (!type.IsAbstract)
                        {
                            // this is an entity. copy the registered types for the target entity
                            if (!TrackedEntityTypes.ContainsKey(type))
                            {
                                TrackedEntityTypes.Add(type, new List <Type>());
                            }
                            TrackedEntityTypes[type].AddRange(TrackedEntityTypes.TryGetValue(trackedAsType, out List <Type> list) ? list : new List <Type>());
                        }
                    }
                    else if (typeof(Component).IsAssignableFrom(type))
                    {
                        if (!type.IsAbstract)
                        {
                            // this is an component. copy the registered types for the target component
                            if (!TrackedComponentTypes.ContainsKey(type))
                            {
                                TrackedComponentTypes.Add(type, new List <Type>());
                            }
                            TrackedComponentTypes[type].AddRange(TrackedComponentTypes.TryGetValue(trackedAsType, out List <Type> list) ? list : new List <Type>());
                        }
                    }
                    else
                    {
                        // this is neither an entity nor a component. Help!
                        throw new Exception("Type '" + type.Name + "' cannot be TrackedAs because it does not derive from Entity or Component");
                    }
                }
            }
        }
Пример #6
0
        public void NoTablesInAssemblyLeavesEmptyProperties()
        {
            var assembly = new FakeAssembly
            {
                TypesToReturn = new[]
                {
                    typeof(DateTime),
                }
            };

            StubDataSource.Assembly = assembly;

            var sut = new StubDataSource();

            sut.SetApplicationEnvironment(applicationEnvironment);

            Assert.IsFalse(sut.DataTables.Any());
            Assert.IsFalse(sut.MetadataTables.Any());
        }
Пример #7
0
        public static Type EntityNameToType(string entityName)
        {
            // see if this is just a type name
            Type ret = FakeAssembly.GetFakeEntryAssembly().GetType(entityName, false, true);

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

            if (entityNameToType is null)
            {
                CreateCache();
            }

            if (entityNameToType.TryGetValue(entityName, out ret))
            {
                return(ret);
            }

            throw new Exception($"Unknown entity name: {entityName}.");
        }
Пример #8
0
        private static void CreateCache()
        {
            entityNameToType = new Dictionary <string, Type>()
            {
                ["checkpoint"]             = typeof(Checkpoint),
                ["jumpThru"]               = typeof(JumpthruPlatform),
                ["refill"]                 = typeof(Refill),
                ["infiniteStar"]           = typeof(FlyFeather),
                ["strawberry"]             = typeof(Strawberry),
                ["memorialTextController"] = typeof(Strawberry),
                ["goldenBerry"]            = typeof(Strawberry),
                ["summitgem"]              = typeof(SummitGem),
                ["blackGem"]               = typeof(HeartGem),
                ["dreamHeartGem"]          = typeof(DreamHeartGem),
                ["spring"]                 = typeof(Spring),
                ["wallSpringLeft"]         = typeof(Spring),
                ["wallSpringRight"]        = typeof(Spring),
                ["fallingBlock"]           = typeof(FallingBlock),
                ["zipMover"]               = typeof(ZipMover),
                ["crumbleBlock"]           = typeof(CrumblePlatform),
                ["dreamBlock"]             = typeof(DreamBlock),
                ["touchSwitch"]            = typeof(TouchSwitch),
                ["switchGate"]             = typeof(SwitchGate),
                ["negaBlock"]              = typeof(NegaBlock),
                ["key"]                         = typeof(Key),
                ["lockBlock"]                   = typeof(LockBlock),
                ["movingPlatform"]              = typeof(MovingPlatform),
                ["rotatingPlatforms"]           = typeof(RotatingPlatform),
                ["blockField"]                  = typeof(BlockField),
                ["cloud"]                       = typeof(Cloud),
                ["booster"]                     = typeof(Booster),
                ["moveBlock"]                   = typeof(MoveBlock),
                ["light"]                       = typeof(PropLight),
                ["switchBlock"]                 = typeof(SwapBlock),
                ["swapBlock"]                   = typeof(SwapBlock),
                ["dashSwitchH"]                 = typeof(DashSwitch),
                ["dashSwitchV"]                 = typeof(DashSwitch),
                ["templeGate"]                  = typeof(TempleGate),
                ["torch"]                       = typeof(Torch),
                ["templeCrackedBlock"]          = typeof(TempleCrackedBlock),
                ["seekerBarrier"]               = typeof(SeekerBarrier),
                ["theoCrystal"]                 = typeof(TheoCrystal),
                ["glider"]                      = typeof(Glider),
                ["theoCrystalPedestal"]         = typeof(TheoCrystalPedestal),
                ["badelineBoost"]               = typeof(BadelineBoost),
                ["cassette"]                    = typeof(Cassette),
                ["cassetteBlock"]               = typeof(CassetteBlock),
                ["wallBooster"]                 = typeof(WallBooster),
                ["bounceBlock"]                 = typeof(BounceBlock),
                ["coreModeToggle"]              = typeof(CoreModeToggle),
                ["iceBlock"]                    = typeof(IceBlock),
                ["fireBarrier"]                 = typeof(FireBarrier),
                ["eyebomb"]                     = typeof(Puffer),
                ["flingBird"]                   = typeof(FlingBird),
                ["flingBirdIntro"]              = typeof(FlingBirdIntro),
                ["birdPath"]                    = typeof(BirdPath),
                ["lightningBlock"]              = typeof(Lightning),
                ["spikesUp"]                    = typeof(Spikes),
                ["spikesDown"]                  = typeof(Spikes),
                ["spikesLeft"]                  = typeof(Spikes),
                ["spikesRight"]                 = typeof(Spikes),
                ["triggerSpikesUp"]             = typeof(TriggerSpikes),
                ["triggerSpikesDown"]           = typeof(TriggerSpikes),
                ["triggerSpikesRight"]          = typeof(TriggerSpikes),
                ["triggerSpikesLeft"]           = typeof(TriggerSpikes),
                ["darkChaser"]                  = typeof(BadelineOldsite),
                ["rotateSpinner"]               = typeof(BladeRotateSpinner),
                ["trackSpinner"]                = typeof(TrackSpinner),
                ["spinner"]                     = typeof(CrystalStaticSpinner),
                ["sinkingPlatform"]             = typeof(SinkingPlatform),
                ["friendlyGhost"]               = typeof(AngryOshiro),
                ["seeker"]                      = typeof(Seeker),
                ["seekerStatue"]                = typeof(SeekerStatue),
                ["slider"]                      = typeof(Slider),
                ["templeBigEyeball"]            = typeof(TempleBigEyeball),
                ["crushBlock"]                  = typeof(CrushBlock),
                ["bigSpinner"]                  = typeof(Bumper),
                ["starJumpBlock"]               = typeof(StarJumpBlock),
                ["floatySpaceBlock"]            = typeof(FloatySpaceBlock),
                ["glassBlock"]                  = typeof(GlassBlock),
                ["goldenBlock"]                 = typeof(GoldenBlock),
                ["fireBall"]                    = typeof(FireBall),
                ["risingLava"]                  = typeof(RisingLava),
                ["sandwichLava"]                = typeof(SandwichLava),
                ["killbox"]                     = typeof(Killbox),
                ["fakeHeart"]                   = typeof(FakeHeart),
                ["lightning"]                   = typeof(Lightning),
                ["finalBoss"]                   = typeof(FinalBoss),
                ["finalBossFallingBlock"]       = typeof(FallingBlock),
                ["finalBossMovingBlock"]        = typeof(FinalBossMovingBlock),
                ["fakeWall"]                    = typeof(FakeWall),
                ["fakeBlock"]                   = typeof(FakeWall),
                ["dashBlock"]                   = typeof(DashBlock),
                ["invisibleBarrier"]            = typeof(InvisibleBarrier),
                ["exitBlock"]                   = typeof(ExitBlock),
                ["conditionBlock"]              = typeof(ExitBlock),
                ["coverupWall"]                 = typeof(CoverupWall),
                ["crumbleWallOnRumble"]         = typeof(CrumbleWallOnRumble),
                ["ridgeGate"]                   = typeof(RidgeGate),
                ["tentacles"]                   = typeof(Tentacles),
                ["starClimbController"]         = typeof(StarClimbGraphicsController),
                ["playerSeeker"]                = typeof(PlayerSeeker),
                ["chaserBarrier"]               = typeof(ChaserBarrier),
                ["introCrusher"]                = typeof(IntroCrusher),
                ["bridge"]                      = typeof(Bridge),
                ["bridgeFixed"]                 = typeof(BridgeFixed),
                ["bird"]                        = typeof(BirdNPC),
                ["introCar"]                    = typeof(IntroCar),
                ["memorial"]                    = typeof(Memorial),
                ["wire"]                        = typeof(Wire),
                ["cobweb"]                      = typeof(Cobweb),
                ["lamp"]                        = typeof(Lamp),
                ["hanginglamp"]                 = typeof(HangingLamp),
                ["hahaha"]                      = typeof(Hahaha),
                ["bonfire"]                     = typeof(Bonfire),
                ["payphone"]                    = typeof(Payphone),
                ["colorSwitch"]                 = typeof(ClutterSwitch),
                ["clutterDoor"]                 = typeof(ClutterDoor),
                ["dreammirror"]                 = typeof(DreamMirror),
                ["resortmirror"]                = typeof(ResortMirror),
                ["towerviewer"]                 = typeof(Lookout),
                ["picoconsole"]                 = typeof(PicoConsole),
                ["wavedashmachine"]             = typeof(WaveDashTutorialMachine),
                ["yellowBlocks"]                = typeof(ClutterBlockBase),
                ["redBlocks"]                   = typeof(ClutterBlockBase),
                ["greenBlocks"]                 = typeof(ClutterBlockBase),
                ["oshirodoor"]                  = typeof(MrOshiroDoor),
                ["templeMirrorPortal"]          = typeof(TempleMirrorPortal),
                ["reflectionHeartStatue"]       = typeof(ReflectionHeartStatue),
                ["resortRoofEnding"]            = typeof(ResortRoofEnding),
                ["gondola"]                     = typeof(Gondola),
                ["birdForsakenCityGem"]         = typeof(ForsakenCitySatellite),
                ["whiteblock"]                  = typeof(WhiteBlock),
                ["plateau"]                     = typeof(Plateau),
                ["soundSource"]                 = typeof(SoundSource),
                ["templeMirror"]                = typeof(TempleMirror),
                ["templeEye"]                   = typeof(TempleEye),
                ["clutterCabinet"]              = typeof(ClutterCabinet),
                ["floatingDebris"]              = typeof(FloatingDebris),
                ["foregroundDebris"]            = typeof(ForegroundDebris),
                ["moonCreature"]                = typeof(MoonCreature),
                ["lightbeam"]                   = typeof(LightBeam),
                ["door"]                        = typeof(Door),
                ["trapdoor"]                    = typeof(Trapdoor),
                ["resortLantern"]               = typeof(ResortLantern),
                ["water"]                       = typeof(Water),
                ["waterfall"]                   = typeof(WaterFall),
                ["bigWaterfall"]                = typeof(BigWaterfall),
                ["clothesline"]                 = typeof(Clothesline),
                ["cliffflag"]                   = typeof(CliffFlags),
                ["cliffside_flag"]              = typeof(CliffsideWindFlag),
                ["flutterbird"]                 = typeof(FlutterBird),
                ["SoundTest3d"]                 = typeof(_3dSoundTest),
                ["SummitBackgroundManager"]     = typeof(AscendManager),
                ["summitGemManager"]            = typeof(SummitGem),
                ["heartGemDoor"]                = typeof(HeartGemDoor),
                ["summitcheckpoint"]            = typeof(SummitCheckpoint),
                ["summitcloud"]                 = typeof(SummitCloud),
                ["coreMessage"]                 = typeof(CoreMessage),
                ["playbackTutorial"]            = typeof(PlayerPlayback),
                ["playbackBillboard"]           = typeof(PlaybackBillboard),
                ["cutsceneNode"]                = typeof(CutsceneNode),
                ["kevins_pc"]                   = typeof(KevinsPC),
                ["powerSourceNumber"]           = typeof(PowerSourceNumber),
                ["npc"]                         = typeof(NPC),
                ["eventTrigger"]                = typeof(EventTrigger),
                ["musicFadeTrigger"]            = typeof(MusicFadeTrigger),
                ["musicTrigger"]                = typeof(MusicTrigger),
                ["altMusicTrigger"]             = typeof(AltMusicTrigger),
                ["cameraOffsetTrigger"]         = typeof(CameraOffsetTrigger),
                ["lightFadeTrigger"]            = typeof(LightFadeTrigger),
                ["bloomFadeTrigger"]            = typeof(BloomFadeTrigger),
                ["cameraTargetTrigger"]         = typeof(CameraTargetTrigger),
                ["cameraAdvanceTargetTrigger"]  = typeof(CameraAdvanceTargetTrigger),
                ["respawnTargetTrigger"]        = typeof(RespawnTargetTrigger),
                ["changeRespawnTrigger"]        = typeof(ChangeRespawnTrigger),
                ["windTrigger"]                 = typeof(WindTrigger),
                ["windAttackTrigger"]           = typeof(WindAttackTrigger),
                ["minitextboxTrigger"]          = typeof(MiniTextboxTrigger),
                ["oshiroTrigger"]               = typeof(OshiroTrigger),
                ["interactTrigger"]             = typeof(InteractTrigger),
                ["checkpointBlockerTrigger"]    = typeof(CheckpointBlockerTrigger),
                ["lookoutBlocker"]              = typeof(LookoutBlocker),
                ["stopBoostTrigger"]            = typeof(StopBoostTrigger),
                ["noRefillTrigger"]             = typeof(NoRefillTrigger),
                ["ambienceParamTrigger"]        = typeof(AmbienceParamTrigger),
                ["creditsTrigger"]              = typeof(CreditsTrigger),
                ["goldenBerryCollectTrigger"]   = typeof(GoldBerryCollectTrigger),
                ["moonGlitchBackgroundTrigger"] = typeof(MoonGlitchBackgroundTrigger),
                ["blackholeStrength"]           = typeof(BlackholeStrengthTrigger),
                ["rumbleTrigger"]               = typeof(RumbleTrigger),
                ["birdPathTrigger"]             = typeof(BirdPathTrigger),
                ["spawnFacingTrigger"]          = typeof(SpawnFacingTrigger),
                ["detachFollowersTrigger"]      = typeof(DetachStrawberryTrigger),
            };

            foreach (var type in FakeAssembly.GetFakeEntryAssembly().GetTypesSafe())
            {
                checkType(type);
            }

            void checkType(Type type)
            {
                foreach (CustomEntityAttribute customEntityAttribute in type.GetCustomAttributes <CustomEntityAttribute>())
                {
                    foreach (string idFull in customEntityAttribute.IDs)
                    {
                        string   id;
                        string[] split = idFull.Split('=');

                        if (split.Length == 1 || split.Length == 2)
                        {
                            id = split[0];
                        }
                        else
                        {
                            // invalid
                            continue;
                        }

                        string IDTrim = id.Trim();
                        if (!entityNameToType.ContainsKey(IDTrim))
                        {
                            entityNameToType.Add(IDTrim, type);
                        }
                        else
                        {
                            Logger.Log("FrostHelper.TypeHelper", $"Found duplicate entity ID {IDTrim} - {type.FullName} vs {entityNameToType[IDTrim].FullName}");
                        }
                    }
                }
            }
        }
Пример #9
0
 public static Type GetTypeFromString(string name)
 {
     return(FakeAssembly.GetFakeEntryAssembly().GetType(name));
 }
Пример #10
0
        public void WhenAdditionalTableProviderProvidedThenAdditionalTablesAdded()
        {
            var assembly = new FakeAssembly
            {
                TypesToReturn = new[]
                {
                    typeof(DateTime),
                    typeof(StubDataTableOne),
                    typeof(StubMetadataTableOne),
                    typeof(Exception),
                }
            };

            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubDataTableOne),
                    serializer,
                    out TableDescriptor expectedDescriptor1));
            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubDataTableTwo),
                    serializer,
                    out TableDescriptor expectedDescriptor2));
            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubDataTableThree),
                    serializer,
                    out TableDescriptor expectedDescriptor3));

            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubMetadataTableOne),
                    serializer,
                    out TableDescriptor expectedDescriptor4));
            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubMetadataTableTwo),
                    serializer,
                    out TableDescriptor expectedDescriptor5));

            StubDataSource.Assembly = assembly;

            bool descriptor2BuildWasCalled = false;
            bool descriptor3BuildWasCalled = false;
            bool descriptor5BuildWasCalled = false;

            var additionalTables = new Dictionary <TableDescriptor, Action <ITableBuilder, IDataExtensionRetrieval> >
            {
                { expectedDescriptor2, (tableBuilder, cookedData) => { descriptor2BuildWasCalled = true; } },
                { expectedDescriptor3, (tableBuilder, cookedData) => { descriptor3BuildWasCalled = true; } },
                { expectedDescriptor5, (tableBuilder, cookedData) => { descriptor5BuildWasCalled = true; } },
            };

            var sut = new StubDataSource(() => additionalTables);

            sut.SetApplicationEnvironment(applicationEnvironment);

            Assert.AreEqual(5, sut.AllTablesExposed.Count);

            // call the build action of each of our tables
            foreach (var kvp in sut.AllTablesExposed)
            {
                kvp.Value.Invoke(null, null);
            }

            Assert.IsTrue(StubDataTableOne.BuildTableWasCalled);
            Assert.IsTrue(descriptor2BuildWasCalled);
            Assert.IsTrue(descriptor3BuildWasCalled);
            Assert.IsTrue(StubMetadataTableOne.BuildTableWasCalled);
            Assert.IsTrue(descriptor5BuildWasCalled);
        }
Пример #11
0
        public void AllTablesIsUnionOfDataAndMetadata()
        {
            var assembly = new FakeAssembly
            {
                TypesToReturn = new[]
                {
                    typeof(DateTime),
                    typeof(StubDataTableOne),
                    typeof(StubDataTableTwo),
                    typeof(StubDataTableThree),
                    typeof(StubMetadataTableOne),
                    typeof(StubMetadataTableTwo),
                    typeof(Exception),
                }
            };

            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubDataTableOne),
                    serializer,
                    out TableDescriptor expectedDescriptor1));
            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubDataTableTwo),
                    serializer,
                    out TableDescriptor expectedDescriptor2));
            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubDataTableThree),
                    serializer,
                    out TableDescriptor expectedDescriptor3));

            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubMetadataTableOne),
                    serializer,
                    out TableDescriptor expectedDescriptor4));
            Assert.IsTrue(
                TableDescriptorFactory.TryCreate(
                    typeof(StubMetadataTableTwo),
                    serializer,
                    out TableDescriptor expectedDescriptor5));

            StubDataSource.Assembly = assembly;

            var sut = new StubDataSource();

            sut.SetApplicationEnvironment(applicationEnvironment);

            Assert.AreEqual(5, sut.AllTablesExposed.Count);

            // call the build action of each of our tables
            foreach (var kvp in sut.AllTablesExposed)
            {
                kvp.Value.Invoke(null, null);
            }

            Assert.IsTrue(StubDataTableOne.BuildTableWasCalled);
            Assert.IsTrue(StubDataTableTwo.BuildTableWasCalled);
            Assert.IsTrue(StubDataTableThree.BuildTableWasCalled);
            Assert.IsTrue(StubMetadataTableOne.BuildTableWasCalled);
            Assert.IsTrue(StubMetadataTableTwo.BuildTableWasCalled);
        }
Пример #12
0
 public static Type GetTypeFromString(string name, string prefix = "Celeste.")
 {
     return(FakeAssembly.GetFakeEntryAssembly().GetType(prefix + name));
 }