Skip to content

Commit 3201868

Browse files
authored
Fix bug for schedule display (#2539)
1 parent 29d7f57 commit 3201868

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/JoinRpg.Domain/CharacterFields/CustomFieldsExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ private static IReadOnlyCollection<FieldWithValue> GetFieldsForContainers(Projec
5858
public static IReadOnlyCollection<FieldWithValue> GetFields(this Character character, ProjectInfo projectInfo)
5959
=> GetFieldsForContainers(projectInfo, character.ApprovedClaim?.DeserializeFieldValues(), character.DeserializeFieldValues());
6060

61+
public static Dictionary<ProjectFieldIdentification, FieldWithValue> GetFieldsDict(this Character character, ProjectInfo projectInfo)
62+
=> character.GetFields(projectInfo).ToDictionary(f => f.Field.Id);
63+
6164
public static IReadOnlyCollection<FieldWithValue> GetFields(this CharacterView character, ProjectInfo projectInfo)
6265
=> GetFieldsForContainers(projectInfo, character.ApprovedClaim?.DeserializeFieldValues(), character.DeserializeFieldValues());
6366

@@ -72,6 +75,9 @@ public static IReadOnlyCollection<FieldWithValue> GetFields(this Claim claim, Pr
7275
claim.DeserializeFieldValues());
7376
}
7477

78+
public static Dictionary<ProjectFieldIdentification, FieldWithValue> GetFieldsDict(this Claim claim, ProjectInfo projectInfo)
79+
=> claim.GetFields(projectInfo).ToDictionary(f => f.Field.Id);
80+
7581
public static FieldWithValue? GetSingleField(this Claim claim, ProjectInfo projectInfo, ProjectFieldIdentification id)
7682
{
7783
return claim.GetFields(projectInfo).SingleOrDefault(f => f.Field.Id == id);

src/JoinRpg.Domain/Schedules/ScheduleBuilder.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using JoinRpg.DataModel;
2+
using JoinRpg.PrimitiveTypes;
23
using JoinRpg.PrimitiveTypes.ProjectMetadata;
34

45
namespace JoinRpg.Domain.Schedules;
@@ -102,24 +103,23 @@ private void PutItem(ProgramItem programItem, List<ProgramItemSlot> slots)
102103

103104
private List<ProgramItemSlot> SelectSlots(ProgramItem programItem, Character character)
104105
{
105-
var fields = character.GetFields(projectInfo);
106+
var fields = character.GetFieldsDict(projectInfo);
106107

107-
List<int> GetSlotIndexes(ProjectFieldInfo field, IEnumerable<ScheduleItemAttribute> items)
108+
int[] GetSlotIndexes(FieldWithValue field, IEnumerable<ScheduleItemAttribute> items)
108109
{
109-
var variantIds = field.SortedVariants
110-
.Select(variant => variant.Id)
111-
.ToList();
112-
var indexes = (from item in items where variantIds.Contains(item.Id) select item.SeqId).ToList();
113-
if (indexes.Count < variantIds.Count) // Some variants not found, probably deleted
110+
ProjectFieldVariantIdentification[] variantIds = [.. field.GetDropdownValues().Select(variant => variant.Id)];
111+
112+
int[] indexes = [.. (from item in items where variantIds.Contains(item.Id) select item.SeqId)];
113+
if (indexes.Length < variantIds.Length) // Some variants not found, probably deleted
114114
{
115115
_ = NotScheduled.Add(programItem);
116116
}
117117

118118
return indexes;
119119
}
120120

121-
var slots = from timeSeqId in GetSlotIndexes(TimeSlotField, TimeSlots)
122-
from roomSeqId in GetSlotIndexes(RoomField, Rooms)
121+
var slots = from timeSeqId in GetSlotIndexes(fields[TimeSlotField.Id], TimeSlots)
122+
from roomSeqId in GetSlotIndexes(fields[RoomField.Id], Rooms)
123123
select Slots[timeSeqId][roomSeqId];
124124

125125
return slots.ToList();

0 commit comments

Comments
 (0)