From 1a7c2ca509a7cd144bfa2e23f837b97c1973a4a8 Mon Sep 17 00:00:00 2001 From: mertwole Date: Tue, 20 Aug 2024 19:51:26 +0400 Subject: [PATCH] Refactor employee personality --- .../Assets/Prefabs/Employee/Employee.prefab | 16 --- ...{EmployeeNameList.asset => NameList.asset} | 4 +- ...ameList.asset.meta => NameList.asset.meta} | 2 +- .../Level Configs/TestLevel/Day01.asset | 53 ++------ .../TestLevel/TestLevelConfig.asset | 44 +------ .../Assets/Scripts/Employee/EmployeeImpl.cs | 41 +++++- .../Scripts/Employee/ExtendedInfo/View.cs | 8 +- .../Scripts/Employee/Personality/Config.meta | 8 ++ .../Personality/NameList.cs} | 6 +- .../Personality/NameList.cs.meta} | 2 +- .../Employee/Personality/PersonalityImpl.cs | 122 +++++++++++++---- .../Personality/PersonalityImpl.cs.meta | 22 ++-- .../Assets/Scripts/Level/Config/DayAction.cs | 8 +- .../Assets/Scripts/Level/Config/Employee.cs | 123 ------------------ .../Scripts/Level/Config/Employee.cs.meta | 11 -- .../Assets/Scripts/Level/Shop/Controller.cs | 7 +- .../Scripts/Level/Shop/Employee/CardView.cs | 9 +- JamGame/Assets/Scripts/Level/Shop/Model.cs | 10 +- .../Scripts/Level/Shop/View/Employees.cs | 12 +- .../Scripts/Location/EmployeeManager/Model.cs | 6 +- 20 files changed, 207 insertions(+), 307 deletions(-) rename JamGame/Assets/ScriptableObjects/Employee Configs/{EmployeeNameList.asset => NameList.asset} (86%) rename JamGame/Assets/ScriptableObjects/Employee Configs/{EmployeeNameList.asset.meta => NameList.asset.meta} (79%) create mode 100644 JamGame/Assets/Scripts/Employee/Personality/Config.meta rename JamGame/Assets/Scripts/{Level/Config/EmployeeNameList.cs => Employee/Personality/NameList.cs} (76%) rename JamGame/Assets/Scripts/{Level/Config/EmployeeNameList.cs.meta => Employee/Personality/NameList.cs.meta} (83%) delete mode 100644 JamGame/Assets/Scripts/Level/Config/Employee.cs delete mode 100644 JamGame/Assets/Scripts/Level/Config/Employee.cs.meta diff --git a/JamGame/Assets/Prefabs/Employee/Employee.prefab b/JamGame/Assets/Prefabs/Employee/Employee.prefab index 9b089961..9521fa2d 100644 --- a/JamGame/Assets/Prefabs/Employee/Employee.prefab +++ b/JamGame/Assets/Prefabs/Employee/Employee.prefab @@ -419,7 +419,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 735ac89528270c746b09f4c604991e52, type: 3} m_Name: m_EditorClassIdentifier: - personality: {fileID: 7027475554387804411} employee: {fileID: 7027475554387804409} name_text: {fileID: 8271836159909123415} quirkViewsLabel: @@ -849,7 +848,6 @@ GameObject: - component: {fileID: 7027475554387804391} - component: {fileID: 7027475554387804408} - component: {fileID: 7027475554387804409} - - component: {fileID: 7027475554387804411} - component: {fileID: 6274426418331602746} - component: {fileID: 7027475554387804412} - component: {fileID: 744904379} @@ -1007,20 +1005,6 @@ MonoBehaviour: incomeGenerator: {fileID: 2575964175689351513} keepDistanceFromNextInLine: {x: 1.2, y: 1.3} registeredModifiers: [] ---- !u!114 &7027475554387804411 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7027475554387804413} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 1c3a921a269683844adf1acfc030e74d, type: 3} - m_Name: - m_EditorClassIdentifier: - name_: John - quirks: [] --- !u!114 &6274426418331602746 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/JamGame/Assets/ScriptableObjects/Employee Configs/EmployeeNameList.asset b/JamGame/Assets/ScriptableObjects/Employee Configs/NameList.asset similarity index 86% rename from JamGame/Assets/ScriptableObjects/Employee Configs/EmployeeNameList.asset rename to JamGame/Assets/ScriptableObjects/Employee Configs/NameList.asset index 9d2b4fcc..5960134f 100644 --- a/JamGame/Assets/ScriptableObjects/Employee Configs/EmployeeNameList.asset +++ b/JamGame/Assets/ScriptableObjects/Employee Configs/NameList.asset @@ -9,8 +9,8 @@ MonoBehaviour: m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 57826b9781e118947a17eb4a12484c96, type: 3} - m_Name: EmployeeNameList + m_Script: {fileID: 11500000, guid: 17fdcae30752e9a4d92db845ff3d3ffb, type: 3} + m_Name: NameList m_EditorClassIdentifier: firstNames: - Hudson diff --git a/JamGame/Assets/ScriptableObjects/Employee Configs/EmployeeNameList.asset.meta b/JamGame/Assets/ScriptableObjects/Employee Configs/NameList.asset.meta similarity index 79% rename from JamGame/Assets/ScriptableObjects/Employee Configs/EmployeeNameList.asset.meta rename to JamGame/Assets/ScriptableObjects/Employee Configs/NameList.asset.meta index 618ded2b..c9c25a71 100644 --- a/JamGame/Assets/ScriptableObjects/Employee Configs/EmployeeNameList.asset.meta +++ b/JamGame/Assets/ScriptableObjects/Employee Configs/NameList.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 9cfeb54453d2df345b5583d794c43760 +guid: d3768e6f3adf815449b7c57a30e90b99 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/JamGame/Assets/ScriptableObjects/Level Configs/TestLevel/Day01.asset b/JamGame/Assets/ScriptableObjects/Level Configs/TestLevel/Day01.asset index c9fdf269..17de892a 100644 --- a/JamGame/Assets/ScriptableObjects/Level Configs/TestLevel/Day01.asset +++ b/JamGame/Assets/ScriptableObjects/Level Configs/TestLevel/Day01.asset @@ -27,6 +27,13 @@ MonoBehaviour: references: version: 2 RefIds: + - rid: 4331002058033856516 + type: {class: FixedConfig, ns: Employee.Personality, asm: Assembly-CSharp} + data: + name: John Appleseed + hireCost: 100 + profession: Software Engineer + quirks: [] - rid: 8023115963875983388 type: {class: Cutscene, ns: Level.Config, asm: Assembly-CSharp} data: @@ -54,9 +61,7 @@ MonoBehaviour: type: {class: Meeting, ns: Level.Config, asm: Assembly-CSharp} data: shopEmployees: - - rid: 8023115963875983399 - - rid: 8023115963875983400 - - rid: 8023115963875983406 + - rid: 4331002058033856516 mode: 1 shopRooms: - rid: 8023115963875983401 @@ -92,34 +97,6 @@ MonoBehaviour: duration: seconds: 1.5 text: Day Ended - - rid: 8023115963875983399 - type: {class: RandomEmployeeConfig, ns: Level.Config, asm: Assembly-CSharp} - data: - nameList: {fileID: 11400000, guid: 9cfeb54453d2df345b5583d794c43760, type: 2} - costRange: - Min: 10 - Max: 60 - Multiply: 5 - quirkList: - QuirkChance: 0.2 - Quirks: - - {fileID: 11400000, guid: 1156cf1b31295974b9f193ed3f761170, type: 2} - - {fileID: 11400000, guid: f0e19fd7eb5f01940a1e652f0dbc564f, type: 2} - - {fileID: 11400000, guid: e251cd156eeb0a343a3b80129ea24798, type: 2} - - rid: 8023115963875983400 - type: {class: RandomEmployeeConfig, ns: Level.Config, asm: Assembly-CSharp} - data: - nameList: {fileID: 11400000, guid: 9cfeb54453d2df345b5583d794c43760, type: 2} - costRange: - Min: 10 - Max: 60 - Multiply: 5 - quirkList: - QuirkChance: 0.2 - Quirks: - - {fileID: 11400000, guid: 1156cf1b31295974b9f193ed3f761170, type: 2} - - {fileID: 11400000, guid: f0e19fd7eb5f01940a1e652f0dbc564f, type: 2} - - {fileID: 11400000, guid: e251cd156eeb0a343a3b80129ea24798, type: 2} - rid: 8023115963875983401 type: {class: FixedRoomConfig, ns: Level.Config, asm: Assembly-CSharp} data: @@ -128,17 +105,3 @@ MonoBehaviour: type: {class: FixedRoomConfig, ns: Level.Config, asm: Assembly-CSharp} data: room: {fileID: 739786844684371711, guid: 12f9d01fff44d1f469de9bec77ff7e01, type: 3} - - rid: 8023115963875983406 - type: {class: RandomEmployeeConfig, ns: Level.Config, asm: Assembly-CSharp} - data: - nameList: {fileID: 11400000, guid: 9cfeb54453d2df345b5583d794c43760, type: 2} - costRange: - Min: 10 - Max: 60 - Multiply: 5 - quirkList: - QuirkChance: 0.2 - Quirks: - - {fileID: 11400000, guid: 1156cf1b31295974b9f193ed3f761170, type: 2} - - {fileID: 11400000, guid: f0e19fd7eb5f01940a1e652f0dbc564f, type: 2} - - {fileID: 11400000, guid: e251cd156eeb0a343a3b80129ea24798, type: 2} diff --git a/JamGame/Assets/ScriptableObjects/Level Configs/TestLevel/TestLevelConfig.asset b/JamGame/Assets/ScriptableObjects/Level Configs/TestLevel/TestLevelConfig.asset index 52979a15..6cb0b182 100644 --- a/JamGame/Assets/ScriptableObjects/Level Configs/TestLevel/TestLevelConfig.asset +++ b/JamGame/Assets/ScriptableObjects/Level Configs/TestLevel/TestLevelConfig.asset @@ -54,9 +54,7 @@ MonoBehaviour: type: {class: Meeting, ns: Level.Config, asm: Assembly-CSharp} data: shopEmployees: - - rid: 8023115963875983386 - - rid: 8023115963875983387 - - rid: 8023115963875983405 + - rid: 4331002058033856515 mode: 1 shopRooms: - rid: 1908735064151687180 @@ -117,28 +115,14 @@ MonoBehaviour: type: {class: FixedRoomConfig, ns: Level.Config, asm: Assembly-CSharp} data: room: {fileID: 739786844684371711, guid: 12f9d01fff44d1f469de9bec77ff7e01, type: 3} - - rid: 8023115963875983386 - type: {class: RandomEmployeeConfig, ns: Level.Config, asm: Assembly-CSharp} + - rid: 4331002058033856515 + type: {class: RandomConfig, ns: Employee.Personality.Config, asm: Assembly-CSharp} data: - nameList: {fileID: 11400000, guid: 9cfeb54453d2df345b5583d794c43760, type: 2} + nameList: {fileID: 11400000, guid: d3768e6f3adf815449b7c57a30e90b99, type: 2} costRange: - Min: 10 - Max: 60 - Multiply: 5 - quirkList: - QuirkChance: 0.2 - Quirks: - - {fileID: 11400000, guid: 1156cf1b31295974b9f193ed3f761170, type: 2} - - {fileID: 11400000, guid: f0e19fd7eb5f01940a1e652f0dbc564f, type: 2} - - {fileID: 11400000, guid: e251cd156eeb0a343a3b80129ea24798, type: 2} - - rid: 8023115963875983387 - type: {class: RandomEmployeeConfig, ns: Level.Config, asm: Assembly-CSharp} - data: - nameList: {fileID: 11400000, guid: 9cfeb54453d2df345b5583d794c43760, type: 2} - costRange: - Min: 10 - Max: 60 - Multiply: 5 + Min: 5 + Max: 30 + Multiply: 10 quirkList: QuirkChance: 0.2 Quirks: @@ -151,17 +135,3 @@ MonoBehaviour: configMode: 1 dayActions: [] preset: {fileID: 11400000, guid: b6e7115d9042bb04398c4f272c0e0ac5, type: 2} - - rid: 8023115963875983405 - type: {class: RandomEmployeeConfig, ns: Level.Config, asm: Assembly-CSharp} - data: - nameList: {fileID: 11400000, guid: 9cfeb54453d2df345b5583d794c43760, type: 2} - costRange: - Min: 10 - Max: 60 - Multiply: 5 - quirkList: - QuirkChance: 0.2 - Quirks: - - {fileID: 11400000, guid: 1156cf1b31295974b9f193ed3f761170, type: 2} - - {fileID: 11400000, guid: f0e19fd7eb5f01940a1e652f0dbc564f, type: 2} - - {fileID: 11400000, guid: e251cd156eeb0a343a3b80129ea24798, type: 2} diff --git a/JamGame/Assets/Scripts/Employee/EmployeeImpl.cs b/JamGame/Assets/Scripts/Employee/EmployeeImpl.cs index 2338b1ab..69430682 100644 --- a/JamGame/Assets/Scripts/Employee/EmployeeImpl.cs +++ b/JamGame/Assets/Scripts/Employee/EmployeeImpl.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; using System.Linq; +using Common; using Employee.Controller; using Employee.Needs; +using Employee.Personality; using Employee.StressMeter; -using Level.Config; +using Level.Boss.Task; using Level.GlobalTime; using Location; using Sirenix.OdinInspector; @@ -62,6 +64,13 @@ public NeedProviderManager NeedProviderManager [SerializeField] private Vector2 keepDistanceFromNextInLine = new(1.0f, 1.5f); + [SerializeField] + [ReadOnly] + private PersonalityImpl personality; + public PersonalityImpl Personality => personality; + + private DataProvider employeeQuirksDataProvider; + private void OnEnable() { controller.OnReachedNeedProvider += ReachedNeedProvider; @@ -335,9 +344,35 @@ public void ReleasedFromNeedProvider() controller.SetNavigationMode(ControllerImpl.NavigationMode.Navmesh); } - public void SetConfig(EmployeeConfig employeeConfig) + public void SetPersonality(PersonalityImpl personality) { - // TODO: Implement config filling (#121) + if (this.personality != null) + { + Debug.LogError( + "Attempted to set personality config for already initialized employee" + ); + return; + } + + this.personality = personality; + + foreach (Quirk quirk in personality.Quirks) + { + foreach (Need.NeedProperties additional_need in quirk.AdditionalNeeds) + { + AddNeed(additional_need); + } + + foreach (IEffect effect in quirk.Effects) + { + RegisterEffect(effect); + } + } + + employeeQuirksDataProvider = new DataProvider( + () => new EmployeeQuirks() { Quirks = this.personality.Quirks }, + DataProviderServiceLocator.ResolveType.MultipleSources + ); } } } diff --git a/JamGame/Assets/Scripts/Employee/ExtendedInfo/View.cs b/JamGame/Assets/Scripts/Employee/ExtendedInfo/View.cs index 4e9fdae4..0c562c1c 100644 --- a/JamGame/Assets/Scripts/Employee/ExtendedInfo/View.cs +++ b/JamGame/Assets/Scripts/Employee/ExtendedInfo/View.cs @@ -16,10 +16,6 @@ public class View : MonoBehaviour { private Camera cam; - [SerializeField] - [Required] - private PersonalityImpl personality; - [SerializeField] [Required] private EmployeeImpl employee; @@ -69,7 +65,7 @@ private void Awake() AddBuff(buff); } - foreach (Quirk quirk in personality.Quirks) + foreach (Quirk quirk in employee.Personality.Quirks) { AddQuirk(quirk); } @@ -95,7 +91,7 @@ private void InitModelViewMaps() private void Update() { transform.LookAt(cam.transform.position); - name_text.text = $"{personality.Name}"; + name_text.text = $"{employee.Personality.Name}"; } public void OnBuffsChanged(object sender, NotifyCollectionChangedEventArgs e) diff --git a/JamGame/Assets/Scripts/Employee/Personality/Config.meta b/JamGame/Assets/Scripts/Employee/Personality/Config.meta new file mode 100644 index 00000000..c339bc66 --- /dev/null +++ b/JamGame/Assets/Scripts/Employee/Personality/Config.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: de270d7dd6247494b85a4fa4354f9e69 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/JamGame/Assets/Scripts/Level/Config/EmployeeNameList.cs b/JamGame/Assets/Scripts/Employee/Personality/NameList.cs similarity index 76% rename from JamGame/Assets/Scripts/Level/Config/EmployeeNameList.cs rename to JamGame/Assets/Scripts/Employee/Personality/NameList.cs index 3ed32712..ae640394 100644 --- a/JamGame/Assets/Scripts/Level/Config/EmployeeNameList.cs +++ b/JamGame/Assets/Scripts/Employee/Personality/NameList.cs @@ -2,11 +2,11 @@ using System.Collections.Generic; using UnityEngine; -namespace Level.Config +namespace Employee.Personality { [Serializable] - [CreateAssetMenu(fileName = "EmployeeNameList", menuName = "Level/EmployeeNameList")] - public class EmployeeNameList : ScriptableObject + [CreateAssetMenu(fileName = "NameList", menuName = "Employee/NameList")] + public class NameList : ScriptableObject { [SerializeField] private List firstNames = new(); diff --git a/JamGame/Assets/Scripts/Level/Config/EmployeeNameList.cs.meta b/JamGame/Assets/Scripts/Employee/Personality/NameList.cs.meta similarity index 83% rename from JamGame/Assets/Scripts/Level/Config/EmployeeNameList.cs.meta rename to JamGame/Assets/Scripts/Employee/Personality/NameList.cs.meta index 5a778746..f10be259 100644 --- a/JamGame/Assets/Scripts/Level/Config/EmployeeNameList.cs.meta +++ b/JamGame/Assets/Scripts/Employee/Personality/NameList.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 57826b9781e118947a17eb4a12484c96 +guid: 17fdcae30752e9a4d92db845ff3d3ffb MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/JamGame/Assets/Scripts/Employee/Personality/PersonalityImpl.cs b/JamGame/Assets/Scripts/Employee/Personality/PersonalityImpl.cs index 7660e4f0..de38e629 100644 --- a/JamGame/Assets/Scripts/Employee/Personality/PersonalityImpl.cs +++ b/JamGame/Assets/Scripts/Employee/Personality/PersonalityImpl.cs @@ -1,46 +1,122 @@ +using System; using System.Collections.Generic; -using Common; -using Employee.Needs; -using Level.Boss.Task; +using Pickle; +using Sirenix.OdinInspector; using UnityEngine; namespace Employee.Personality { - [RequireComponent(typeof(EmployeeImpl))] - [AddComponentMenu("Scripts/Employee/Personality/Employee.Personality")] - public class PersonalityImpl : MonoBehaviour + public interface IConfig { + public PersonalityImpl GetPersonality(); + } + + public class PersonalityImpl + { + private string name; + private int hireCost; + private string profession; + private List quirks; + + public string Name => name; + public int HireCost => hireCost; + public string Profession => profession; + public List Quirks => quirks; + + public PersonalityImpl(string name, int hireCost, string profession, List quirks) + { + this.name = name; + this.hireCost = hireCost; + this.profession = profession; + this.quirks = quirks; + } + } + + [Serializable] + public class FixedConfig : IConfig + { + [SerializeField] + [FoldoutGroup("@" + nameof(Label))] + private string name; + + [SerializeField] + [FoldoutGroup("@" + nameof(Label))] + private int hireCost; + [SerializeField] - private string name_; - public string Name => name_; + [FoldoutGroup("@" + nameof(Label))] + private string profession; [SerializeField] + [FoldoutGroup("@" + nameof(Label))] private List quirks; - public IEnumerable Quirks => quirks; - private DataProvider employeeQuirksDataProvider; + private string Label => $"Employee - {name}"; - private void Start() + public PersonalityImpl GetPersonality() { - employeeQuirksDataProvider = new DataProvider( - () => new EmployeeQuirks() { Quirks = quirks }, - DataProviderServiceLocator.ResolveType.MultipleSources - ); + return new PersonalityImpl(name, hireCost, profession, quirks); + } + } - EmployeeImpl employee = GetComponent(); + [Serializable] + public class RandomConfig : IConfig + { + [Serializable] + private struct CostRange + { + public int Min; + public int Max; + public int Multiply; - foreach (Quirk quirk in quirks) + public int GenerateCost() { - foreach (Need.NeedProperties additional_need in quirk.AdditionalNeeds) - { - employee.AddNeed(additional_need); - } + return UnityEngine.Random.Range(Min, Max) * Multiply; + } + } - foreach (IEffect effect in quirk.Effects) + [Serializable] + private struct QuirkList + { + public float QuirkChance; + public List Quirks; + + public List GenerateQuirks() + { + List quirks = new(); + foreach (Quirk quirk in Quirks) { - employee.RegisterEffect(effect); + if (UnityEngine.Random.Range(0f, 1f) <= QuirkChance) + { + quirks.Add(quirk); + } } + return quirks; } } + + [SerializeField] + [Pickle(typeof(NameList), LookupType = ObjectProviderType.Assets)] + [FoldoutGroup("Employee - Random")] + private NameList nameList; + + [SerializeField] + [FoldoutGroup("Employee - Random")] + private CostRange costRange; + + [SerializeField] + [FoldoutGroup("Employee - Random")] + private QuirkList quirkList; + + public PersonalityImpl GetPersonality() + { + // TODO: #48 + return new PersonalityImpl( + nameList.GenerateName(), + costRange.GenerateCost(), + "Programmer", + quirkList.GenerateQuirks() + ); + } } } diff --git a/JamGame/Assets/Scripts/Employee/Personality/PersonalityImpl.cs.meta b/JamGame/Assets/Scripts/Employee/Personality/PersonalityImpl.cs.meta index 1495202d..9715829b 100644 --- a/JamGame/Assets/Scripts/Employee/Personality/PersonalityImpl.cs.meta +++ b/JamGame/Assets/Scripts/Employee/Personality/PersonalityImpl.cs.meta @@ -1,11 +1,11 @@ -fileFormatVersion: 2 -guid: 1c3a921a269683844adf1acfc030e74d -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: +fileFormatVersion: 2 +guid: 9d2e8304cd75c0b4790ea65e8b4a9892 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/JamGame/Assets/Scripts/Level/Config/DayAction.cs b/JamGame/Assets/Scripts/Level/Config/DayAction.cs index 329e4e65..f19cdc7e 100644 --- a/JamGame/Assets/Scripts/Level/Config/DayAction.cs +++ b/JamGame/Assets/Scripts/Level/Config/DayAction.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; using System.Linq; +using Employee.Personality; using Level.GlobalTime; using Sirenix.OdinInspector; using TileBuilder; using UnityEngine; +using IPersonalityConfig = Employee.Personality.IConfig; namespace Level.Config { @@ -82,9 +84,9 @@ public class Meeting : IDayAction { [SerializeReference] [FoldoutGroup("Employees to sell in shop")] - private List shopEmployees = new(); - public IEnumerable ShopEmployees => - shopEmployees.Select(x => x.GetEmployeeConfig()); + private List shopEmployees = new(); + public IEnumerable ShopEmployees => + shopEmployees.Select(x => x.GetPersonality()); private enum SourceMode { diff --git a/JamGame/Assets/Scripts/Level/Config/Employee.cs b/JamGame/Assets/Scripts/Level/Config/Employee.cs deleted file mode 100644 index d935d7c1..00000000 --- a/JamGame/Assets/Scripts/Level/Config/Employee.cs +++ /dev/null @@ -1,123 +0,0 @@ -using System; -using System.Collections.Generic; -using Employee.Personality; -using Pickle; -using Sirenix.OdinInspector; -using UnityEngine; - -namespace Level.Config -{ - public interface IEmployeeConfig - { - public EmployeeConfig GetEmployeeConfig(); - } - - public class EmployeeConfig - { - private string name; - private int hireCost; - private string profession; - private List quirks; - - public string Name => name; - public int HireCost => hireCost; - public string Profession => profession; - public List Quirks => quirks; - - public EmployeeConfig(string name, int hireCost, string profession, List quirks) - { - this.name = name; - this.hireCost = hireCost; - this.profession = profession; - this.quirks = quirks; - } - } - - [Serializable] - public class FixedEmployeeConfig : IEmployeeConfig - { - [SerializeField] - [FoldoutGroup("@" + nameof(Label))] - private string name; - - [SerializeField] - [FoldoutGroup("@" + nameof(Label))] - private int hireCost; - - [SerializeField] - [FoldoutGroup("@" + nameof(Label))] - private string profession; - - [SerializeField] - [FoldoutGroup("@" + nameof(Label))] - private List quirks; - - private string Label => $"Employee - {name}"; - - public EmployeeConfig GetEmployeeConfig() - { - return new EmployeeConfig(name, hireCost, profession, quirks); - } - } - - [Serializable] - public class RandomEmployeeConfig : IEmployeeConfig - { - [Serializable] - private struct CostRange - { - public int Min; - public int Max; - public int Multiply; - - public int GenerateCost() - { - return UnityEngine.Random.Range(Min, Max) * Multiply; - } - } - - [Serializable] - private struct QuirkList - { - public float QuirkChance; - public List Quirks; - - public List GenerateQuirks() - { - List quirks = new(); - foreach (Quirk quirk in Quirks) - { - if (UnityEngine.Random.Range(0f, 1f) <= QuirkChance) - { - quirks.Add(quirk); - } - } - return quirks; - } - } - - [SerializeField] - [Pickle(typeof(EmployeeNameList), LookupType = ObjectProviderType.Assets)] - [FoldoutGroup("Employee - Random")] - private EmployeeNameList nameList; - - [SerializeField] - [FoldoutGroup("Employee - Random")] - private CostRange costRange; - - [SerializeField] - [FoldoutGroup("Employee - Random")] - private QuirkList quirkList; - - public EmployeeConfig GetEmployeeConfig() - { - // TODO: #48 - return new EmployeeConfig( - nameList.GenerateName(), - costRange.GenerateCost(), - "Programmer", - quirkList.GenerateQuirks() - ); - } - } -} diff --git a/JamGame/Assets/Scripts/Level/Config/Employee.cs.meta b/JamGame/Assets/Scripts/Level/Config/Employee.cs.meta deleted file mode 100644 index 47d5bb57..00000000 --- a/JamGame/Assets/Scripts/Level/Config/Employee.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 084465deeff652243adc0269faf3e681 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/JamGame/Assets/Scripts/Level/Shop/Controller.cs b/JamGame/Assets/Scripts/Level/Shop/Controller.cs index 3b44f6d3..a30a94c9 100644 --- a/JamGame/Assets/Scripts/Level/Shop/Controller.cs +++ b/JamGame/Assets/Scripts/Level/Shop/Controller.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using Common; +using Employee.Personality; using Level.Config; using Level.Inventory.Controller; using Level.Room; @@ -56,12 +57,12 @@ public Result TryBuyRoom(InternalUid roomUid, int cost) return new SuccessResult(); } - public void SetShopEmployees(IEnumerable employeeConfigs) + public void SetShopEmployees(IEnumerable employeePersonalities) { - shopModel.ResetEmployees(employeeConfigs); + shopModel.ResetEmployees(employeePersonalities); } - public Result TryBuyEmployee(EmployeeConfig employee) + public Result TryBuyEmployee(PersonalityImpl employee) { Result result = financesController.TryTakeMoney(employee.HireCost); if (result.Success) diff --git a/JamGame/Assets/Scripts/Level/Shop/Employee/CardView.cs b/JamGame/Assets/Scripts/Level/Shop/Employee/CardView.cs index c2449309..6a40650b 100644 --- a/JamGame/Assets/Scripts/Level/Shop/Employee/CardView.cs +++ b/JamGame/Assets/Scripts/Level/Shop/Employee/CardView.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using Common; using Employee.Personality; -using Level.Config; using Sirenix.OdinInspector; using TMPro; using UnityEngine; @@ -58,8 +57,8 @@ public class CardView : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler [ReadOnly] [SerializeField] - private EmployeeConfig employeeConfig; - public EmployeeConfig EmployeeConfig => employeeConfig; + private PersonalityImpl employeeConfig; + public PersonalityImpl EmployeeConfig => employeeConfig; private Controller controller; private Dictionary quirksByUid; @@ -74,9 +73,9 @@ public void Initialize() quirksByUid = AddressableTools.LoadAllScriptableObjectAssets(quirkLabel); } - public void SetEmployeeConfig(EmployeeConfig employeeConfig) + public void SetEmployeePersonality(PersonalityImpl employeePersonality) { - this.employeeConfig = employeeConfig; + employeeConfig = employeePersonality; UpdateData(); } diff --git a/JamGame/Assets/Scripts/Level/Shop/Model.cs b/JamGame/Assets/Scripts/Level/Shop/Model.cs index f322f1b4..6d80564c 100644 --- a/JamGame/Assets/Scripts/Level/Shop/Model.cs +++ b/JamGame/Assets/Scripts/Level/Shop/Model.cs @@ -3,7 +3,7 @@ using System.Collections.Specialized; using System.Linq; using Common; -using Level.Config; +using Employee.Personality; using Level.Room; using UnityEngine; @@ -19,7 +19,7 @@ public event NotifyCollectionChangedEventHandler RoomsCollectionChanged remove => roomsInShop.CollectionChanged -= value; } - private ObservableCollection employeesInShop = new(); + private ObservableCollection employeesInShop = new(); public event NotifyCollectionChangedEventHandler EmployeeCollectionChanged { add => employeesInShop.CollectionChanged += value; @@ -63,16 +63,16 @@ public void ClearRooms() roomsInShop.Clear(); } - public void ResetEmployees(IEnumerable employees) + public void ResetEmployees(IEnumerable employees) { ClearEmployees(); - foreach (EmployeeConfig employee in employees) + foreach (PersonalityImpl employee in employees) { AddEmployee(employee); } } - public void AddEmployee(EmployeeConfig employee) + public void AddEmployee(PersonalityImpl employee) { employeesInShop.Add(employee); } diff --git a/JamGame/Assets/Scripts/Level/Shop/View/Employees.cs b/JamGame/Assets/Scripts/Level/Shop/View/Employees.cs index b1900552..c7ed7096 100644 --- a/JamGame/Assets/Scripts/Level/Shop/View/Employees.cs +++ b/JamGame/Assets/Scripts/Level/Shop/View/Employees.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; -using Level.Config; +using Employee.Personality; using Pickle; using Sirenix.OdinInspector; using UnityEngine; @@ -43,10 +43,10 @@ private void OnShopEmployeesChanged(object sender, NotifyCollectionChangedEventA switch (e.Action) { case NotifyCollectionChangedAction.Add: - AddNewEmployee(e.NewItems[0] as EmployeeConfig); + AddNewEmployee(e.NewItems[0] as PersonalityImpl); break; case NotifyCollectionChangedAction.Remove: - RemoveOldEmployee(e.OldItems[0] as EmployeeConfig); + RemoveOldEmployee(e.OldItems[0] as PersonalityImpl); break; case NotifyCollectionChangedAction.Reset: DeleteAllEmployees(); @@ -59,21 +59,21 @@ private void OnShopEmployeesChanged(object sender, NotifyCollectionChangedEventA } } - private void AddNewEmployee(EmployeeConfig newEmployee) + private void AddNewEmployee(PersonalityImpl newEmployee) { Employee.CardView newEmployeeCard = Instantiate( employeeCardPrefab, content.ContentTransform ); newEmployeeCard.Initialize(); - newEmployeeCard.SetEmployeeConfig(newEmployee); + newEmployeeCard.SetEmployeePersonality(newEmployee); employeeCards.Add(newEmployeeCard); newEmployeeCard.OnPointerEnterEvent += () => cardInstance.UpdateData(newEmployeeCard); newEmployeeCard.OnPointerExitEvent += () => cardInstance.UpdateData(null); } - private void RemoveOldEmployee(EmployeeConfig oldEmployee) + private void RemoveOldEmployee(PersonalityImpl oldEmployee) { Employee.CardView employeeCard = employeeCards.Find(x => x.EmployeeConfig == oldEmployee diff --git a/JamGame/Assets/Scripts/Location/EmployeeManager/Model.cs b/JamGame/Assets/Scripts/Location/EmployeeManager/Model.cs index d16ef7f8..d7b9700a 100644 --- a/JamGame/Assets/Scripts/Location/EmployeeManager/Model.cs +++ b/JamGame/Assets/Scripts/Location/EmployeeManager/Model.cs @@ -4,9 +4,9 @@ using Common; using Employee; using Employee.Needs; +using Employee.Personality; using Level; using Level.Boss.Task; -using Level.Config; using Sirenix.OdinInspector; using UnityEngine; using UnityEngine.Events; @@ -105,7 +105,7 @@ public IEnumerator TurnOnAllEmployees(float delay) } } - public Result AddEmployee(EmployeeConfig config) + public Result AddEmployee(PersonalityImpl personality) { Result result = tileBuilderController.GrowMeetingRoomForEmployees(employees.Count + 1); @@ -118,7 +118,7 @@ public Result AddEmployee(EmployeeConfig config) .GetComponent(); employee.gameObject.SetActive(true); - employee.SetConfig(config); + employee.SetPersonality(personality); employee.NeedProviderManager = needProviderManager; employee.IncomeGenerator.Finances = finances;