forked from wofsauge/External-Item-Descriptions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
1745 lines (1584 loc) · 69.6 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
EID = RegisterMod("External Item Descriptions", 1)
-- important variables
EID.GameVersion = "ab+"
EID.Languages = {"en_us", "en_us_detailed", "fr", "pt", "pt_br", "ru", "spa", "it", "bul", "pl", "de", "tr_tr", "ko_kr", "zh_cn", "ja_jp", "cs_cz"}
EID.descriptions = {} -- Table that holds all translation strings
EID.enableDebug = false
local game = Game()
require("eid_config")
EID.Config = EID.UserConfig
EID.Config.Version = "3.2" -- note: changing this will reset everyone's settings to default!
EID.ModVersion = "4.41"
EID.DefaultConfig.Version = EID.Config.Version
EID.isHidden = false
EID.player = nil -- The primary Player Entity of Player 1
EID.players = {} -- Both Player Entities of Player 1 if applicable (includes Esau, T.Forgotten)
EID.coopMainPlayers = {} -- The primary Player Entity for each controller being used
EID.coopAllPlayers = {} -- Every Player Entity (includes Esau, T.Forgotten)
EID.controllerIndexes = {} -- A table to map each controller index to their player number for coloring indicators
EID.isMultiplayer = false -- Used to color P1's highlight/outline indicators (single player just uses white)
EID.BoC = {}
-- general variables
EID.PositionModifiers = {}
EID.DescModifiers = {}
EID.UsedPosition = Vector(EID.Config["XPosition"], EID.Config["YPosition"])
EID.Scale = EID.Config["Size"]
EID.isDisplaying = false
EID.isDisplayingPermanent = false
EID.permanentDisplayTextObj = nil
EID.lastDescriptionEntity = nil
EID.lineHeight = 11
EID.itemConfig = Isaac.GetItemConfig()
EID.itemUnlockStates = {}
EID.CraneItemType = {}
EID.absorbedItems = {}
EID.CollectedItems = {}
EID.IgnoredEntities = {}
EID.CurrentRoomGridEntities = {}
EID.UnidentifyablePillEffects = {} -- List of pilleffects that are always unidentifyable
EID.UsedPillColors = {} -- Colors of pills that have been eaten during this game
local pathsChecked = {}
local altPathItemChecked = {}
local alwaysUseLocalMode = false -- set to true after drawing a non-local mode description this frame
EID.ForceRefreshCache = false -- set to true to force-refresh descriptions, currently used for potential transformation text changes
EID.holdTabPlayer = 0
EID.holdTabCounter = 0
EID.DInfinityState = {}
local forgottenDropTimer = 0
EID.GameUpdateCount = 0
EID.GameRenderCount = 0
-- Sprite inits
EID.IconSprite = Sprite()
EID.IconSprite:Load("gfx/eid_transform_icons.anm2", true)
EID.InlineIconSprite = Sprite()
EID.InlineIconSprite:Load("gfx/eid_inline_icons.anm2", true)
EID.InlineIconSprite2 = Sprite()
EID.InlineIconSprite2:Load("gfx/eid_inline_icons.anm2", true)
EID.CardPillSprite = Sprite()
EID.CardPillSprite:Load("gfx/eid_cardspills.anm2", true)
EID.ItemSprite = Sprite()
EID.ItemSprite:Load("gfx/005.100_collectible.anm2", true)
EID.PlayerSprite = Sprite()
EID.PlayerSprite:Load("gfx/eid_player_icons.anm2", true)
local ArrowSprite = Sprite()
ArrowSprite:Load("gfx/eid_transform_icons.anm2", true)
ArrowSprite:Play("Arrow", false)
EID.CursorSprite = Sprite()
EID.CursorSprite:Load("gfx/eid_transform_icons.anm2", true)
EID.CursorSprite:Play("Cursor")
local hudBBSprite = Sprite()
hudBBSprite:Load("gfx/eid_transform_icons.anm2", true)
hudBBSprite:Play("boundingBox")
EID.ModIndicator = { }
-- Overwriting "RegisterMod" to track which mods are loading
-- Useful to associate items to mods
EID._currentMod = ""
local OldRegisterMod = RegisterMod
RegisterMod = function (modName, apiVersion, ...)
EID._currentMod = modName
EID.ModIndicator[modName] = { Name = modName, Icon = nil }
return OldRegisterMod(modName, apiVersion, ...)
end
------- Load all modules and other stuff ------
--transformation infos
require("descriptions."..EID.GameVersion..".transformations")
--languages
for _,lang in ipairs(EID.Languages) do
require("descriptions."..EID.GameVersion.."."..lang)
end
table.sort(EID.Languages)
pcall(require,"scripts.eid_savegames")
require("eid_mcm")
require("eid_data")
require("eid_xmldata")
require("eid_api")
require("eid_modifiers")
require("eid_holdmapdesc")
require("eid_itemprediction")
-- load Repentence descriptions
if REPENTANCE then
EID.GameVersion = "rep"
for _,lang in ipairs(EID.Languages) do
local wasSuccessful, err = pcall(require,"descriptions."..EID.GameVersion.."."..lang)
if not wasSuccessful and not string.find(err, "not found") then
Isaac.ConsoleOutput("Load rep "..lang.." failed: "..tostring(err))
end
end
local wasSuccessful, _ = pcall(require,"descriptions."..EID.GameVersion..".transformations")
require("eid_bagofcrafting")
end
EID.LastRenderCallColor = EID:getTextColor()
local nullVector = Vector(0,0)
---------------------------------------------------------------------------
------------------------------- Load Font ---------------------------------
local modfolder ='external item descriptions_836319872' --release mod folder name
local function GetCurrentModPath()
if debug then
if REPENTANCE then require("eid_tmtrainer") end
return string.sub(debug.getinfo(GetCurrentModPath).source,2) .. "/../"
end
--use some very hacky trickery to get the path to this mod
local _, err = pcall(require, "")
local _, basePathStart = string.find(err, "no file '", 1)
local _, modPathStart = string.find(err, "no file '", basePathStart)
local modPathEnd, _ = string.find(err, ".lua'", modPathStart)
local modPath = string.sub(err, modPathStart+1, modPathEnd-1)
modPath = string.gsub(modPath, "\\", "/")
modPath = string.gsub(modPath, "//", "/")
modPath = string.gsub(modPath, ":/", ":\\")
return modPath
end
EID.modPath = GetCurrentModPath()
EID.font = Font() -- init font object
EID:fixDefinedFont()
local fontFile = EID.Config["FontType"] or "default"
local success = EID:loadFont(EID.modPath .. "resources/font/eid_"..fontFile..".fnt")
if not success then
if REPENTANCE then
success = EID:loadFont("../mods/"..modfolder.."/resources/font/eid_"..fontFile..".fnt")
if not success then
Isaac.ConsoleOutput("EID WAS NOT ABLE TO LOAD THE FONT!!!!!!!! Please contact the mod creator!\n")
Isaac.ConsoleOutput("File not found (absolute path): "..EID.modPath .. "resources/font/eid_"..fontFile..".fnt\n")
Isaac.ConsoleOutput("File not found (relative path): ../mods/"..modfolder.."/resources/font/eid_"..fontFile..".fnt")
return
else
EID.modPath = "../mods/"..modfolder.."/"
end
else
Isaac.ConsoleOutput("EID WAS NOT ABLE TO LOAD THE FONT!!!!!!!! Please contact the mod creator!\n")
Isaac.ConsoleOutput("File does not exist: "..EID.modPath .. "resources/font/eid_"..fontFile..".fnt")
return
end
end
---------------------------------------------------------------------------
-------------Handle Resetting Floor Trackers--------------
function EID:onNewFloor()
pathsChecked = {}
if REPENTANCE then
EID.BoC.RoomQueries = {}
EID.BoC.FloorQuery = {}
EID.CraneItemType = {}
EID.flipItemPositions = {}
altPathItemChecked = {}
end
end
EID:AddCallback(ModCallbacks.MC_POST_NEW_LEVEL, EID.onNewFloor)
---------------------------------------------------------------------------
------------------------Handle ALT FLOOR CHOICE----------------------------
local questionMarkSprite = Sprite()
questionMarkSprite:Load("gfx/005.100_collectible.anm2",true)
questionMarkSprite:ReplaceSpritesheet(1,"gfx/items/collectibles/questionmark.png")
questionMarkSprite:LoadGraphics()
function EID:IsAltChoice(pickup)
-- do not run this while Curse of the Blind is active, since this function is really just a "is collectible pedestal a red question mark" check
if not REPENTANCE or EID:hasCurseBlind() then
return false
end
if altPathItemChecked[pickup.InitSeed] ~= nil then
return altPathItemChecked[pickup.InitSeed]
end
if game:GetRoom():GetType() ~= RoomType.ROOM_TREASURE then
altPathItemChecked[pickup.InitSeed] = false
return false
end
local entitySprite = pickup:GetSprite()
local name = entitySprite:GetAnimation()
if name ~= "Idle" and name ~= "ShopIdle" then
-- Collectible can be ignored. It's definitely not hidden
altPathItemChecked[pickup.InitSeed] = false
return false
end
questionMarkSprite:SetFrame(name,entitySprite:GetFrame())
-- Quickly check some points in entitySprite to not need to check the whole sprite
-- We check the range from Y -40 to 10 in 3 pixel steps and also X -1 to 1. GetTexel() gets the color value of a sprite at a given location. the center of the sprite is here in the Pivot point of the sprite in the anm2 file.
-- therefore we go negative 40 pixels up to read the sprite as it is on a pedestal. We also look 10 pixel down to make comparing shop items more accurate
for i = -1,1,1 do
for j = -40,10,3 do
local qcolor = questionMarkSprite:GetTexel(Vector(i,j),nullVector,1,1)
local ecolor = entitySprite:GetTexel(Vector(i,j),nullVector,1,1)
if qcolor.Red ~= ecolor.Red or qcolor.Green ~= ecolor.Green or qcolor.Blue ~= ecolor.Blue then
-- it is not same with question mark sprite
altPathItemChecked[pickup.InitSeed] = false
return false
end
end
end
altPathItemChecked[pickup.InitSeed] = true
return true
end
---------------------------------------------------------------------------
-----------------Handle Crane Game & Flip Item Callbacks-------------------
local initialItemNext = false
local flipItemNext = false
if REPENTANCE then
EID.flipItemPositions = {}
EID.flipMaxIndex = -1
local lastGetItemResult = {nil, nil, nil, nil} -- itemID, Frame, gridIndex, InitSeed
local lastFrameGridChecked = 0
function EID:postGetCollectible(selectedCollectible, itemPoolType, decrease, seed)
-- Handle Crane Game
if itemPoolType == ItemPoolType.POOL_CRANE_GAME then
for _, crane in ipairs(Isaac.FindByType(6, 16, -1, true, false)) do
if not crane:GetSprite():IsPlaying("Broken") then
if not EID.CraneItemType[tostring(crane.InitSeed)] then
EID.CraneItemType[tostring(crane.InitSeed)] = selectedCollectible
break
end
end
end
end
-- Handle Flip item
-- PRE_ROOM_ENTITY_SPAWN sets us up to watch for the first POST_GET_COLLECTIBLE for this pedestal
-- (Tainted Isaac and Glitched Crown cause additional calls that have to be ignored)
-- POST_PICKUP_INIT occurs right before the Flip item is decided, so it sets us up to watch for the Flip item
-- (it also watches for item rerolls to fill the new entity's GetData)
-- POST_NEW_ROOM then handles putting the result in the entity's GetData
local curFrame = Isaac.GetFrameCount()
local curRoomIndex = game:GetLevel():GetCurrentRoomDesc().ListIndex
if curFrame == lastGetItemResult[2] then
if initialItemNext then lastGetItemResult[1] = selectedCollectible
elseif flipItemNext and lastGetItemResult[1] then
if EID.flipItemPositions[curRoomIndex] == nil then
EID.flipItemPositions[curRoomIndex] = {}
end
EID.flipItemPositions[curRoomIndex][lastGetItemResult[4]] = {selectedCollectible, lastGetItemResult[3]}
end
end
initialItemNext = false
flipItemNext = false
end
EID:AddCallback(ModCallbacks.MC_POST_GET_COLLECTIBLE, EID.postGetCollectible)
-- Handle Flip Item spawn
function EID:preRoomEntitySpawn(entityType, variant, subtype, gridIndex, seed)
flipItemNext = false
if entityType == 6 and variant == 14 then
-- Inner Child pedestal
lastGetItemResult = {688, Isaac.GetFrameCount(), gridIndex, nil}
elseif entityType == 5 then
lastGetItemResult = {nil, Isaac.GetFrameCount(), gridIndex, nil}
-- Pedestals in need of a random item will call GET_COLLECTIBLE; fixed pedestals (Knife Piece 1) will not
if subtype == 0 then initialItemNext = true
else lastGetItemResult[1] = subtype end
end
end
EID:AddCallback(ModCallbacks.MC_PRE_ROOM_ENTITY_SPAWN, EID.preRoomEntitySpawn)
function EID:postPickupInitFlip(entity)
initialItemNext = false
flipItemNext = true
lastGetItemResult[4] = entity.InitSeed
local curRoomIndex = game:GetLevel():GetCurrentRoomDesc().ListIndex
local gridPos = game:GetRoom():GetGridIndex(entity.Position)
-- Update a Flip item's init seed after D6 rerolls or using Flip (aka Grid Index didn't change, Init Seed did)
if EID.flipItemPositions[curRoomIndex] and not EID.flipItemPositions[curRoomIndex][entity.InitSeed] then
-- Check if any Flip pedestals have changed grid indexes (fixes bugs with Greed shops)
if lastFrameGridChecked ~= Isaac.GetFrameCount() then EID:CheckFlipGridIndexes() end
for k,v in pairs(EID.flipItemPositions[curRoomIndex]) do
if v[2] == gridPos then
EID.flipItemPositions[curRoomIndex][entity.InitSeed] = v
EID.flipItemPositions[curRoomIndex][k] = nil
break
end
end
end
-- Give this new entity its Flip Item data if possible
local flipEntry = EID.flipItemPositions[curRoomIndex] and EID.flipItemPositions[curRoomIndex][entity.InitSeed]
if flipEntry then
entity:GetData()["EID_FlipItemID"] = flipEntry[1]
end
end
EID:AddCallback(ModCallbacks.MC_POST_PICKUP_INIT, EID.postPickupInitFlip, PickupVariant.PICKUP_COLLECTIBLE)
function EID:CheckPedestalIndex(entity)
-- Only pedestals with indexes that were present at room load can be flip pedestals
-- Fixes shop restock machines and Diplopia... mostly. At least while you're in the room.
if entity:GetData()["EID_FlipItemID"] and entity.Index > EID.flipMaxIndex then
local curRoomIndex = game:GetLevel():GetCurrentRoomDesc().ListIndex
local gridPos = game:GetRoom():GetGridIndex(entity.Position)
local flipEntry = EID.flipItemPositions[curRoomIndex] and EID.flipItemPositions[curRoomIndex][entity.InitSeed]
-- only wipe the data if the grid index matches (so Diplopia pedestals don't)
if flipEntry and gridPos == flipEntry[2] then EID.flipItemPositions[curRoomIndex][entity.InitSeed] = nil end
entity:GetData()["EID_FlipItemID"] = nil
end
end
EID:AddCallback(ModCallbacks.MC_POST_PICKUP_UPDATE, EID.CheckPedestalIndex, PickupVariant.PICKUP_COLLECTIBLE)
-- Before using Flip, swap all flippable pedestal's current item with the flip one (also, fix grid index if needed)
function EID:CheckFlipGridIndexes(collectibleType)
-- also, reload our descriptions due to transformation progress changing upon Flip
EID.ForceRefreshCache = true
lastFrameGridChecked = Isaac.GetFrameCount()
local curRoomIndex = game:GetLevel():GetCurrentRoomDesc().ListIndex
if EID.flipItemPositions[curRoomIndex] then
local pedestals = Isaac.FindByType(5, 100, -1, true, false)
for _, pedestal in ipairs(pedestals) do
local flipEntry = EID.flipItemPositions[curRoomIndex][pedestal.InitSeed]
if flipEntry then
local gridPos = game:GetRoom():GetGridIndex(pedestal.Position)
flipEntry[2] = gridPos
if collectibleType == CollectibleType.COLLECTIBLE_FLIP then
-- don't swap a flip shadow with an empty pedestal!
if pedestal.SubType == 0 then EID.flipItemPositions[curRoomIndex][pedestal.InitSeed] = nil
else flipEntry[1] = pedestal.SubType end
end
end
end
end
end
EID:AddCallback(ModCallbacks.MC_PRE_USE_ITEM, EID.CheckFlipGridIndexes, CollectibleType.COLLECTIBLE_FLIP)
end
-- Watch for a Void absorbing active items
function EID:CheckVoidAbsorbs(collectibleType, rng, player)
local playerID = EID:getPlayerID(player)
EID.absorbedItems[tostring(playerID)] = EID.absorbedItems[tostring(playerID)] or {}
for _,v in ipairs(EID:VoidRoomCheck()) do
EID.absorbedItems[tostring(playerID)][tostring(v)] = true
end
EID.RecheckVoid = true
end
EID:AddCallback(ModCallbacks.MC_PRE_USE_ITEM, EID.CheckVoidAbsorbs, CollectibleType.COLLECTIBLE_VOID)
---------------------------------------------------------------------------
--------------------------Handle Scale Shortcut----------------------------
local scaleMin = 0.1
local scaleMax = 2
local scaleSpeed = 0.01 -- scale size per frame
local scaleToBigger = true
EID.CurrentScaleType = "Size" -- Size or LocalModeSize; checked by EID:getTextPosition() to not apply modifiers in local mode
local scaleHoldFrame = 0
local function handleScaleKey()
local scaleKey = EID.Config["SizeHotkey"]
-- press and hold ScaleKey
if Input.IsButtonPressed(scaleKey, 0) then
if scaleHoldFrame > 60 then
EID.MCM_OptionChanged = true
local newScale
if scaleToBigger then
newScale = EID.Scale + scaleSpeed
if newScale > scaleMax then
scaleToBigger = false
end
else
newScale = EID.Scale - scaleSpeed
if newScale < scaleMin then
scaleToBigger = true
end
end
EID.Scale = newScale
EID.Config[EID.CurrentScaleType] = newScale
else
scaleHoldFrame = scaleHoldFrame + 1
end
end
-- press ScaleKey
if Input.IsButtonTriggered(scaleKey, 0) then
EID.MCM_OptionChanged = true
scaleHoldFrame = 0
local scale = EID.Scale
-- switch between 1, 1.5 and 0.5
if math.abs(scale - 1) < 0.01 then
scale = 1.5
elseif math.abs(scale - 1.5) < 0.01 then
scale = 0.5
else
scale = 1
end
EID.Config[EID.CurrentScaleType] = scale
EID.Scale = scale
end
end
---------------------------------------------------------------------------
---------------------------Printing Functions------------------------------
EID.previousDescs = {}
EID.CachingDescription = false
EID.CachedIcons = {}
EID.CachedStrings = {}
EID.CachedIndicators = {}
EID.CachedRenderPoses = {}
EID.descriptionsToPrint = {}
EID.entitiesToPrint = {}
local function resetDescCache()
EID.CachedIcons = {}
EID.CachedStrings = {}
EID.CachedRenderPoses = {}
-- EID.CachedIndicators = {}
EID.previousDescs = {}
end
function EID:addDescriptionToPrint(desc, insertLoc)
if desc.Entity and EID.entitiesToPrint[GetPtrHash(desc.Entity)] then return end
if #EID.descriptionsToPrint == EID.Config["MaxDescriptionsToDisplay"] then return end
if insertLoc then table.insert(EID.descriptionsToPrint, insertLoc, desc)
else table.insert(EID.descriptionsToPrint, desc) end
if desc.Entity then EID.entitiesToPrint[GetPtrHash(desc.Entity)] = true end
end
local prevPrintFrame = 0
function EID:printDescriptions(useCached)
prevPrintFrame = EID.GameRenderCount
EID.CachingDescription = false
if not useCached then
-- Test if we should print our cached descriptions or not
-- Did an option change, or it's a different number of descriptions?
if #EID.descriptionsToPrint ~= #EID.previousDescs or EID.OptionChanged or EID.MCM_OptionChanged then
EID:printNewDescriptions()
return
end
-- Do the description entities match, and the description texts match?
for i,newDesc in ipairs(EID.descriptionsToPrint) do
local oldDesc = EID.previousDescs[i]
if newDesc.Description ~= oldDesc.Description or newDesc.Name ~= oldDesc.Name or
(newDesc.Entity and oldDesc.Entity and GetPtrHash(newDesc.Entity) ~= GetPtrHash(oldDesc.Entity)) then
EID:printNewDescriptions()
return
end
end
end
if #EID.previousDescs > 0 then
EID.isDisplaying = true
end
-- Print our cached descriptions
for i,indicator in ipairs(EID.CachedIndicators) do
EID:renderIndicator(indicator[1], indicator[2])
end
for i,oldDesc in ipairs(EID.previousDescs) do
EID:printDescription(oldDesc, i)
end
end
function EID:printNewDescriptions()
EID.CachingDescription = true
resetDescCache()
for _,newDesc in ipairs(EID.descriptionsToPrint) do
if newDesc.Description == "UnidentifiedPill" then
if EID:renderUnidentifiedPill(newDesc.Entity) ~= false then
table.insert(EID.previousDescs, newDesc)
end
elseif newDesc.Description == "QuestionMark" then
if EID:renderQuestionMark(newDesc.Entity) ~= false then
table.insert(EID.previousDescs, newDesc)
end
elseif EID:printDescription(newDesc) ~= false then
table.insert(EID.previousDescs, newDesc)
end
end
EID.CachingDescription = false
if #EID.previousDescs > 0 then
EID.isDisplaying = true
end
end
function EID:printDescription(desc, cachedID)
EID:PositionLocalMode(desc.Entity)
-- Do not print this description if it has to be drawn in the top-left and we've already drawn a top-left desc this frame
if EID.CurrentScaleType == "Size" then
if alwaysUseLocalMode then return false
else alwaysUseLocalMode = true end
end
EID.isDisplaying = true
local renderPos = EID:getTextPosition()
if cachedID then
local localModeDiff = renderPos - EID.CachedRenderPoses[cachedID]
-- Drawing our currently saved description
for _,icon in ipairs(EID.CachedIcons[cachedID]) do
-- set inline icon to specific frame
if icon[6] >= 0 then
icon[1]:SetFrame(icon[5], icon[6])
-- frame of -1 = it's an animation, let it play
elseif not icon[1]:IsPlaying(icon[5]) or icon[1]:IsFinished(icon[5]) then
icon[1]:Play(icon[5],true)
else
icon[1]:Update()
end
EID:renderIcon(icon[1], icon[2] + localModeDiff.X, icon[3] + localModeDiff.Y, icon[4])
end
for _,str in ipairs(EID.CachedStrings[cachedID]) do
-- check for func (Rainbow, Blink, Fade), reset the color's Alpha to EID.Config["Transparency"] if func
if str[5] then
str[4].Alpha = str[6]
str[4] = str[5](str[4])
end
EID.font:DrawStringScaledUTF8(str[1], str[2] + localModeDiff.X, str[3] + localModeDiff.Y, EID.Scale, EID.Scale, str[4], 0, false)
end
return
else
table.insert(EID.CachedIcons, {})
table.insert(EID.CachedStrings, {})
table.insert(EID.CachedRenderPoses, Vector(renderPos.X, renderPos.Y))
end
local textScale = Vector(EID.Scale, EID.Scale)
local offsetX = 0
EID.lineHeight = EID.Config["LineHeight"]
if EID.Config["ShowItemIcon"] and desc.Icon then
offsetX = offsetX + 14
EID:renderInlineIcons({{desc.Icon,0}}, renderPos.X - 3 * EID.Scale, renderPos.Y - 4 * EID.Scale)
end
--Display ItemType / Charge
local itemType = -1
if desc.ObjSubType ~= nil and desc.ObjType == 5 and desc.ObjVariant == 100 then
itemType = EID.itemConfig:GetCollectible(desc.ObjSubType).Type or -1
end
if EID.Config["ShowItemType"] and (itemType == 3 or itemType == 4) then
local offsetY = 2
EID.IconSprite:Play(EID.ItemTypeAnm2Names[itemType])
EID:renderIcon(EID.IconSprite, renderPos.X + offsetX * EID.Scale, renderPos.Y + offsetY * EID.Scale, nil, EID.ItemTypeAnm2Names[itemType], 0)
if itemType == 3 then
-- Display Charge
offsetX = offsetX + 1
local curItemConfig = EID.itemConfig:GetCollectible(desc.ObjSubType)
local anim2 = "numbers"
local frame2 = curItemConfig.MaxCharges
if REPENTANCE and curItemConfig.ChargeType == ItemConfig.CHARGE_TIMED then
anim2 = "Misc"; frame2 = 6 -- Timer Icon
elseif REPENTANCE and (curItemConfig.ChargeType == ItemConfig.CHARGE_SPECIAL or desc.ObjSubType == CollectibleType.COLLECTIBLE_BLANK_CARD or desc.ObjSubType == CollectibleType.COLLECTIBLE_PLACEBO or
desc.ObjSubType == CollectibleType.COLLECTIBLE_CLEAR_RUNE or desc.ObjSubType == CollectibleType.COLLECTIBLE_D_INFINITY) then
frame2 = 13 -- Question Mark Icon
end
EID.InlineIconSprite2:SetFrame(anim2, frame2)
EID:renderIcon(EID.InlineIconSprite2, renderPos.X + offsetX * EID.Scale, renderPos.Y + offsetY * EID.Scale, nil, anim2, frame2)
end
offsetX = offsetX + 8
end
--Display Itemname
local curName = ""
if EID.Config["ShowItemName"] then
curName = desc.Name
if EID.Config["TranslateItemName"] ~= 2 then
local curLanguage = EID.Config["Language"]
if EID:getLanguage() ~= "en_us" then
EID.Config["Language"] = "en_us"
local englishName = desc.PermanentTextEnglish or EID:getObjectName(desc.ObjType, desc.ObjVariant, desc.ObjSubType)
EID.Config["Language"] = curLanguage
if EID.Config["TranslateItemName"] == 1 then
curName = englishName
elseif EID.Config["TranslateItemName"] == 3 and curName ~= englishName then
curName = curName.." ("..englishName..")"
end
end
end
end
-- Display Entity ID
if EID.Config["ShowObjectID"] and desc.ObjType > 0 then
curName = curName.." {{ColorGray}}"..desc.ObjType.."."..desc.ObjVariant.."."..desc.ObjSubType
end
-- Display Quality
if EID.Config["ShowQuality"] and desc.Quality then
curName = curName.." - {{Quality"..desc.Quality.."}}"
end
-- Display the mod this item is from
if desc.ModName then
if EID.Config["ModIndicatorDisplay"] == "Both" or EID.Config["ModIndicatorDisplay"] == "Name only" then
curName = curName .. " {{"..EID.Config["ModIndicatorTextColor"].."}}" .. EID.ModIndicator[desc.ModName].Name
end
if (EID.Config["ModIndicatorDisplay"] == "Both" or EID.Config["ModIndicatorDisplay"] == "Icon only") and EID.ModIndicator[desc.ModName].Icon then
curName = curName .. "{{".. EID.ModIndicator[desc.ModName].Icon .."}}"
end
end
EID:renderString(
curName,
renderPos + (Vector(offsetX, -3) * EID.Scale),
textScale,
EID:getNameColor()
)
renderPos.Y = renderPos.Y + EID.lineHeight * EID.Scale
--Display Transformation
if not (desc.Transformation == "0" or desc.Transformation == "" or desc.Transformation == nil) then
for transform in string.gmatch(desc.Transformation, "([^,]+)") do
--have a blank sprite info table if we aren't displaying it
local transformSprite = EID.Config["TransformationIcons"] and EID:getTransformationIcon(transform) or {}
local transformLineHeight = EID.lineHeight
if EID.Config["TransformationIcons"] then
transformLineHeight = math.max(EID.lineHeight, transformSprite[4])
EID:renderInlineIcons({{transformSprite,0}}, renderPos.X, renderPos.Y)
end
if EID.Config["TransformationText"] or EID.Config["TransformationProgress"] then
local transformationName = ""
if EID.Config["TransformationText"] then
transformationName = EID:getTransformationName(transform)
end
if EID.Config["TransformationProgress"] then
EID:evaluateTransformationProgress(transform)
transformationName = transformationName .. " "
for _, player in ipairs(EID.coopAllPlayers) do
local playerType = player:GetPlayerType()
if playerType ~= PlayerType.PLAYER_THESOUL_B and player:GetBabySkin() == -1 then
if #EID.coopAllPlayers > 1 then
local playerIcon = EID:getIcon("Player"..playerType) ~= EID.InlineIcons["ERROR"] and "{{Player"..playerType.."}}" or "{{CustomTransformation}}"
transformationName = transformationName .. playerIcon
end
local numCollected = EID.TransformationProgress[EID:getPlayerID(player)] and EID.TransformationProgress[EID:getPlayerID(player)][transform] or 0
local numMax = EID.TransformationData[transform] and EID.TransformationData[transform].NumNeeded or 3
transformationName = transformationName.."("..numCollected.."/"..numMax..") "
end
end
end
local iconWidth = transformSprite[3] or -1
local iconHeight = transformSprite[4] or -1
local textOffsetY = math.min(0, (iconHeight - 9)) / 4
EID:renderString(
transformationName,
renderPos + (Vector(iconWidth + 4, textOffsetY)* EID.Scale),
textScale,
EID:getTransformationColor()
)
end
if (EID.Config["TransformationIcons"] or EID.Config["TransformationText"] or EID.Config["TransformationProgress"]) then
renderPos.Y = renderPos.Y + transformLineHeight * EID.Scale
end
end
end
if EID.Config["ShowItemDescription"] then
EID:printBulletPoints(desc.Description, renderPos)
end
end
function EID:printBulletPoints(description, renderPos)
local textboxWidth = tonumber(EID.Config["TextboxWidth"])
local textScale = Vector(EID.Scale, EID.Scale)
description = EID:replaceNameMarkupStrings(description)
description = EID:replaceShortMarkupStrings(description)
description = EID:replaceMarkupSize(description)
for line in string.gmatch(description, "([^#]+)") do
local formatedLines = EID:fitTextToWidth(line, textboxWidth, EID.BreakUtf8CharsLanguage[EID:getLanguage()])
local textColor = EID:getTextColor()
for i, lineToPrint in ipairs(formatedLines) do
-- render bulletpoint
if i == 1 then
local bpIcon, rejectedIcon = EID:handleBulletpointIcon(lineToPrint)
if EID:getIcon(bpIcon) ~= EID.InlineIcons["ERROR"] then
lineToPrint = string.gsub(lineToPrint, bpIcon .. " ", "", 1)
textColor = EID:renderString(bpIcon, renderPos + Vector(-3 * EID.Scale, 0), textScale , textColor)
else
if rejectedIcon then lineToPrint = string.gsub(lineToPrint, rejectedIcon .. " ", "", 1) end
textColor = EID:renderString(bpIcon, renderPos, textScale , textColor)
end
EID.LastRenderCallColor = EID:copyKColor(textColor) -- Save line start Color for eventual Color Reset call
end
textColor = EID:renderString(lineToPrint, renderPos + Vector(12 * EID.Scale, 0), textScale, textColor)
renderPos.Y = renderPos.Y + EID.lineHeight * EID.Scale
end
end
end
---------------------------------------------------------------------------
----------------------------Handle New Room--------------------------------
EID.isMirrorRoom = false
EID.isDeathCertRoom = false
if REPENTANCE then
function EID:AssignFlipItems()
EID.flipMaxIndex = -1
local curRoomIndex = game:GetLevel():GetCurrentRoomDesc().ListIndex
if EID.flipItemPositions[curRoomIndex] then
local pedestals = Isaac.FindByType(5, 100, -1, true, false)
for _, pedestal in ipairs(pedestals) do
local flipEntry = EID.flipItemPositions[curRoomIndex][pedestal.InitSeed]
if flipEntry then
if pedestal.Index > EID.flipMaxIndex then EID.flipMaxIndex = pedestal.Index end
pedestal:GetData()["EID_FlipItemID"] = flipEntry[1]
end
end
end
end
function EID:onNewRoomRep()
local level = game:GetLevel()
EID.isMirrorRoom = level:GetCurrentRoom():IsMirrorWorld()
EID.isDeathCertRoom = EID:GetDimension(level) == 2
-- Handle Flip Item
initialItemNext = false
flipItemNext = false
EID:AssignFlipItems()
end
EID:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, EID.onNewRoomRep)
end
-- On new room, save the status of any variables that need to be rewound upon Glowing Hourglass usage
function EID:onNewRoom()
EID.RecentlyTouchedItems = {}
EID.CurrentRoomGridEntities = {}
local room = game:GetRoom()
for i = 1, room:GetGridSize(), 1 do
local gridEntity = room:GetGridEntity(i)
if gridEntity and EID:hasDescription(gridEntity) then
EID.CurrentRoomGridEntities[i] = gridEntity
end
end
end
EID:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, EID.onNewRoom)
---------------------------------------------------------------------------
---------------------------Handle Rendering--------------------------------
function EID:renderQuestionMark(entity)
EID:PositionLocalMode(entity)
if EID.CurrentScaleType == "Size" then
if alwaysUseLocalMode then return false
else alwaysUseLocalMode = true end
end
EID.IconSprite:Play("CurseOfBlind")
local pos = EID:getTextPosition()
if EID.CachingDescription then
table.insert(EID.CachedStrings, {})
table.insert(EID.CachedIcons, {})
table.insert(EID.CachedRenderPoses, Vector(pos.X, pos.Y))
end
EID:renderIcon(EID.IconSprite, pos.X + 5 * EID.Scale, pos.Y + 5 * EID.Scale, nil, "CurseOfBlind", 0)
end
function EID:renderUnidentifiedPill(entity)
EID:PositionLocalMode(entity)
if EID.CurrentScaleType == "Size" then
if alwaysUseLocalMode then return false
else alwaysUseLocalMode = true end
end
local pillColor = entity.SubType
if pillColor >= 2049 then
pillColor = pillColor - 2048
end
local pos = EID:getTextPosition()
if EID.CachingDescription then
table.insert(EID.CachedStrings, {})
table.insert(EID.CachedIcons, {})
table.insert(EID.CachedRenderPoses, Vector(pos.X, pos.Y))
end
EID:renderString(
"{{Pill"..pillColor.."}} "..EID:getDescriptionEntry("unidentifiedPill"),
pos,
Vector(EID.Scale, EID.Scale),
EID:getErrorColor()
)
end
-- RGB colors for each player's highlights (Red, Blue, Green, Yellow)
local playerRGB = { {1,0.6,0.6}, {0.5,0.75,1}, {0.5,1,0.75}, {0.9, 0.9, 0.5} }
function EID:renderIndicator(entity, playerNum)
if EID.Config["Indicator"] == "none" then
return
end
local repDiv = 1
local entityPos = Isaac.WorldToScreen(entity.Position)
local ArrowOffset = Vector(0, -35)
if entity.Variant == 100 and not entity:ToPickup():IsShopItem() then
ArrowOffset = Vector(0, -62)
end
local arrowPos = Isaac.WorldToScreen(entity.Position + ArrowOffset)
if not EID:IsGridEntity(entity) and entity:GetData() and entity:GetData()["EID_RenderOffset"] then
entityPos = entityPos + entity:GetData()["EID_RenderOffset"]
end
-- Move highlights a bit to fit onto the alt Item layout of Flip / Tainted Laz
if REPENTANCE and not EID:IsGridEntity(entity) then
if entity.Variant == 100 and EID:PlayersHaveCollectible(CollectibleType.COLLECTIBLE_FLIP) and EID:getEntityData(entity, "EID_FlipItemID") then
entityPos = entityPos + Vector(2.5,2.5)
elseif entity.Type == 6 and entity.Variant == 16 then
entityPos = entityPos + Vector(0,-5)
end
end
local sprite = nil
if not EID:IsGridEntity(entity) then sprite = entity:GetSprite() end
if REPENTANCE then
repDiv = 255
if EID.isMirrorRoom then
local screenCenter = EID:getScreenSize()/2
entityPos.X = entityPos.X - (entityPos-screenCenter).X * 2
arrowPos.X = arrowPos.X - (arrowPos-screenCenter).X * 2
if sprite then sprite.FlipX = true end
end
end
-- Don't apply sprite.Color changes to Effects (Dice Floors, Card Reading Portals), use Arrow instead
if EID.Config["Indicator"] == "arrow" or entity.Type == 1000 or EID:IsGridEntity(entity) then
ArrowSprite:RenderLayer(playerNum-1, arrowPos, nullVector, nullVector)
else
local colorMult = {1,1,1}
local framecount = entity.FrameCount or game:GetFrameCount()
if EID.isMultiplayer then colorMult = playerRGB[playerNum] end
if EID.Config["Indicator"] == "blink" then
local c = 255 - math.floor(255 * ((framecount % 40) / 40))
local r, g, b = math.floor(c*colorMult[1]), math.floor(c*colorMult[2]), math.floor(c*colorMult[3])
sprite.Color = Color(1, 1, 1, 1, r/repDiv, g/repDiv, b/repDiv)
EID:RenderEntity(entity, sprite, entityPos)
sprite.Color = Color(1, 1, 1, 1, 0, 0, 0)
else
if EID.Config["Indicator"] == "highlight" then
local c = 255 - math.floor(255 * ((framecount % 40) / 40))
local r, g, b = math.floor(c*colorMult[1]), math.floor(c*colorMult[2]), math.floor(c*colorMult[3])
sprite.Color = Color(1, 1, 1, 1, r/repDiv, g/repDiv, b/repDiv)
elseif EID.Config["Indicator"] == "border" then
local c = 255
local r, g, b = math.floor(c*colorMult[1]), math.floor(c*colorMult[2]), math.floor(c*colorMult[3])
sprite.Color = Color(1, 1, 1, 1, r/repDiv, g/repDiv, b/repDiv)
end
EID:RenderEntity(entity, sprite, entityPos + Vector(0, 1))
EID:RenderEntity(entity, sprite, entityPos + Vector(0, -1))
EID:RenderEntity(entity, sprite, entityPos + Vector(1, 0))
EID:RenderEntity(entity, sprite, entityPos + Vector(-1, 0))
sprite.Color = Color(1, 1, 1, 1, 0, 0, 0)
EID:RenderEntity(entity, sprite, entityPos)
end
end
if EID.isMirrorRoom then
if sprite then sprite.FlipX = false end
end
end
function EID:PositionLocalMode(entity)
-- don't use Local Mode for descriptions without an entity (or dice floors)
if (EID.Config["DisplayMode"] == "local" or alwaysUseLocalMode) and entity and entity.Variant ~= EffectVariant.DICE_FLOOR then
EID.Scale = EID.Config["LocalModeSize"]
EID.CurrentScaleType = "LocalModeSize"
local textBoxWidth = EID.Config["LocalModeCentered"] and tonumber(EID.Config["TextboxWidth"])/2 * EID.Scale or -30
local textPosOffset = Vector(-textBoxWidth, 20)
EID:alterTextPos(Isaac.WorldToScreen(entity.Position + textPosOffset))
if EID.isMirrorRoom then
EID:alterTextPos(Isaac.WorldToScreen(entity.Position + textPosOffset * Vector(-1,0)))
local screenCenter = EID:getScreenSize()/2
EID.UsedPosition.X = EID.UsedPosition.X - (EID.UsedPosition-screenCenter).X * 2
end
else
EID.Scale = EID.Config["Size"]
EID.CurrentScaleType = "Size"
EID.UsedPosition = Vector(EID.Config["XPosition"], EID.Config["YPosition"])
end
end
function EID:renderHUDLocationIndicators()
local mousePos = Isaac.WorldToRenderPosition(Input.GetMousePosition(true)) * 2
Isaac.RenderScaledText("Mouse pos X:"..mousePos.X.." Y:"..mousePos.Y, 100, 10, 0.5, 0.5, 1 ,1 ,1 ,1 )
Isaac.RenderScaledText("HUD Adjustment Preview!", 200, 10, 1, 1, 1 ,0.25 ,0.25 ,1 )
for k, v in pairs(EID.HUDElements) do
local hudElement = EID:handleHUDElement(v)
hudBBSprite.Scale = Vector(hudElement.width/2, hudElement.height/2)
hudBBSprite.Color = Color(1, 1, 1, EID.Config["Transparency"], 0, 0, 0)
hudBBSprite:Render(Vector(hudElement.x/2, hudElement.y/2), nullVector, nullVector)
Isaac.RenderScaledText(k, hudElement.x/2, hudElement.y/2, 0.5, 0.5, 1, 1, 1 ,1)
end
end
local lastMousePos = Vector(0,0)
local lastMouseMove = 0
function EID:handleHoverHUD()
local mousePos = Isaac.WorldToScreen(Input.GetMousePosition(true)) * 2
if mousePos:Distance(lastMousePos) > 2 then
lastMousePos = mousePos
lastMouseMove = game:GetFrameCount()
end
if game:GetFrameCount() - lastMouseMove > 60 * 3 then
return nil
end
if EID.Config["ShowCursor"] then
EID.CursorSprite:Render(Vector(mousePos.X / 2, mousePos.Y / 2), nullVector, nullVector)
end
for k, v in pairs(EID.HUDElements) do
local hudElement = EID:handleHUDElement(v)
if hudElement.x <= mousePos.X and (hudElement.x + hudElement.width) >= mousePos.X and hudElement.y <= mousePos.Y and (hudElement.y + hudElement.height) >= mousePos.Y then
local result = hudElement.descriptionObj()
if result then return result end
end
end
return nil
end
function EID:setPlayer()
local numPlayers = game:GetNumPlayers()
-- Old simple setPlayer, to reduce runtime in single player
if numPlayers == 1 or not EID.Config["CoopDescriptions"] then
local p = Isaac.GetPlayer(0)
if REPENTANCE and p:GetPlayerType() == PlayerType.PLAYER_THEFORGOTTEN_B then
EID.player = p:GetOtherTwin() or p
else
EID.player = p
end
EID.players = { EID.player, REPENTANCE and EID.player:GetOtherTwin() }
EID.coopMainPlayers = { EID.player }
EID.coopAllPlayers = EID.players
EID.controllerIndexes[p.ControllerIndex] = 1
EID.isMultiplayer = false
return
end
-- Get our primary player, our list of all players, and a list of the primary player for each controller
EID.coopAllPlayers = {} -- all player characters in order
EID.coopMainPlayers = {} -- the primary player character from each controller
EID.controllerIndexes = {} -- simple table to map each controller index to P1/P2/P3/P4 (since index 0 could be P2)
local currentPlayerNum = 1
for i = 0, numPlayers - 1 do
local player = Isaac.GetPlayer(i)
-- Don't include player entities with a parent (Strawman / Soul of Jacob and Esau)
if player.Parent == nil then
local newIndex = not EID.controllerIndexes[player.ControllerIndex]
-- Tainted Soul is treated as the primary player for Tainted Forgotten, so swap them
if REPENTANCE and (player:GetPlayerType() == PlayerType.PLAYER_THEFORGOTTEN_B
or player:GetPlayerType() == PlayerType.PLAYER_THESOUL_B) then
player = player:GetOtherTwin() or player
end
table.insert(EID.coopAllPlayers, player)
if newIndex then
table.insert(EID.coopMainPlayers, player)
EID.controllerIndexes[player.ControllerIndex] = currentPlayerNum
currentPlayerNum = currentPlayerNum + 1
end
end
end
EID.player = EID.coopAllPlayers[1]
-- second entry will be nil if no twin or AB+ (REPENTANCE = nil)
EID.players = { EID.player, REPENTANCE and EID.player:GetOtherTwin() }
EID.isMultiplayer = #EID.coopMainPlayers > 1
end
---------------------------------------------------------------------------
---------------------------On Update Function------------------------------
-- Runs 30 times a second; doesn't update while paused
local collSpawned = false
EID.RecheckVoid = false
function EID:onGameUpdate()
EID.GameUpdateCount = EID.GameUpdateCount + 1
EID:checkPlayersForMissingItems()