add given applications

This commit is contained in:
2026-07-10 01:45:31 +07:00
parent 99f0e50f9a
commit c15106dc2d
2 changed files with 54 additions and 4 deletions
+15 -4
View File
@@ -14,6 +14,7 @@ func (s *story) GetStory(
keys := map[string]struct{}{}
codesWithUseActions := map[string]struct{}{}
codesHidden := map[string]struct{}{}
givenApplications := map[string]struct{}{}
for i, code := range codes {
var prevPlace *Place
if i > 0 {
@@ -54,10 +55,11 @@ func (s *story) GetStory(
story.Places = append(story.Places, s.buildNotFoundPlace(code))
continue
}
story.Places = append(
story.Places,
s.mapPlace(place, nextPlace, codesWithUseActions, keys),
)
newPlace := s.mapPlace(place, nextPlace, codesWithUseActions, keys, givenApplications)
story.Places = append(story.Places, newPlace)
for _, application := range newPlace.Applications {
givenApplications[application.Name] = struct{}{}
}
}
return story
}
@@ -116,11 +118,15 @@ func (s *story) mapPlace(
nextPlace *Place,
codesWithUseActions map[string]struct{},
keys map[string]struct{},
givenApplications map[string]struct{},
) *Place {
var applications []*Application
if len(place.Applications) > 0 {
applications = make([]*Application, 0, len(place.Applications))
for _, application := range place.Applications {
if _, ok := givenApplications[application.Name]; ok {
continue
}
applications = append(
applications,
&Application{
@@ -130,6 +136,10 @@ func (s *story) mapPlace(
)
}
}
if len(applications) == 0 {
applications = nil
}
var doors []*Door
_, useAction := codesWithUseActions[place.Code]
if len(place.Doors) > 0 && !useAction {
@@ -161,6 +171,7 @@ func (s *story) mapPlace(
if len(doors) == 0 {
doors = nil
}
return &Place{
Code: place.Code,
Name: place.Name,
@@ -162,6 +162,45 @@ func Test_story_GetStory(t *testing.T) {
},
},
},
{
name: "Улики не повторяются",
scenario: &Story{
Places: []*Place{
{
Code: "Ы",
Name: "Название точки",
Text: "Текст точки.",
Applications: []*Application{
{
Name: "Название улики",
Image: "image.png",
},
},
},
},
},
codes: []string{"Ы", "Ы"},
want: &Story{
Places: []*Place{
{
Code: "Ы",
Name: "Название точки",
Text: "Текст точки.",
Applications: []*Application{
{
Name: "Название улики",
Image: "image.png",
},
},
},
{
Code: "Ы",
Name: "Название точки",
Text: "Текст точки.",
},
},
},
},
{
name: "Получение точки с действием",
scenario: &Story{