generated from VLADIMIR/template
add doors
This commit is contained in:
@@ -47,11 +47,7 @@ func (s *StoryService) Update(ctx context.Context) error {
|
||||
|
||||
func (s *StoryService) GetPlace(code string) *Place {
|
||||
if strings.HasPrefix(code, "[") || strings.HasSuffix(code, "]") {
|
||||
return &Place{
|
||||
Code: code,
|
||||
Name: "Не найдено",
|
||||
Text: "Уважаемые детективы внимательно прочитайте правила.",
|
||||
}
|
||||
return NewClientErrorPlace(code)
|
||||
}
|
||||
clearCode := s.cleaner.ClearCode(code)
|
||||
for _, place := range s.story.Places {
|
||||
@@ -66,21 +62,34 @@ func (s *StoryService) GetPlace(code string) *Place {
|
||||
},
|
||||
)
|
||||
}
|
||||
return &Place{
|
||||
Code: place.Code,
|
||||
Name: place.Name,
|
||||
Text: s.cleaner.ClearText(place.Text),
|
||||
Applications: applications,
|
||||
Hidden: place.Hidden,
|
||||
Doors: place.Doors,
|
||||
}
|
||||
return NewPlace(
|
||||
place.Code,
|
||||
place.Name,
|
||||
s.cleaner.ClearText(place.Text),
|
||||
WithPlaceApplication(applications...),
|
||||
WithPlaceHidden(place.Hidden),
|
||||
WithPlaceDoors(place.Doors...),
|
||||
)
|
||||
}
|
||||
}
|
||||
return &Place{
|
||||
Code: code,
|
||||
Name: "Не найдено",
|
||||
Text: "Такой точки не существует.",
|
||||
return NewNotFoundPlace(code)
|
||||
}
|
||||
|
||||
func (s *StoryService) GetPlaces(codes []string) []*Place {
|
||||
places := make([]*Place, 0, 100)
|
||||
m := map[string]any{}
|
||||
for _, code := range codes {
|
||||
place := s.GetPlace(code)
|
||||
_, ok := m[place.Code]
|
||||
if place.Hidden && !ok {
|
||||
place = NewNotFoundPlace(place.Code)
|
||||
}
|
||||
places = append(places, place)
|
||||
for _, door := range place.Doors {
|
||||
m[door.Code] = struct{}{}
|
||||
}
|
||||
}
|
||||
return places
|
||||
}
|
||||
|
||||
func (s *StoryService) UpdatePlace(ctx context.Context, code string, node *GraphNode) error {
|
||||
@@ -109,12 +118,12 @@ func (s *StoryService) deletePlace(ctx context.Context, code string) error {
|
||||
func (s *StoryService) addPlace(ctx context.Context, node *GraphNode) error {
|
||||
s.story.Places = append(
|
||||
s.story.Places,
|
||||
&Place{
|
||||
Code: node.Code,
|
||||
Name: node.Name,
|
||||
Text: s.formatter.FormatText(node.Text),
|
||||
Applications: s.getApplications(node),
|
||||
},
|
||||
NewPlace(
|
||||
node.Code,
|
||||
node.Name,
|
||||
s.formatter.FormatText(node.Text),
|
||||
WithPlaceApplication(s.getApplications(node)...),
|
||||
),
|
||||
)
|
||||
return s.Update(ctx)
|
||||
}
|
||||
@@ -122,23 +131,23 @@ func (s *StoryService) addPlace(ctx context.Context, node *GraphNode) error {
|
||||
func (s *StoryService) updatePlace(ctx context.Context, code string, node *GraphNode) error {
|
||||
for i := range s.story.Places {
|
||||
if s.story.Places[i].Code == code {
|
||||
s.story.Places[i] = &Place{
|
||||
Code: node.Code,
|
||||
Name: node.Name,
|
||||
Text: s.formatter.FormatText(node.Text),
|
||||
Applications: s.getApplications(node),
|
||||
}
|
||||
s.story.Places[i] = NewPlace(
|
||||
node.Code,
|
||||
node.Name,
|
||||
s.formatter.FormatText(node.Text),
|
||||
WithPlaceApplication(s.getApplications(node)...),
|
||||
)
|
||||
return s.Update(ctx)
|
||||
}
|
||||
}
|
||||
for i := range s.story.Places {
|
||||
if s.story.Places[i].Code == node.Code {
|
||||
s.story.Places[i] = &Place{
|
||||
Code: code,
|
||||
Name: node.Name,
|
||||
Text: s.formatter.FormatText(node.Text),
|
||||
Applications: s.getApplications(node),
|
||||
}
|
||||
s.story.Places[i] = NewPlace(
|
||||
code,
|
||||
node.Name,
|
||||
s.formatter.FormatText(node.Text),
|
||||
WithPlaceApplication(s.getApplications(node)...),
|
||||
)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user