Skip to content

Commit

Permalink
Merge pull request #1 from Dual-Iron/small-update
Browse files Browse the repository at this point in the history
Thanks v much for the fixes and tweaks, and massive apologies that it took me so long to review
  • Loading branch information
casheww authored Sep 26, 2021
2 parents 6730c9e + c934dd5 commit 09522c4
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 61 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Ignore user paths
user.targets

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
Expand Down
21 changes: 6 additions & 15 deletions ChunkLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ namespace HeadsShouldersKneesAndToes
{
class ChunkLabel : CosmeticSprite
{
public ChunkLabel(BodyChunk chunk, int index, Room room)
public ChunkLabel(BodyChunk chunk, int index)
{
this.chunk = chunk;
startRoomName = room.abstractRoom.name;

// set label text properties
label = new FLabel("DisplayFont", index.ToString())
Expand All @@ -22,14 +21,10 @@ public ChunkLabel(BodyChunk chunk, int index, Room room)

public override void Update(bool eu)
{
try
if (chunk.owner?.room?.abstractRoom?.name != TaggerMod.CurrentRoomName || chunk.owner.slatedForDeletetion)
{
if (chunk.owner.room.abstractRoom.name != startRoomName)
{
Destroy();
}
Destroy();
}
catch (NullReferenceException) { }

base.Update(eu);
}
Expand All @@ -45,18 +40,15 @@ public override void InitiateSprites(RoomCamera.SpriteLeaser sLeaser, RoomCamera
{
// set label background properties (sans color)
sLeaser.sprites = new FSprite[1];
sLeaser.sprites[0] = new FSprite("pixel", true)
{
scaleX = 8f,
scaleY = 8f
};
sLeaser.sprites[0] = new FSprite("pixel", true);
AddToContainer(sLeaser, rCam, null);
}

public override void DrawSprites(RoomCamera.SpriteLeaser sLeaser, RoomCamera rCam, float timeStacker, Vector2 camPos)
{
Vector2 pos = Vector2.Lerp(chunk.lastPos, chunk.pos, timeStacker) - camPos;
sLeaser.sprites[0].SetPosition(pos);
sLeaser.sprites[0].scaleX = sLeaser.sprites[0].scaleY = chunk.rad * 2;
label.SetPosition(pos);
sLeaser.sprites[0].isVisible = TaggerMod.ChunkTagsVisible;
label.isVisible = TaggerMod.ChunkTagsVisible;
Expand All @@ -76,13 +68,12 @@ public override void AddToContainer(RoomCamera.SpriteLeaser sLeaser, RoomCamera
public override void ApplyPalette(RoomCamera.SpriteLeaser sLeaser, RoomCamera rCam, RoomPalette palette)
{
// set colour of label background
Color color = Color.black;
Color color = palette.skyColor * 0.9f;
color.a = 0.7f;
sLeaser.sprites[0].color = color;
}

readonly BodyChunk chunk;
readonly FLabel label;
readonly string startRoomName;
}
}
3 changes: 2 additions & 1 deletion HeadsShouldersKneesAndToes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy /Y $(TargetPath) "D:\Games\Steam\steamapps\common\Rain World\Mods"</PostBuildEvent>
<PostBuildEvent Label="copyoutput">copy /Y $(TargetPath) "D:\Games\Steam\steamapps\common\Rain World\Mods"</PostBuildEvent>
</PropertyGroup>
<Import Condition="Exists('user.targets')" Project="user.targets" />
</Project>
14 changes: 4 additions & 10 deletions SpriteLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ namespace HeadsShouldersKneesAndToes
{
class SpriteLabel : CosmeticSprite
{
public SpriteLabel(FSprite sprite, Creature owner, int index, Room room)
public SpriteLabel(FSprite sprite, UpdatableAndDeletable owner, int index)
{
this.sprite = sprite;
this.owner = owner;
startRoomName = room.abstractRoom.name;

// set label text properties
label = new FLabel("DisplayFont", index.ToString())
Expand All @@ -23,14 +22,10 @@ public SpriteLabel(FSprite sprite, Creature owner, int index, Room room)

public override void Update(bool eu)
{
try
if (owner.room?.abstractRoom?.name != TaggerMod.CurrentRoomName || owner.slatedForDeletetion)
{
if (owner.room.abstractRoom.name != startRoomName)
{
Destroy();
}
Destroy();
}
catch (NullReferenceException) { }

base.Update(eu);
}
Expand Down Expand Up @@ -85,8 +80,7 @@ public override void ApplyPalette(RoomCamera.SpriteLeaser sLeaser, RoomCamera rC
}

readonly FSprite sprite;
readonly Creature owner;
readonly UpdatableAndDeletable owner;
readonly FLabel label;
readonly string startRoomName;
}
}
50 changes: 26 additions & 24 deletions TaggerMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ namespace HeadsShouldersKneesAndToes
[BepInPlugin("casheww.chunk_tagger", "Tagger", "1.1")]
class TaggerMod : BaseUnityPlugin
{

void OnEnable()
public void OnEnable()
{
On.GraphicsModule.InitiateSprites += GraphicsModule_InitiateSprites;
On.RoomCamera.SpriteLeaser.ctor += SpriteLeaser_ctor;
ChunkTagsVisible = false;
SpriteTagsVisible = false;
TileGridVisible = false;
}

void Update()
public void Update()
{
if (Input.GetKeyDown(KeyCode.Equals))
{
Expand All @@ -32,44 +31,47 @@ void Update()
}
}

void GraphicsModule_InitiateSprites(On.GraphicsModule.orig_InitiateSprites orig,
GraphicsModule self, RoomCamera.SpriteLeaser sLeaser, RoomCamera rCam)
private void SpriteLeaser_ctor(On.RoomCamera.SpriteLeaser.orig_ctor orig, RoomCamera.SpriteLeaser self, IDrawable obj, RoomCamera rCam)
{
orig(self, sLeaser, rCam);
orig(self, obj, rCam);

if (self.owner is Creature)
if (!(obj is ChunkLabel || obj is SpriteLabel || obj is TileGridLine))
{
for (int i = 0; i < self.owner.bodyChunks.Length; i++)
{
ChunkLabel chunkLabel = new ChunkLabel(self.owner.bodyChunks[i], i, rCam.room);
rCam.room.AddObject(chunkLabel);
}
var physobjs = obj as PhysicalObject ?? (obj is GraphicsModule g ? g.owner : null);

for (int i = 0; i < sLeaser.sprites.Length; i++)
if (physobjs != null)
{
SpriteLabel spriteLabel = new SpriteLabel(sLeaser.sprites[i],
self.owner as Creature, i, rCam.room);
rCam.room.AddObject(spriteLabel);
for (int i = 0; i < physobjs.bodyChunks.Length; i++)
{
ChunkLabel chunkLabel = new ChunkLabel(physobjs.bodyChunks[i], i);
rCam.room.AddObject(chunkLabel);
}
for (int i = 0; i < self.sprites.Length; i++)
{
SpriteLabel spriteLabel = new SpriteLabel(self.sprites[i], physobjs, i);
rCam.room.AddObject(spriteLabel);
}
}

if (rCam.room.abstractRoom.name != CurrentTiledRoomName)
if (rCam.room.abstractRoom.name != CurrentRoomName)
{
for (int x = 0; x < rCam.room.Width; x++)
for (int x = 0; x < rCam.room.TileWidth; x++)
{
TileGridLine tileMarker = new TileGridLine(rCam.room, TileGridLine.Orientation.Vertical, x);
TileGridLine tileMarker = new TileGridLine(TileGridLine.Orientation.Vertical, x);
rCam.room.AddObject(tileMarker);
}
for (int y = 0; y < rCam.room.Height; y++)
for (int y = 0; y < rCam.room.TileHeight; y++)
{
TileGridLine tileMarker = new TileGridLine(rCam.room, TileGridLine.Orientation.Horizontal, y);
TileGridLine tileMarker = new TileGridLine(TileGridLine.Orientation.Horizontal, y);
rCam.room.AddObject(tileMarker);
}
CurrentTiledRoomName = rCam.room.abstractRoom.name;
}
}

CurrentRoomName = rCam.room.abstractRoom.name;
}

public static string CurrentTiledRoomName { get; private set; }
public static string CurrentRoomName { get; private set; }

public static bool ChunkTagsVisible { get; private set; }
public static bool SpriteTagsVisible { get; private set; }
Expand Down
16 changes: 5 additions & 11 deletions TileGridLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,21 @@ namespace HeadsShouldersKneesAndToes
{
class TileGridLine : CosmeticSprite
{
public TileGridLine(Room room, Orientation o, int n)
public TileGridLine(Orientation o, int n)
{
startRoomName = room.abstractRoom.name;
this.o = o;
this.n = n;
}

readonly Orientation o;
readonly int n;
readonly string startRoomName;

public override void Update(bool eu)
{
try
if (room.abstractRoom?.name != TaggerMod.CurrentRoomName)
{
if (room.abstractRoom.name != startRoomName)
{
Destroy();
}
Destroy();
}
catch (NullReferenceException) { }

base.Update(eu);
}
Expand Down Expand Up @@ -57,11 +51,11 @@ public override void DrawSprites(RoomCamera.SpriteLeaser sLeaser, RoomCamera rCa
sLeaser.sprites[0].isVisible = TaggerMod.TileGridVisible;
if (o == Orientation.Vertical)
{
sLeaser.sprites[0].SetPosition(rCam.room.MiddleOfTile(n, rCam.room.Height / 2) - camPos - new Vector2(10, 0));
sLeaser.sprites[0].SetPosition(rCam.room.MiddleOfTile(n, rCam.room.TileHeight / 2) - camPos - new Vector2(10, 0));
}
else
{
sLeaser.sprites[0].SetPosition(rCam.room.MiddleOfTile(rCam.room.Width / 2, n) - camPos - new Vector2(0, 10));
sLeaser.sprites[0].SetPosition(rCam.room.MiddleOfTile(rCam.room.TileWidth / 2, n) - camPos - new Vector2(0, 10));
}
base.DrawSprites(sLeaser, rCam, timeStacker, camPos);
}
Expand Down

0 comments on commit 09522c4

Please sign in to comment.