Skip to content

Commit

Permalink
Fixed for Timberborn 0.4.1.1 (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
KYPremco authored Apr 20, 2023
1 parent e81bff7 commit 2b384d2
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 328 deletions.
39 changes: 3 additions & 36 deletions Core/TimberApi.Common/TimberApi.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,15 @@
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>9</LangVersion>
<Authors>hawkfalcon, TheBloodEyes, thundersen</Authors>
<Authors>Hawkfalcon, TheBloodEyes, Hythonhan</Authors>
<PackageProjectUrl>https://timberapi.com</PackageProjectUrl>
<PackageLicenseExpression>LGPL-2.1-or-later</PackageLicenseExpression>
<ReleaseVersion>TIMBER_API_VERSION_PLACEHOLDER</ReleaseVersion>
</PropertyGroup>

<PropertyGroup>
<!-- Set to true if you want to use the live timberborn assemblies of the game, requires symlink -->
<UseLocalTimberbornSource>false</UseLocalTimberbornSource>
<!-- none: don't copy, bepinex: path to game > bepinex > plugins, timberapi: path to game > timberapi -->
<CopyDllToPath>none</CopyDllToPath>
</PropertyGroup>

<Import Project="$(SolutionDir)GameImports.targets" />

<ItemGroup>
<PackageReference Include="Unity.InputSystem" Version="1.5.0" />
<PackageReference Include="UnityEngine.Modules" Version="2022.1.6" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Timberborn.GameLibs" Version="0.4.0-r.0" Condition="$(UseLocalTimberbornSource) == false" />
<PackageReference Include="System.Collections.Immutable" Version="5.0.0" />
</ItemGroup>

<!-- Import dll's from Timberborn's symlink in solution folder-->
<ItemGroup Condition="$(UseLocalTimberbornSource)">
<Reference Include="$(SolutionDir)Timberborn\Timberborn_Data\Managed\Timberborn.*.dll">
<DestinationSubDirectory>libs/</DestinationSubDirectory>
</Reference>
<Reference Include="$(SolutionDir)Timberborn\Timberborn_Data\Managed\Bindito.*.dll">
<DestinationSubDirectory>libs/</DestinationSubDirectory>
</Reference>
</ItemGroup>

<!-- Used for automaticly transfer dll to Timberborn location, make a symlink `Timberborn` in the solution folder -->
<PropertyGroup Condition="$(CopyDllToPath) == 'timberapi'">
<TimberApiPath>$(SolutionDir)Timberborn\TimberAPI</TimberApiPath>
</PropertyGroup>

<PropertyGroup Condition="$(CopyDllToPath) == 'bepinex'">
<TimberApiPath>$(SolutionDir)Timberborn\BepInEx\plugins\$(SolutionName)</TimberApiPath>
</PropertyGroup>

<Target Name="AutomaticCopyToTimberborn" BeforeTargets="AfterBuild" Condition="$(CopyDllToPath) != 'none'">
<Message Text="### Copy TimberApi common ###" Importance="high" />
<Copy SourceFiles="$(TargetDir)$(TargetFileName)" DestinationFolder="$(TimberApiPath)\core" />
</Target>
</Project>
46 changes: 3 additions & 43 deletions Core/TimberApi.Core/TimberApi.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,15 @@
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>9</LangVersion>
<Authors>TheBloodEyes</Authors>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ReleaseVersion>TIMBER_API_VERSION_PLACEHOLDER</ReleaseVersion>
</PropertyGroup>

<PropertyGroup>
<!-- Set to true if you want to use the live timberborn assemblies of the game, requires symlink -->
<UseLocalTimberbornSource>false</UseLocalTimberbornSource>
<!-- none: don't copy, bepinex: path to game > bepinex > plugins, timberapi: path to game > timberapi -->
<CopyDllToPath>none</CopyDllToPath>
</PropertyGroup>

<Import Project="$(SolutionDir)GameImports.targets" />

<ItemGroup>
<ProjectReference Include="..\TimberApi.Common\TimberApi.Common.csproj" />
<ProjectReference Include="..\TimberApi\TimberApi.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="GriffinPlus.Lib.FastActivator" Version="1.1.0" />
<PackageReference Include="Lib.Harmony" Version="2.2.2" NoWarn="NU1701" />
<PackageReference Include="MonoMod.RuntimeDetour" Version="21.12.13.1" />
<PackageReference Include="MonoMod.Utils" Version="22.5.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Collections.Immutable" Version="5.0.0" />
<PackageReference Include="Unity.InputSystem" Version="1.5.0" />
<PackageReference Include="UnityEngine.Modules" Version="2022.1.6" />
<PackageReference Include="Timberborn.GameLibs" Version="0.4.0-r.0" Condition="$(UseLocalTimberbornSource) == false" />
</ItemGroup>

<!-- Import dll's from Timberborn's symlink in solution folder-->
<ItemGroup Condition="$(UseLocalTimberbornSource)">
<Reference Include="$(SolutionDir)Timberborn\Timberborn_Data\Managed\Timberborn.*.dll">
<DestinationSubDirectory>libs/</DestinationSubDirectory>
</Reference>
<Reference Include="$(SolutionDir)Timberborn\Timberborn_Data\Managed\Bindito.*.dll">
<DestinationSubDirectory>libs/</DestinationSubDirectory>
</Reference>
</ItemGroup>

<!-- Used for automaticly transfer dll to Timberborn location, make a symlink `Timberborn` in the solution folder -->
<PropertyGroup Condition="$(CopyDllToPath) == 'timberapi'">
<TimberApiPath>$(SolutionDir)Timberborn\TimberAPI</TimberApiPath>
</PropertyGroup>

<PropertyGroup Condition="$(CopyDllToPath) == 'bepinex'">
<TimberApiPath>$(SolutionDir)Timberborn\BepInEx\plugins\$(SolutionName)</TimberApiPath>
</PropertyGroup>

<Target Name="AutomaticCopyToTimberborn" BeforeTargets="AfterBuild" Condition="$(CopyDllToPath) != 'none'">
<Message Text="### Copy TimberApi common ###" Importance="high" />
<Copy SourceFiles="$(TargetDir)$(TargetFileName)" DestinationFolder="$(TimberApiPath)\core" />
</Target>
</Project>
56 changes: 33 additions & 23 deletions Core/TimberApi/ObjectSelectionSystem/PickObjectTool.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Timberborn.Common;
using Timberborn.BaseComponentSystem;
using Timberborn.CoreUI;
using Timberborn.EntitySystem;
using Timberborn.InputSystem;
Expand All @@ -12,24 +10,35 @@

namespace TimberApi.ObjectSelectionSystem
{

// TODO: This class has commented code regarding custom cursor from PickObjectTool
// In the future the code can be uncommented, when the old cursor for the tool is recovered.
public class PickObjectTool : Tool, IInputProcessor
{
//private static readonly string CursorKey = "PickObjectCursor";

private readonly InputService _inputService;

private readonly ToolManager _toolManager;

private readonly Highlighter _highlighter;

private readonly Colors _colors;

private readonly EntityComponentRegistry _entityComponentRegistry;

//private readonly CursorService _cursorService;

private readonly SelectableObjectRaycaster _selectableObjectRaycaster;
private ToolDescription _toolDescription;
private string _warning;
private readonly HashSet<GameObject> _allCandidates = new HashSet<GameObject>();
private Func<GameObject, string> _validateCandidate;
private Action<GameObject> _callback;

private ToolDescription _toolDescription = null!;

private string _warning = "";

private readonly Dictionary<GameObject, BaseComponent> _allCandidates = new();

private Func<GameObject, string> _validateCandidate = null!;

private Action<GameObject> _callback = null!;

public PickObjectTool(InputService inputService, ToolManager toolManager, Highlighter highlighter, Colors colors, EntityComponentRegistry entityComponentRegistry, CursorService cursorService, SelectableObjectRaycaster selectableObjectRaycaster)
{
Expand Down Expand Up @@ -65,29 +74,31 @@ public override string WarningText()
return _warning;
}

public void StartPicking<T>(string title, string description, Func<GameObject, string> validateCandidate, Action<GameObject> callback) where T : MonoBehaviour, IRegisteredComponent
public void StartPicking<T>(string title, string description, Func<GameObject, string> validateCandidate, Action<GameObject> callback) where T : BaseComponent, IRegisteredComponent
{
_toolDescription = CreateDescription(title, description);
_validateCandidate = validateCandidate;
_callback = callback;
_allCandidates.Clear();
IEnumerable<GameObject> values = from component in _entityComponentRegistry.GetEnabled<T>()
select component.gameObject;
_allCandidates.AddRange(values);

foreach (var component in _entityComponentRegistry.GetEnabled<T>())
{
_allCandidates.Add(component.GameObjectFast, component);
}
_toolManager.SwitchTool(this);
}

}
public bool ProcessInput()
{
HighlightCandidates();
if (_selectableObjectRaycaster.TryHitSelectableObject(out var hitObject) && _allCandidates.Contains(hitObject))
if (_selectableObjectRaycaster.TryHitSelectableObject(out var hitObject) && _allCandidates.ContainsKey(hitObject.GameObjectFast))
{
_highlighter.HighlightSecondary(hitObject, _colors.EntitySelection);
_warning = _validateCandidate(hitObject);
if (_inputService.SelectionStart && !_inputService.MouseOverUI)
_warning = _validateCandidate(hitObject.GameObjectFast);
if (_inputService is { SelectionStart: true, MouseOverUI: false })
{
_toolManager.SwitchToDefaultTool();
_callback(hitObject);
_callback(hitObject.GameObjectFast);
return true;
}
}
Expand All @@ -98,16 +109,15 @@ public bool ProcessInput()
private void HighlightCandidates()
{
_highlighter.UnhighlightAllSecondary();
foreach (GameObject allCandidate in _allCandidates)
foreach (var allCandidate in _allCandidates)
{
Color color = ((_validateCandidate(allCandidate) == "") ? _colors.BuildablePreview : _colors.UnbuildablePreview);
_highlighter.HighlightSecondary(allCandidate, color);
var color = _validateCandidate(allCandidate.Key) == "" ? _colors.BuildablePreview : _colors.UnbuildablePreview; _highlighter.HighlightSecondary(allCandidate.Value, color);
}
}

private static ToolDescription CreateDescription(string title, string description)
{
ToolDescription.Builder builder = new ToolDescription.Builder(title);
var builder = new ToolDescription.Builder(title);
builder.AddSection(description);
return builder.Build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ internal class PathShaderApplier : IShaderApplier

public void LoadShader()
{
_pathShader = Resources.Load<GameObject>("Buildings/Paths/Path/Path.Folktails")
.GetComponentInChildren<MeshRenderer>().materials[0].shader;
_pathShader = Resources.Load<Material>("buildings/paths/path/Path.Folktails").shader;
}

public bool ShouldApplyShader(Material material)
Expand Down
3 changes: 1 addition & 2 deletions Core/TimberApi/ShaderSystem/ShaderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ private Shader Shader
{
if (_shader == null)
{
_shader = Resources.Load<GameObject>("Buildings/Paths/Platform/Platform.Full.Folktails")
.GetComponent<MeshRenderer>().materials[0].shader;
_shader = Resources.Load<Material>("materials/goods/Box").shader;
}

return _shader;
Expand Down
3 changes: 2 additions & 1 deletion Core/TimberApi/ShaderSystem/ShaderSystemConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ internal class ShaderApplierConfigurator : IConfigurator
{
public void Configure(IContainerDefinition containerDefinition)
{
containerDefinition.MultiBind<IShaderApplier>().To<DirtUrpApplier>().AsSingleton();
// TODO: Not yet found
// containerDefinition.MultiBind<IShaderApplier>().To<DirtUrpApplier>().AsSingleton();
containerDefinition.MultiBind<IShaderApplier>().To<PathShaderApplier>().AsSingleton();
}
}
Expand Down
48 changes: 3 additions & 45 deletions Core/TimberApi/TimberApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@
<Nullable>enable</Nullable>
<LangVersion>9</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Authors>hawkfalcon, TheBloodEyes, thundersen</Authors>
<Authors>Hawkfalcon, TheBloodEyes, Thundersen, Hythonhan</Authors>
<PackageProjectUrl>https://timberapi.com</PackageProjectUrl>
<PackageLicenseExpression>LGPL-2.1-or-later</PackageLicenseExpression>
<ReleaseVersion>TIMBER_API_VERSION_PLACEHOLDER</ReleaseVersion>
</PropertyGroup>

<PropertyGroup>
<!-- Set to true if you want to use the live timberborn assemblies of the game, requires symlink -->
<UseLocalTimberbornSource>false</UseLocalTimberbornSource>
<!-- none: don't copy, bepinex: path to game > bepinex > plugins, timberapi: path to game > timberapi -->
<CopyDllToPath>none</CopyDllToPath>
</PropertyGroup>

<Import Project="$(SolutionDir)GameImports.targets" />

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>TimberApi.Core</_Parameter1>
Expand All @@ -26,41 +21,4 @@
<ItemGroup>
<ProjectReference Include="..\TimberApi.Common\TimberApi.Common.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Lib.Harmony" Version="2.2.2" NoWarn="NU1701" />
<PackageReference Include="Threenine.LinqToCsv" Version="1.6.0" />
<PackageReference Include="MonoMod.Utils" Version="22.5.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Collections.Immutable" Version="5.0.0" />
<PackageReference Include="UnityEngine.Modules" Version="2022.1.6" IncludeAssets="compile" />
<PackageReference Include="Timberborn.GameLibs" Version="0.4.0-r.0" Condition="$(UseLocalTimberbornSource) == false" />
</ItemGroup>

<!-- Import dll's from Timberborn's symlink in solution folder-->
<ItemGroup Condition="$(UseLocalTimberbornSource)">
<Reference Include="$(SolutionDir)Timberborn\Timberborn_Data\Managed\Timberborn.*.dll">
<DestinationSubDirectory>libs/</DestinationSubDirectory>
</Reference>
<Reference Include="$(SolutionDir)Timberborn\Timberborn_Data\Managed\Bindito.*.dll">
<DestinationSubDirectory>libs/</DestinationSubDirectory>
</Reference>
</ItemGroup>
<ItemGroup>
<Folder Include="ThunderstorePackage\" />
</ItemGroup>

<!-- Used for automaticly transfer dll to Timberborn location, make a symlink `Timberborn` in the solution folder -->
<PropertyGroup Condition="$(CopyDllToPath) == 'timberapi'">
<TimberApiPath>$(SolutionDir)Timberborn\TimberAPI</TimberApiPath>
</PropertyGroup>

<PropertyGroup Condition="$(CopyDllToPath) == 'bepinex'">
<TimberApiPath>$(SolutionDir)Timberborn\BepInEx\plugins\$(SolutionName)</TimberApiPath>
</PropertyGroup>

<Target Name="AutomaticCopyToTimberborn" BeforeTargets="AfterBuild" Condition="$(CopyDllToPath) != 'none'">
<Message Text="### Copy TimberApi common ###" Importance="high" />
<Copy SourceFiles="$(TargetDir)$(TargetFileName)" DestinationFolder="$(TimberApiPath)\core" />
</Target>
</Project>
Loading

0 comments on commit 2b384d2

Please sign in to comment.