chore(服务端): 初始化工程仓库
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"perler-beads-server/internal/domain"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func demoColors() []domain.Color {
|
||||
defs := [][3]string{{"DEMO-R", "演示红", "#E85555"}, {"DEMO-Y", "演示黄", "#FFD166"}, {"DEMO-B", "演示蓝", "#4A90D9"}, {"DEMO-G", "演示绿", "#4DAA7A"}, {"DEMO-W", "演示白", "#FFFFFF"}, {"DEMO-K", "演示黑", "#25282D"}, {"DEMO-O", "演示橙", "#F59F45"}, {"DEMO-P", "演示紫", "#9370DB"}, {"DEMO-C", "演示青", "#63C8CE"}, {"DEMO-S", "演示粉", "#F2A7BC"}}
|
||||
out := []domain.Color{}
|
||||
for i, d := range defs {
|
||||
out = append(out, domain.Color{Code: d[0], Name: d[1], Hex: d[2], Location: fmt.Sprintf("A%d", i+1), Available: true})
|
||||
}
|
||||
return out
|
||||
}
|
||||
func demoPatterns(store string, colors []domain.Color) []domain.Pattern {
|
||||
defs := []struct{ title, rows string }{{"原创像素心(演示)", ".RR.RR./RRRRRRR/RRRRRRR/.RRRRR./..RRR../...R.../......."}, {"原创像素菱形(演示)", "...Y.../..YYY../.YYOYY./YYOOOYY/.YYOYY./..YYY../...Y..."}, {"原创像素小花(演示)", "..SSS../.SSYSS./..SSS../...G.../...G.../..GGG../...G..."}, {"原创像素星(演示)", "...B.../...B.../BBBBBBB/.BCCCB./..BBB../.BB.BB./B.....B"}}
|
||||
lookup := map[rune]string{}
|
||||
for _, c := range colors {
|
||||
lookup[[]rune(c.Code)[len(c.Code)-1]] = c.Code
|
||||
}
|
||||
out := []domain.Pattern{}
|
||||
for k, d := range defs {
|
||||
cells := []*string{}
|
||||
for _, row := range strings.Split(d.rows, "/") {
|
||||
for _, v := range row {
|
||||
if v == '.' {
|
||||
cells = append(cells, nil)
|
||||
} else {
|
||||
code := lookup[v]
|
||||
cells = append(cells, &code)
|
||||
}
|
||||
}
|
||||
}
|
||||
p := domain.Pattern{ID: fmt.Sprintf("demo-%d", k+1), Title: d.title, Category: "原创演示", Width: 7, Height: 7, Cells: cells, Colors: colors, Visibility: "public", StoreID: store, CreatedAt: "2026-10-03T00:00:00Z", Demo: true}
|
||||
if e := p.Validate(); e != nil {
|
||||
panic(e)
|
||||
}
|
||||
out = append(out, p)
|
||||
}
|
||||
return out
|
||||
}
|
||||
Reference in New Issue
Block a user