66using System . Linq ;
77using System ;
88using BepInEx . Configuration ;
9+ using MiniMapMod . Adapters ;
10+ using MiniMapLibrary . Interfaces ;
911
1012namespace MiniMapMod
1113{
@@ -24,41 +26,23 @@ public class MiniMapPlugin : BaseUnityPlugin
2426
2527 private bool ScannedStaticObjects = false ;
2628
27- private readonly Dictionary < InteractableKind , ConfigEntry < bool > > ScanOptions = new ( ) ;
28-
29- private readonly Dictionary < InteractableKind , string > InteractibleKindDescriptions = new ( ) ;
29+ private IConfig config ;
3030
3131 public void Awake ( )
3232 {
3333 Log . Init ( Logger ) ;
3434
35- InteractibleKindDescriptions . Add ( InteractableKind . Chest , "Chests, including shops" ) ;
36- InteractibleKindDescriptions . Add ( InteractableKind . Utility , "Scrappers" ) ;
37- InteractibleKindDescriptions . Add ( InteractableKind . Teleporter , "Boss teleporter" ) ;
38- InteractibleKindDescriptions . Add ( InteractableKind . Shrine , "All shrines (excluding Newt)" ) ;
39- InteractibleKindDescriptions . Add ( InteractableKind . Special , "Special interactibles such as the landing pod" ) ;
40- InteractibleKindDescriptions . Add ( InteractableKind . Player , "Players" ) ;
41- InteractibleKindDescriptions . Add ( InteractableKind . Drone , "Drones" ) ;
42- InteractibleKindDescriptions . Add ( InteractableKind . Barrel , "Barrels" ) ;
43- InteractibleKindDescriptions . Add ( InteractableKind . Enemy , "Enemies" ) ;
44- InteractibleKindDescriptions . Add ( InteractableKind . Printer , "Printers" ) ;
45- InteractibleKindDescriptions . Add ( InteractableKind . LunarPod , "Lunar pods (chests)" ) ;
35+ config = new ConfigAdapter ( this . Config ) ;
4636
4737 // bind options
4838 InteractableKind [ ] kinds = Enum . GetValues ( typeof ( InteractableKind ) ) . Cast < InteractableKind > ( ) . Where ( x=> x != InteractableKind . none && x != InteractableKind . All ) . ToArray ( ) ;
4939
50- for ( int i = 0 ; i < kinds . Length ; i ++ )
40+ foreach ( var item in kinds )
5141 {
52- InteractableKind kind = kinds [ i ] ;
53-
54- ScanOptions . Add ( kind , Config . Bind < bool > ( $ "Icon.{ kind } ", "enabled" , true , $ "Whether or { InteractibleKindDescriptions [ kind ] } should be shown on the minimap.") ) ;
55-
56- ConfigEntry < Color > activeColor = Config . Bind < Color > ( $ "Icon.{ kind } ", "activeColor" , Settings . GetColor ( kind , true ) , "The color the icon should be when it has not been interacted with" ) ;
57- ConfigEntry < Color > inactiveColor = Config . Bind < Color > ( $ "Icon.{ kind } ", "inactiveColor" , Settings . GetColor ( kind , false ) , "The color the icon should be when it has used/bought" ) ;
58- ConfigEntry < float > iconWidth = Config . Bind < float > ( $ "Icon.{ kind } ", "width" , Settings . GetInteractableSize ( kind ) . Width , "Width of the icon" ) ;
59- ConfigEntry < float > iconHeight = Config . Bind < float > ( $ "Icon.{ kind } ", "height" , Settings . GetInteractableSize ( kind ) . Height , "Width of the icon" ) ;
60-
61- Settings . UpdateSetting ( kind , iconWidth . Value , iconHeight . Value , activeColor . Value , inactiveColor . Value ) ;
42+ Settings . LoadConfigEntries ( item , config ) ;
43+
44+ InteractibleSetting setting = Settings . GetSetting ( item ) ;
45+ Log . LogInfo ( $ "MINIMAP: Loaded { item } config [{ ( setting . Config . Enabled . Value ? "enabled" : "disabled" ) } , { setting . ActiveColor } , { setting . InactiveColor } , ({ setting . Dimensions . Width } x{ setting . Dimensions . Height } )]") ;
6246 }
6347
6448 Log . LogInfo ( "MINIMAP: Creating scene scan hooks" ) ;
@@ -182,6 +166,8 @@ private void Reset()
182166 TrackedObjects . Clear ( ) ;
183167 TrackedDimensions . Clear ( ) ;
184168 Minimap . Destroy ( ) ;
169+
170+ // mark the scene as scannable again so we scan for chests etc..
185171 ScannedStaticObjects = false ;
186172 }
187173
@@ -196,17 +182,24 @@ private void ScanScene()
196182
197183 private void ScanStaticTypes ( )
198184 {
185+ // if we have alreadys scanned don't scan again until we die or the scene changes (this method has sever performance implications)
199186 if ( ScannedStaticObjects )
200187 {
201188 return ;
202189 }
203190
204- RegisterMonobehaviorType < ChestBehavior > ( InteractableKind . Chest , dynamicObject : false , selector : chest => chest . GetComponent < PurchaseInteraction > ( ) . contextToken != "LUNAR_CHEST_CONTEXT" ) ;
191+ // NON lunar pods
192+ RegisterMonobehaviorType < ChestBehavior > ( InteractableKind . Chest , dynamicObject : false ,
193+ selector : chest => chest . GetComponent < PurchaseInteraction > ( ) . contextToken != "LUNAR_CHEST_CONTEXT" ) ;
205194
206- RegisterMonobehaviorType < ChestBehavior > ( InteractableKind . LunarPod , dynamicObject : false , selector : chest => chest . GetComponent < PurchaseInteraction > ( ) . contextToken == "LUNAR_CHEST_CONTEXT" ) ;
195+ // lunar pods
196+ RegisterMonobehaviorType < ChestBehavior > ( InteractableKind . LunarPod , dynamicObject : false ,
197+ selector : chest => chest . GetComponent < PurchaseInteraction > ( ) . contextToken == "LUNAR_CHEST_CONTEXT" ) ;
207198
199+ // adapative chests
208200 RegisterMonobehaviorType < RouletteChestController > ( InteractableKind . Chest , dynamicObject : false ) ;
209201
202+ // shrines
210203 RegisterMonobehaviorType < ShrineBloodBehavior > ( InteractableKind . Shrine , dynamicObject : false ) ;
211204
212205 RegisterMonobehaviorType < ShrineChanceBehavior > ( InteractableKind . Shrine , dynamicObject : false ) ;
@@ -220,21 +213,29 @@ private void ScanStaticTypes()
220213 RegisterMonobehaviorType < ShrineRestackBehavior > ( InteractableKind . Shrine , dynamicObject : false ) ;
221214
222215 // normal shops
223- RegisterMonobehaviorType < ShopTerminalBehavior > ( InteractableKind . Chest , dynamicObject : false , selector : shop => shop . GetComponent < PurchaseInteraction > ( ) . contextToken != "DUPLICATOR_CONTEXT" ) ;
216+ RegisterMonobehaviorType < ShopTerminalBehavior > ( InteractableKind . Chest , dynamicObject : false ,
217+ selector : shop => shop . GetComponent < PurchaseInteraction > ( ) . contextToken != "DUPLICATOR_CONTEXT" ) ;
224218
225219 // duplicators
226- RegisterMonobehaviorType < ShopTerminalBehavior > ( InteractableKind . Printer , dynamicObject : false , selector : shop => shop . GetComponent < PurchaseInteraction > ( ) . contextToken == "DUPLICATOR_CONTEXT" ) ;
220+ RegisterMonobehaviorType < ShopTerminalBehavior > ( InteractableKind . Printer , dynamicObject : false ,
221+ selector : shop => shop . GetComponent < PurchaseInteraction > ( ) . contextToken == "DUPLICATOR_CONTEXT" ) ;
227222
223+ // barrels
228224 RegisterMonobehaviorType < BarrelInteraction > ( InteractableKind . Barrel , barrel => ! barrel . Networkopened , dynamicObject : false ) ;
229225
226+ // scrapper
230227 RegisterMonobehaviorType < ScrapperController > ( InteractableKind . Utility , dynamicObject : false ) ;
231228
229+ // random stuff like the exploding backpack door on the landing pod
232230 RegisterMonobehaviorType < GenericInteraction > ( InteractableKind . Special , dynamicObject : false ) ;
233231
232+ // boss teleporter
234233 RegisterMonobehaviorType < TeleporterInteraction > ( InteractableKind . Teleporter , ( teleporter ) => teleporter . activationState != TeleporterInteraction . ActivationState . Charged , dynamicObject : false ) ;
235234
235+ // drones
236236 RegisterMonobehaviorType < SummonMasterBehavior > ( InteractableKind . Drone , dynamicObject : false ) ;
237237
238+ // make sure we only do this once per scene
238239 ScannedStaticObjects = true ;
239240 }
240241
@@ -265,7 +266,7 @@ private void ClearDynamicTrackedObjects()
265266 private void RegisterMonobehaviorType < T > ( InteractableKind kind , Func < T , bool > ActiveChecker = null , bool dynamicObject = true , Func < T , bool > selector = null ) where T : MonoBehaviour
266267 {
267268 // check to see if it's enabled in the config
268- if ( ScanOptions [ kind ] . Value == false )
269+ if ( Settings . GetSetting ( kind ) . Config . Enabled . Value == false )
269270 {
270271 return ;
271272 }
0 commit comments