This commit is contained in:
Lachlan Leone
2024-01-27 03:50:35 +11:00
parent 2d6abcd684
commit 4dd11a9f73
11 changed files with 265 additions and 27 deletions
+4
View File
@@ -0,0 +1,4 @@
# Release Notes v0.1.3
- Added method to disable deselect pets
- Added preference to toggle pet collision
+4
View File
@@ -0,0 +1,4 @@
[h1]Release Notes v0.1.3[/h1]
- Added method to disable deselect pets
- Added preference to toggle pet collision
+1
View File
@@ -37,6 +37,7 @@ namespace Pets.Customs.Types
view.agent = Prefab.GetComponentInChildren<NavMeshAgent>(); view.agent = Prefab.GetComponentInChildren<NavMeshAgent>();
view.animator = Prefab.GetComponentInChildren<Animator>(); view.animator = Prefab.GetComponentInChildren<Animator>();
view.vfx = Prefab.GetComponentInChildren<VisualEffect>(); view.vfx = Prefab.GetComponentInChildren<VisualEffect>();
view.Colliders = new List<Collider>(Prefab.GetComponentsInChildren<Collider>());
TextMeshPro tmp = Prefab.GetComponentInChildren<TextMeshPro>(); TextMeshPro tmp = Prefab.GetComponentInChildren<TextMeshPro>();
if (tmp != null) if (tmp != null)
{ {
+2 -1
View File
@@ -12,6 +12,7 @@ namespace Pets.Menus
return new PetGridMenu(Pets, container, player, has_back); return new PetGridMenu(Pets, container, player, has_back);
} }
public List<Pet> Pets = new List<Pet>(); public List<Pet> _Pets = new List<Pet>();
public List<int> Pets = new List<int>();
} }
} }
+12 -6
View File
@@ -1,31 +1,37 @@
using System.Collections.Generic; using System.Collections.Generic;
using Kitchen; using Kitchen;
using Kitchen.Modules; using Kitchen.Modules;
using KitchenData;
using Pets.Customs.Types; using Pets.Customs.Types;
using Pets.Views; using Pets.Views;
using UnityEngine; using UnityEngine;
namespace Pets.Menus namespace Pets.Menus
{ {
public class PetGridMenu : GridMenu<Pet> public class PetGridMenu : GridMenu<int>
{ {
public PetGridMenu(List<Pet> items, Transform container, int player, bool has_back) : base(items, container, player, has_back) public PetGridMenu(List<int> items, Transform container, int player, bool has_back) : base(items, container, player, has_back)
{ {
} }
protected override int ColumnLength => 3; protected override int ColumnLength => 3;
protected override void SetupElement(Pet item, GridMenuElement element) protected override void SetupElement(int item, GridMenuElement element)
{ {
element.Set(PrefabSnapshot.GetSnapshot(item.IconPrefab)); if (item == 0)
{
element.Set(Mod.Bundle.LoadAsset<Texture2D>("None"));
return;
}
element.Set(PrefabSnapshot.GetSnapshot(GameData.Main.Get<Pet>(item).IconPrefab));
} }
protected override void OnSelect(Pet item) protected override void OnSelect(int item)
{ {
if (Player != 0 && item != null) if (Player != 0 && item != null)
{ {
PetRequestView.PlayerID = Player; PetRequestView.PlayerID = Player;
PetRequestView.PetID = item.ID; PetRequestView.PetID = item;
} }
} }
} }
+36
View File
@@ -0,0 +1,36 @@
using System.Collections.Generic;
using Kitchen;
using Kitchen.Modules;
using KitchenLib;
using KitchenLib.Preferences;
using UnityEngine;
namespace Pets.Menus
{
public class PreferenceMenu<T>: KLMenu<T>
{
public PreferenceMenu(Transform container, ModuleList module_list) : base(container, module_list)
{
}
private Option<bool> petsHaveColliders = new Option<bool>(new List<bool> { true, false }, Mod.manager.GetPreference<PreferenceBool>("petsHaveColliders").Value, new List<string> { "Enabled", "Disabled" });
public override void Setup(int player_id)
{
AddLabel("Pet Colliders");
New<SpacerElement>(true);
AddSelect(petsHaveColliders);
petsHaveColliders.OnChanged += delegate (object _, bool result)
{
Mod.manager.GetPreference<PreferenceBool>("petsHaveColliders").Set(result);
};
New<SpacerElement>(true);
New<SpacerElement>(true);
AddButton(base.Localisation["MENU_BACK_SETTINGS"], delegate(int i)
{
Mod.manager.Save();
RequestPreviousMenu();
});
}
}
}
+33 -11
View File
@@ -4,12 +4,14 @@ using KitchenLib.Logging.Exceptions;
using KitchenMods; using KitchenMods;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using Kitchen;
using Kitchen.Modules; using Kitchen.Modules;
using KitchenLib.Event;
using KitchenLib.Interfaces; using KitchenLib.Interfaces;
using KitchenLib.Preferences;
using KitchenLib.Utils; using KitchenLib.Utils;
using Pets.Components; using Pets.Components;
using Pets.Customs; using Pets.Customs;
using Pets.Customs.Types;
using Pets.Menus; using Pets.Menus;
using Pets.Views; using Pets.Views;
using UnityEngine; using UnityEngine;
@@ -20,12 +22,13 @@ namespace Pets
{ {
public const string MOD_GUID = "com.starfluxgames.pets"; public const string MOD_GUID = "com.starfluxgames.pets";
public const string MOD_NAME = "Pets"; public const string MOD_NAME = "Pets";
public const string MOD_VERSION = "0.1.2"; public const string MOD_VERSION = "0.1.3";
public const string MOD_AUTHOR = "StarFluxGames"; public const string MOD_AUTHOR = "StarFluxGames";
public const string MOD_GAMEVERSION = ">=1.1.8"; public const string MOD_GAMEVERSION = ">=1.1.8";
public static AssetBundle Bundle; public static AssetBundle Bundle;
public static KitchenLogger Logger; public static KitchenLogger Logger;
public static PreferenceManager manager;
public static float MinimumSpeedThreshold = 0.1f; public static float MinimumSpeedThreshold = 0.1f;
@@ -40,15 +43,16 @@ namespace Pets
if (grid.name == "Root") if (grid.name == "Root")
{ {
GridMenuPetConfig config = new GridMenuPetConfig(); GridMenuPetConfig config = new GridMenuPetConfig();
config.Pets.Add(GDOUtils.GetCustomGameDataObject<Goose>().GameDataObject as Pet); config.Pets.Add(0);
config.Pets.Add(GDOUtils.GetCustomGameDataObject<Penguin>().GameDataObject as Pet); config.Pets.Add(GDOUtils.GetCustomGameDataObject<Goose>().ID);
config.Pets.Add(GDOUtils.GetCustomGameDataObject<Cat>().GameDataObject as Pet); config.Pets.Add(GDOUtils.GetCustomGameDataObject<Penguin>().ID);
config.Pets.Add(GDOUtils.GetCustomGameDataObject<Chick>().GameDataObject as Pet); config.Pets.Add(GDOUtils.GetCustomGameDataObject<Cat>().ID);
config.Pets.Add(GDOUtils.GetCustomGameDataObject<Rabbit>().GameDataObject as Pet); config.Pets.Add(GDOUtils.GetCustomGameDataObject<Chick>().ID);
config.Pets.Add(GDOUtils.GetCustomGameDataObject<Squirrel>().GameDataObject as Pet); config.Pets.Add(GDOUtils.GetCustomGameDataObject<Rabbit>().ID);
config.Pets.Add(GDOUtils.GetCustomGameDataObject<DogChihuahua>().GameDataObject as Pet); config.Pets.Add(GDOUtils.GetCustomGameDataObject<Squirrel>().ID);
config.Pets.Add(GDOUtils.GetCustomGameDataObject<Elephant>().GameDataObject as Pet); config.Pets.Add(GDOUtils.GetCustomGameDataObject<DogChihuahua>().ID);
config.Pets.Add(GDOUtils.GetCustomGameDataObject<Seal>().GameDataObject as Pet); config.Pets.Add(GDOUtils.GetCustomGameDataObject<Elephant>().ID);
config.Pets.Add(GDOUtils.GetCustomGameDataObject<Seal>().ID);
config.Icon = Bundle.LoadAsset<Texture2D>("PawPrint"); config.Icon = Bundle.LoadAsset<Texture2D>("PawPrint");
grid.Links.Add(config); grid.Links.Add(config);
} }
@@ -60,6 +64,24 @@ namespace Pets
Bundle = mod.GetPacks<AssetBundleModPack>().SelectMany(e => e.AssetBundles).FirstOrDefault() ?? throw new MissingAssetBundleException(MOD_GUID); Bundle = mod.GetPacks<AssetBundleModPack>().SelectMany(e => e.AssetBundles).FirstOrDefault() ?? throw new MissingAssetBundleException(MOD_GUID);
Logger = InitLogger(); Logger = InitLogger();
manager = new PreferenceManager(MOD_GUID);
manager.RegisterPreference(new PreferenceBool("petsHaveColliders", true));
manager.Load();
manager.Save();
ModsPreferencesMenu<MainMenuAction>.RegisterMenu(MOD_NAME, typeof(PreferenceMenu<MainMenuAction>), typeof(MainMenuAction));
ModsPreferencesMenu<PauseMenuAction>.RegisterMenu(MOD_NAME, typeof(PreferenceMenu<PauseMenuAction>), typeof(PauseMenuAction));
Events.MainMenuView_SetupMenusEvent += (s, args) =>
{
args.addMenu.Invoke(args.instance, new object[] { typeof(PreferenceMenu<MainMenuAction>), new PreferenceMenu<MainMenuAction>(args.instance.ButtonContainer, args.module_list) });
};
Events.PlayerPauseView_SetupMenusEvent += (s, args) =>
{
args.addMenu.Invoke(args.instance, new object[] { typeof(PreferenceMenu<PauseMenuAction>), new PreferenceMenu<PauseMenuAction>(args.instance.ButtonContainer, args.module_list) });
};
ViewUtils.RegisterView("Pets.Views.PetRequestView", typeof(SPetRequestView), typeof(PetRequestView)); ViewUtils.RegisterView("Pets.Views.PetRequestView", typeof(SPetRequestView), typeof(PetRequestView));
} }
} }
+151
View File
@@ -0,0 +1,151 @@
using System.Collections.Generic;
using Kitchen;
using KitchenData;
using KitchenMods;
using Pets.Components;
using Pets.Customs.Types;
using Pets.Enums;
using Unity.Collections;
using Unity.Entities;
using UnityEngine;
namespace Pets.Systems.EditorMenu
{
public class SpawnDebugPets : GameSystemBase
{
private EntityQuery _displayPets;
protected override void Initialise()
{
return;
base.Initialise();
_displayPets = GetEntityQuery(typeof(CDisplayPet));
foreach (Pet pet in GameData.Main.Get<Pet>())
{
_pets.Add(pet);
}
}
private Vector3 _spawnPosition = new Vector3(0, 0, 0);
private Vector3 facing = new Vector3(0, 0, 0);
private List<Pet> _pets = new List<Pet>();
private int _selectedPet = 0;
protected override void OnUpdate()
{
return;
using NativeArray<Entity> displayPets = _displayPets.ToEntityArray(Allocator.Temp);
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
_spawnPosition.x -= 1;
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
_spawnPosition.x += 1;
}
if (Input.GetKeyDown(KeyCode.UpArrow))
{
_spawnPosition.z += 1;
}
if (Input.GetKeyDown(KeyCode.DownArrow))
{
_spawnPosition.z -= 1;
}
if (Input.GetKeyDown(KeyCode.Keypad2))
{
facing = _spawnPosition;
facing.z -= 1;
}
if (Input.GetKeyDown(KeyCode.Keypad4))
{
facing = _spawnPosition;
facing.x -= 1;
}
if (Input.GetKeyDown(KeyCode.Keypad6))
{
facing = _spawnPosition;
facing.x += 1;
}
if (Input.GetKeyDown(KeyCode.Keypad8))
{
facing = _spawnPosition;
facing.z += 1;
}
if (Input.GetKeyDown(KeyCode.Keypad7))
{
facing = _spawnPosition;
facing.x -= 1;
facing.z += 1;
}
if (Input.GetKeyDown(KeyCode.Keypad9))
{
facing = _spawnPosition;
facing.x += 1;
facing.z += 1;
}
if (Input.GetKeyDown(KeyCode.Keypad1))
{
facing = _spawnPosition;
facing.x -= 1;
facing.z -= 1;
}
if (Input.GetKeyDown(KeyCode.Keypad3))
{
facing = _spawnPosition;
facing.x += 1;
facing.z -= 1;
}
for (int i = 0; i < displayPets.Length; i++)
{
Entity displayPet = displayPets[i];
EntityManager.AddComponentData(displayPet, new CPosition(_spawnPosition));
EntityManager.AddComponentData(displayPet, new CMoveToLocation
{
Location = _spawnPosition,
DesiredFacing = facing
});
}
if (Input.GetKeyDown(KeyCode.G))
{
for (int i = 0; i < displayPets.Length; i++)
{
Entity displayPet = displayPets[i];
EntityManager.DestroyEntity(displayPet);
}
if (_selectedPet < _pets.Count - 1)
{
_selectedPet++;
}
else
{
_selectedPet = 0;
}
Entity pet = EntityManager.CreateEntity();
EntityManager.AddComponentData(pet, new CPet
{
State = PetState.Idle,
PetType = _pets[_selectedPet].ID
});
EntityManager.AddComponentData(pet, new CPosition(_spawnPosition));
EntityManager.AddComponentData(pet, new CRequiresView
{
Type = _pets[_selectedPet].ViewType,
PhysicsDriven = true
});
EntityManager.AddComponentData(pet, new CDoNotPersist());
EntityManager.AddComponentData(pet, new CDisplayPet());
}
}
}
}
+4 -4
View File
@@ -91,10 +91,6 @@ namespace Pets.Systems
protected bool CanGetTo(Vector3 startingPosition, Vector3 targetPosition, Vector3 targetOffset, out Vector3 targetDestination, bool ShowDebugSpheres = false) protected bool CanGetTo(Vector3 startingPosition, Vector3 targetPosition, Vector3 targetOffset, out Vector3 targetDestination, bool ShowDebugSpheres = false)
{ {
if (!ShowDebugSpheres)
Mod.Logger.LogInfo("");
if (ShowDebugSpheres) if (ShowDebugSpheres)
{ {
if (point1 != null) if (point1 != null)
@@ -154,8 +150,12 @@ namespace Pets.Systems
return false; return false;
} }
if (ShowDebugSpheres)
{
point1.GetComponent<MeshRenderer>().material = MaterialUtils.GetExistingMaterial("AppleGreen"); point1.GetComponent<MeshRenderer>().material = MaterialUtils.GetExistingMaterial("AppleGreen");
point2.GetComponent<MeshRenderer>().material = MaterialUtils.GetExistingMaterial("AppleGreen"); point2.GetComponent<MeshRenderer>().material = MaterialUtils.GetExistingMaterial("AppleGreen");
}
return true; return true;
} }
+14 -1
View File
@@ -1,7 +1,9 @@
using System; using System;
using System.Collections.Generic;
using Controllers; using Controllers;
using Kitchen; using Kitchen;
using KitchenData; using KitchenData;
using KitchenLib.Preferences;
using KitchenMods; using KitchenMods;
using MessagePack; using MessagePack;
using Pets.Components; using Pets.Components;
@@ -22,6 +24,7 @@ namespace Pets.Views
public VisualEffect vfx; public VisualEffect vfx;
public GameObject warningIcon; public GameObject warningIcon;
public TextMeshPro label; public TextMeshPro label;
public List<Collider> Colliders;
public override void SetPosition(UpdateViewPositionData pos) public override void SetPosition(UpdateViewPositionData pos)
{ {
@@ -81,7 +84,8 @@ namespace Pets.Views
PreferedFacingDirection = PreferedFacingDirection, PreferedFacingDirection = PreferedFacingDirection,
State = cPet.State, State = cPet.State,
RequestingInputSource = RequestingInputSource, RequestingInputSource = RequestingInputSource,
PetName = cPet.PetName.Value PetName = cPet.PetName.Value,
EnableColliders = Mod.manager.GetPreference<PreferenceBool>("petsHaveColliders").Value
}); });
if (ApplyUpdates(cLinkedView, (data) => if (ApplyUpdates(cLinkedView, (data) =>
{ {
@@ -131,6 +135,7 @@ namespace Pets.Views
[Key(4)] public PetState State; [Key(4)] public PetState State;
[Key(5)] public int RequestingInputSource; [Key(5)] public int RequestingInputSource;
[Key(6)] public string PetName; [Key(6)] public string PetName;
[Key(7)] public bool EnableColliders;
} }
[MessagePackObject(false)] [MessagePackObject(false)]
@@ -226,6 +231,14 @@ namespace Pets.Views
label.font = GameData.Main.GlobalLocalisation.Fonts[KitchenData.Font.Default]; label.font = GameData.Main.GlobalLocalisation.Fonts[KitchenData.Font.Default];
label.text = Data.PetName; label.text = Data.PetName;
} }
if (Colliders != null)
{
foreach (Collider collider in Colliders)
{
collider.enabled = Data.EnableColliders;
}
}
} }
} }
} }