checklist 로직 분리

This commit is contained in:
NTG 2025-08-21 19:26:14 +09:00
parent 5642a5fe77
commit b0ffb9df08
6 changed files with 59 additions and 35 deletions

View File

@ -225,6 +225,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: e765c62d234d09447bff001041f3dea6, type: 3} m_Script: {fileID: 11500000, guid: e765c62d234d09447bff001041f3dea6, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
_parent: {fileID: 4147204719077067979}
--- !u!1 &4608547885265804944 --- !u!1 &4608547885265804944
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -6340,7 +6341,6 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
<UiType>k__BackingField: 3 <UiType>k__BackingField: 3
_enableBlockImage: 0 _enableBlockImage: 0
InputActionMaps: 3
_uiActionsInputBinding: {fileID: 11400000, guid: 8073fcaf56fc7c34e996d0d47044f146, type: 2} _uiActionsInputBinding: {fileID: 11400000, guid: 8073fcaf56fc7c34e996d0d47044f146, type: 2}
_checklistView: {fileID: 7075966153492927588} _checklistView: {fileID: 7075966153492927588}
_inventoryView: {fileID: 3570087040626823091} _inventoryView: {fileID: 3570087040626823091}
@ -6363,7 +6363,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 80dee5e1862248aab26236036049e5fc, type: 3} m_Script: {fileID: 11500000, guid: 80dee5e1862248aab26236036049e5fc, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
_holdCompleteTime: 0
--- !u!1001 &4530765275021007961 --- !u!1001 &4530765275021007961
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -16,29 +16,22 @@ public enum ChecklistLocalizationKey
public class ChecklistView : MonoBehaviour, IEventHandler<TodayMenuAddedEvent>, IEventHandler<TodayMenuRemovedEvent> public class ChecklistView : MonoBehaviour, IEventHandler<TodayMenuAddedEvent>, IEventHandler<TodayMenuRemovedEvent>
{ {
private List<ChecklistData> _checklistDatas; [SerializeField] private Transform _parent;
private Dictionary<ChecklistLocalizationKey, string> _checklistLocalizationKeys = new() private RestaurantManagementViewModel _viewModel;
private void OnDestroy()
{ {
{ChecklistLocalizationKey.Checklist1, "checklist_1"}, EventBus.Unregister<TodayMenuAddedEvent>(this);
{ChecklistLocalizationKey.Checklist2, "checklist_2"}, EventBus.Unregister<TodayMenuRemovedEvent>(this);
{ChecklistLocalizationKey.Checklist3, "checklist_3"},
};
private RestaurantManagementState restaurantManagementStateSo;
public void Initalize()
{
restaurantManagementStateSo = RestaurantState.Instance.ManagementState;
_checklistDatas = new List<ChecklistData>(3);
_checklistDatas = GetComponentsInChildren<ChecklistData>().ToList();
foreach (var checklistData in _checklistDatas)
{
checklistData.Initialize();
} }
public void Initialize(RestaurantManagementViewModel viewModel)
{
_viewModel = viewModel;
ClearObject(_parent);
_viewModel.CreateChecklist(_parent);
UpdateView(); UpdateView();
EventBus.Register<TodayMenuAddedEvent>(this); EventBus.Register<TodayMenuAddedEvent>(this);
@ -47,23 +40,18 @@ public void Initalize()
public void UpdateView() public void UpdateView()
{ {
if (restaurantManagementStateSo == null) return; _viewModel.UpdateChecklistView();
bool[] states = restaurantManagementStateSo.GetChecklistStates();
int loopCount = Mathf.Min(_checklistDatas.Count, states.Length);
for (int i = 0; i < loopCount; i++)
{
_checklistDatas[i].UpdateData(_checklistLocalizationKeys[(ChecklistLocalizationKey)i], states[i]);
}
} }
public void Invoke(TodayMenuRemovedEvent evt) => UpdateView(); public void Invoke(TodayMenuRemovedEvent evt) => UpdateView();
public void Invoke(TodayMenuAddedEvent evt) => UpdateView(); public void Invoke(TodayMenuAddedEvent evt) => UpdateView();
private void OnDestroy() private void ClearObject(Transform parent)
{ {
EventBus.Unregister<TodayMenuAddedEvent>(this); foreach (Transform child in _parent)
EventBus.Unregister<TodayMenuRemovedEvent>(this); {
Destroy(child.gameObject);
}
} }
} }
} }

View File

@ -111,7 +111,7 @@ private void SetupViewModelEvents()
private void InitializeViews() private void InitializeViews()
{ {
_checklistView.Initalize(); _checklistView.Initialize(_viewModel);
_inventoryView.Initialize(_viewModel); _inventoryView.Initialize(_viewModel);
_itemDetailView.Initialize(); _itemDetailView.Initialize();
_todayMenuView.Initialize(_viewModel); _todayMenuView.Initialize(_viewModel);

View File

@ -180,6 +180,41 @@ public void MoveTab(int direction)
#endregion #endregion
#region ChecklistView
private List<ChecklistData> _checklistDatas;
private Dictionary<ChecklistLocalizationKey, string> _checklistLocalizationKeys = new()
{
{ChecklistLocalizationKey.Checklist1, "checklist_1"},
{ChecklistLocalizationKey.Checklist2, "checklist_2"},
{ChecklistLocalizationKey.Checklist3, "checklist_3"},
};
public void CreateChecklist(Transform parent)
{
var checklistCount = GetRestaurantManagementData().ChecklistCount;
_checklistDatas = new List<ChecklistData>(checklistCount);
for (int i = 0; i < checklistCount; i++)
{
var instance = Instantiate(GetRestaurantManagementData().ChecklistDataPrefab, parent);
instance.Initialize();
_checklistDatas.Add(instance);
}
}
public void UpdateChecklistView()
{
bool[] states = GetRestaurantManagementState().GetChecklistStates();
int loopCount = Mathf.Min(_checklistDatas.Count, states.Length);
for (int i = 0; i < loopCount; i++)
{
_checklistDatas[i].UpdateData(_checklistLocalizationKeys[(ChecklistLocalizationKey)i], states[i]);
}
}
#endregion
#region InventoryView #region InventoryView
private InventoryCategoryType _currenInventoryCategoryType = InventoryCategoryType.Food; private InventoryCategoryType _currenInventoryCategoryType = InventoryCategoryType.Food;

View File

@ -14,6 +14,7 @@ public class RestaurantManagementData : ScriptableObject
public int MaxCookwareCount = 6; public int MaxCookwareCount = 6;
[Title("체크리스트 조건")] [Title("체크리스트 조건")]
public int ChecklistCount = 3;
public int ChecklistFoodCount = 1; public int ChecklistFoodCount = 1;
public int ChecklistCookwareCount = 1; public int ChecklistCookwareCount = 1;
public int ChecklistMatchedMenuWithCookwareCount = 1; public int ChecklistMatchedMenuWithCookwareCount = 1;
@ -21,6 +22,7 @@ public class RestaurantManagementData : ScriptableObject
[Title("컴포넌트")] [Title("컴포넌트")]
public ItemSlotUi ItemSlotUiPrefab; public ItemSlotUi ItemSlotUiPrefab;
public TasteHashTagSlotUi TasteHashTagSlotUiPrefab; public TasteHashTagSlotUi TasteHashTagSlotUiPrefab;
public ChecklistData ChecklistDataPrefab;
public Material FoodTasteMaterial; public Material FoodTasteMaterial;
public Material DrinkTasteMaterial; public Material DrinkTasteMaterial;