Skip to content

Commit

Permalink
Update for 1.0 (b313/exp) compatibility
Browse files Browse the repository at this point in the history
- Bumped unity version to 2022.3.29f1
  • Loading branch information
mgreter committed Jul 4, 2024
1 parent 0a6cc57 commit 3e6ed7f
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 432 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ jobs:

steps:
- name: Check out repository code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Call 7D2D compiler action
uses: OCB7D2D/OcbModCompiler@master
with:
v7d2d: 'V1.0'
name: "OcbRemoteTurretControl"
version: "${{ github.ref_name }}"
token: "${{ secrets.GITHUB_TOKEN }}"
Expand Down
14 changes: 7 additions & 7 deletions Harmony/OcbRemoteTurret.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,20 @@ public static bool Prefix(XUiC_PowerRangedAmmoSlots __instance)
}
}

/*************************************************************************/
// Below is a few advanced transpiler patches
// Inserting `UpgradeVariantHelper` into handler
/*************************************************************************/
/*************************************************************************/
// Below is a few advanced transpiler patches
// Inserting `UpgradeVariantHelper` into handler
/*************************************************************************/

// Used by patched function below
static void UpgradeVariantHelper(ItemStack stack)
// Used by patched function below
private static void UpgradeVariantHelper(ItemStack stack)
{
// Check if we are dealing with a block
if (stack.itemValue.type < Block.ItemsStartHere)
{
// Check if the block has `ReturnVariantHelper` set
if (Block.list[stack.itemValue.type].Properties.Values
.TryGetString("ReturnVariantHelper", out string variant))
.TryGetValue("ReturnVariantHelper", out string variant))
{
// Upgrade `itemValue` to variant helper block type
if (Block.GetBlockByName(variant) is Block helper)
Expand Down
34 changes: 18 additions & 16 deletions Library/BlockRemoteTurret.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public readonly static List<TileEntityPowered>
public static TileEntityPowered LastPanelOpen = null;
// public BlockRemoteTurret() => IsRandomlyTick = false;

private Dictionary<string, Tuple<string, int>> AmmoPerks
private readonly Dictionary<string, Tuple<string, int>> AmmoPerks
= new Dictionary<string, Tuple<string, int>>();
private Dictionary<string, Tuple<ProgressionValue, int>> PlayerPerks
private readonly Dictionary<string, Tuple<ProgressionValue, int>> PlayerPerks
= new Dictionary<string, Tuple<ProgressionValue, int>>();

// Key-Mappings to switch turret cameras
Expand Down Expand Up @@ -95,12 +95,12 @@ public override void Init()
KeyMapPrev = KeyCode.A; KeyMapNext = KeyCode.D;
Properties.ParseEnum("ScreenKeyMapPrev", ref KeyMapPrev);
Properties.ParseEnum("ScreenKeyMapNext", ref KeyMapNext);
if (Properties.Values.TryGetString("AmmoPerks", out string ammos))
if (Properties.Values.TryGetValue("AmmoPerks", out string ammos))
{
// Note: we don't allow whitespace!?
foreach (var ammo in ammos.Split(','))
{
if (Properties.Values.TryGetString(ammo + "Perk", out string skill))
if (Properties.Values.TryGetValue(ammo + "Perk", out string skill))
{
int minLevel = 0;
Properties.ParseInt(ammo + "PerkLevel", ref minLevel);
Expand Down Expand Up @@ -160,31 +160,33 @@ public static void AddEntityToEntries(
public static TileEntityPowered PanelToOpen = null;

public override bool OnBlockActivated(
string _commandName,
string _commandName,
WorldBase world,
int cIdx,
Vector3i position,
BlockValue _blockValue,
EntityAlive player)
EntityPlayerLocal player)
{
if (_commandName == "activate")
{
CurrentOpenBlock = null;
CurrentOpenPanel = null;
RemoteTurretUtils.CollectTurrets(world, cIdx,
RemoteTurretUtils.CollectTurrets(world,
position, ControlPanels, RemoteTurrets);
var te = world.GetTileEntity(cIdx, position);
if (!(te is TileEntityPowered tep))
{
GameManager.ShowTooltip(player as EntityPlayerLocal,
Localization.Get("ttNoTurretConnected"), string.Empty, "ui_denied");
GameManager.ShowTooltip(player,
Localization.Get("ttNoTurretConnected"),
string.Empty, "ui_denied");
return false;
}
// Check if panel is powered and has turrets
if (!tep.IsPowered || RemoteTurrets.Count == 0)
{
GameManager.ShowTooltip(player as EntityPlayerLocal,
Localization.Get("ttNoTurretConnected"), string.Empty, "ui_denied");
GameManager.ShowTooltip(player,
Localization.Get("ttNoTurretConnected"),
string.Empty, "ui_denied");
return false;
}
// Set `OnOpen` state
Expand Down Expand Up @@ -237,7 +239,7 @@ public static bool OnPanelOpen(LocalPlayerUI ui)
return true;
}

private BlockActivationCommand[] cmds = new BlockActivationCommand[2]
private new readonly BlockActivationCommand[] cmds = new BlockActivationCommand[2]
{
new BlockActivationCommand("activate", "tool", true),
new BlockActivationCommand("take", "hand", false)
Expand Down Expand Up @@ -279,7 +281,7 @@ public override string GetActivationText(
/****************************************************************************/

IEnumerator UpdateCoroutine = null;
Dictionary<Vector3i, RemoteTurretPanel> Loaded
readonly Dictionary<Vector3i, RemoteTurretPanel> Loaded
= new Dictionary<Vector3i, RemoteTurretPanel>();

private IEnumerator UpdateNext()
Expand Down Expand Up @@ -312,15 +314,15 @@ private int Vector3DistSquared(Vector3i v3i)
}

public override void OnBlockEntityTransformBeforeActivated(WorldBase _world,
Vector3i _blockPos, int _cIdx, BlockValue _blockValue, BlockEntityData _ebcd)
Vector3i _blockPos, BlockValue _blockValue, BlockEntityData _ebcd)
{
base.OnBlockEntityTransformBeforeActivated(_world, _blockPos, _cIdx, _blockValue, _ebcd);
base.OnBlockEntityTransformBeforeActivated(_world, _blockPos, _blockValue, _ebcd);
if (Loaded.Count == 0)
{
UpdateCoroutine = UpdateNext();
GameManager.Instance.StartCoroutine(UpdateCoroutine);
}
Loaded.Add(_blockPos, new RemoteTurretPanel(_world, _cIdx, _blockPos,
Loaded.Add(_blockPos, new RemoteTurretPanel(_world, _blockPos,
_ebcd.transform.Find("Screen"), this));
}

Expand Down
9 changes: 3 additions & 6 deletions Library/RemoteTurretControlPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ public class RemoteTurretPanel : PoweredScreenPanel
// Just a reference to our world
private readonly WorldBase World;

// Never know what this does!?
private readonly int ClrIdx = 0;

// Position of the remote turret control panel
private readonly Vector3i Position;

Expand Down Expand Up @@ -96,12 +93,12 @@ private void SetRenderersActive(bool enabled)


// Constructor
public RemoteTurretPanel(WorldBase world, int clrIdx, Vector3i pos, Transform monitor, BlockRemoteTurret block)
public RemoteTurretPanel(WorldBase world, Vector3i pos, Transform monitor, BlockRemoteTurret block)
{
Block = block; // Set as already as possible
if (block == null) throw new Exception("No Block");
LastTick = GetRandomCamIntervalOffset(0.3f);
World = world; ClrIdx = clrIdx; Position = pos;
World = world; Position = pos;
if (World == null) throw new Exception("No World");
Renderers = monitor?.GetComponentsInChildren<MeshRenderer>();
if (MainRenderer == null) throw new Exception("No Monitor");
Expand Down Expand Up @@ -162,7 +159,7 @@ public void Tick(bool active)
// Gather all connected turrets
// Does so by following wires
RemoteTurretUtils.CollectTurrets(
World, ClrIdx, Position,
World, Position,
ControlPanels, RemoteTurrets);
// Reset view index
CurrentCam = 0;
Expand Down
3 changes: 1 addition & 2 deletions Library/RemoteTurretUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ private static List<Vector3i> PoweredChildren(TileEntityPowered te)

public static void CollectTurrets(
WorldBase world,
int cIdx,
Vector3i blockPos,
List<TileEntityPowered> ControlPanels,
List<TileEntityPoweredRangedTrap> RemoteTurrets,
Expand All @@ -37,7 +36,7 @@ public static void CollectTurrets(
var queued = queue.Dequeue();
var position = queued.Item1;
var depth = queued.Item2;
if (world.GetTileEntity(cIdx, position) is TileEntityPowered tep)
if (world.GetTileEntity(position) is TileEntityPowered tep)
{
// Skip other remote turret blocks (only collect local turrets)
if (tep.blockValue.Block is BlockRemoteTurret)
Expand Down
15 changes: 4 additions & 11 deletions Library/XUI_PowerRemoteTurretControlPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class XUI_PowerRemoteTurretPanel : XUiC_PowerRangedTrapWindowGroup
public TileEntityPowered LastPanel => BlockRemoteTurret.LastPanelOpen;

// Reference to the camera preview window
private XUiC_CameraWindow cameraWindowPreview;
// private XUiC_CameraWindow cameraWindowPreview;

// Current slot we are viewing
// We always have a lock on it
Expand All @@ -36,13 +36,6 @@ public class XUI_PowerRemoteTurretPanel : XUiC_PowerRangedTrapWindowGroup
private int LastSlotLocked = -1;
private bool RequestPending = false;

public override void Init()
{
base.Init();
var preview = GetChildById("windowPowerCameraControlPreview");
cameraWindowPreview = preview as XUiC_CameraWindow;
}

// Coroutine to close instantly
// Needed to give a little timeout
private IEnumerator CloseLater()
Expand Down Expand Up @@ -185,7 +178,7 @@ private void Destroy()
ControlPanels.Clear();
}

private void TileEntityDestroyed(TileEntity te)
private void TileEntityDestroyed(ITileEntity te)
{
Destroy();
}
Expand Down Expand Up @@ -300,9 +293,9 @@ public void SetCurrentTurretSlot(int slot)

static readonly FieldInfo FieldLockedTileEntities = AccessTools.Field(typeof(GameManager), "lockedTileEntities");

public static Dictionary<TileEntity, int> GetServerLocks()
public static Dictionary<ITileEntity, int> GetServerLocks()
{
return (Dictionary<TileEntity, int>)FieldLockedTileEntities.GetValue(GameManager.Instance);
return (Dictionary<ITileEntity, int>)FieldLockedTileEntities.GetValue(GameManager.Instance);
}

// Call as a remote function call to acquire new and release old lock
Expand Down
2 changes: 1 addition & 1 deletion ModInfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
<Description value="Connect and control remote turrets and view their cameras" />
<Website value="https://github.com/OCB7D2D/OcbRemoteTurretControl" />
<Author value="ocbMaurice" />
<Version value="0.2.1" />
<Version value="0.3.0" />
</xml>
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,23 @@ which means that screens the player stands closer are updated more
frequently. When very close, up to same fps as the main game runs.
Further away you may only get an update each 1 or 2 seconds.

## Download and Install

End-Users are encouraged to download my mods from [NexusMods][5].
Every download there helps me to buy stuff for mod development.

Otherwise please use one of the [official releases][6] here.
Only clone or download the repo if you know what you do!

[5]: https://www.nexusmods.com/7daystodie/mods/2279
[6]: https://github.com/OCB7D2D/OcbRemoteTurretControl/releases

## Changelog

### Version 0.3.0

- First compatibility with V1.0 (exp)

### Version 0.2.1

- Add fog and sky to all electric cameras
Expand Down Expand Up @@ -187,6 +202,5 @@ Further away you may only get an update each 1 or 2 seconds.

- Initial working version

## Compatibility

Developed initially for version a20.5(b2), updated through A21.0(b324).
[1]:
[2]:
1 change: 0 additions & 1 deletion RemoteTurretControl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
<Compile Include="Library\XUI_PowerRangedTrapWindowGroup.cs" />
<Compile Include="LibThrottleCams\ThrottleCams.cs" />
<Compile Include="Utils\HarmonySerializer.cs" />
<Compile Include="Utils\ModXmlPatcher.cs" />
<Content Include="Config\loot.xml" />
<Content Include="Config\recipes.xml" />
<Content Include="Config\progression.xml" />
Expand Down
Binary file modified RemoteTurretControl.dll
Binary file not shown.
Binary file modified Resources/RemoteTurretPanels.unity3d
Binary file not shown.
4 changes: 2 additions & 2 deletions Unity/TurretPanel/ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2021.3.19f1
m_EditorVersionWithRevision: 2021.3.19f1 (c9714fde33b6)
m_EditorVersion: 2022.3.29f1
m_EditorVersionWithRevision: 2022.3.29f1 (8d510ca76d2b)
Loading

0 comments on commit 3e6ed7f

Please sign in to comment.