Skip to content

Commit

Permalink
Fix bug for schedule display (#2539)
Browse files Browse the repository at this point in the history
  • Loading branch information
leotsarev authored Feb 20, 2024
1 parent 29d7f57 commit 3201868
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/JoinRpg.Domain/CharacterFields/CustomFieldsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ private static IReadOnlyCollection<FieldWithValue> GetFieldsForContainers(Projec
public static IReadOnlyCollection<FieldWithValue> GetFields(this Character character, ProjectInfo projectInfo)
=> GetFieldsForContainers(projectInfo, character.ApprovedClaim?.DeserializeFieldValues(), character.DeserializeFieldValues());

public static Dictionary<ProjectFieldIdentification, FieldWithValue> GetFieldsDict(this Character character, ProjectInfo projectInfo)
=> character.GetFields(projectInfo).ToDictionary(f => f.Field.Id);

public static IReadOnlyCollection<FieldWithValue> GetFields(this CharacterView character, ProjectInfo projectInfo)
=> GetFieldsForContainers(projectInfo, character.ApprovedClaim?.DeserializeFieldValues(), character.DeserializeFieldValues());

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

public static Dictionary<ProjectFieldIdentification, FieldWithValue> GetFieldsDict(this Claim claim, ProjectInfo projectInfo)
=> claim.GetFields(projectInfo).ToDictionary(f => f.Field.Id);

public static FieldWithValue? GetSingleField(this Claim claim, ProjectInfo projectInfo, ProjectFieldIdentification id)
{
return claim.GetFields(projectInfo).SingleOrDefault(f => f.Field.Id == id);
Expand Down
18 changes: 9 additions & 9 deletions src/JoinRpg.Domain/Schedules/ScheduleBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using JoinRpg.DataModel;
using JoinRpg.PrimitiveTypes;
using JoinRpg.PrimitiveTypes.ProjectMetadata;

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

private List<ProgramItemSlot> SelectSlots(ProgramItem programItem, Character character)
{
var fields = character.GetFields(projectInfo);
var fields = character.GetFieldsDict(projectInfo);

List<int> GetSlotIndexes(ProjectFieldInfo field, IEnumerable<ScheduleItemAttribute> items)
int[] GetSlotIndexes(FieldWithValue field, IEnumerable<ScheduleItemAttribute> items)
{
var variantIds = field.SortedVariants
.Select(variant => variant.Id)
.ToList();
var indexes = (from item in items where variantIds.Contains(item.Id) select item.SeqId).ToList();
if (indexes.Count < variantIds.Count) // Some variants not found, probably deleted
ProjectFieldVariantIdentification[] variantIds = [.. field.GetDropdownValues().Select(variant => variant.Id)];

int[] indexes = [.. (from item in items where variantIds.Contains(item.Id) select item.SeqId)];
if (indexes.Length < variantIds.Length) // Some variants not found, probably deleted
{
_ = NotScheduled.Add(programItem);
}

return indexes;
}

var slots = from timeSeqId in GetSlotIndexes(TimeSlotField, TimeSlots)
from roomSeqId in GetSlotIndexes(RoomField, Rooms)
var slots = from timeSeqId in GetSlotIndexes(fields[TimeSlotField.Id], TimeSlots)
from roomSeqId in GetSlotIndexes(fields[RoomField.Id], Rooms)
select Slots[timeSeqId][roomSeqId];

return slots.ToList();
Expand Down

0 comments on commit 3201868

Please sign in to comment.