Add playable hub travel with durable character transfers
This commit is contained in:
@@ -107,6 +107,12 @@ func scalar(v string) *yaml.Node { return &yaml.Node{Kind: yaml.ScalarNode, Tag:
|
||||
// Only the worlds sequence is changed; image pins, comments and runtime settings
|
||||
// stay intact. Gitea's content SHA rejects concurrent image-promotion overwrites.
|
||||
func (c *Client) CreateWorld(ctx context.Context, id, seed string) (string, error) {
|
||||
return c.CreateInstance(ctx, id, seed, "survival")
|
||||
}
|
||||
func (c *Client) CreateInstance(ctx context.Context, id, seed, kind string) (string, error) {
|
||||
if kind != "hub" && kind != "survival" {
|
||||
return "", errors.New("invalid world kind")
|
||||
}
|
||||
if !identifier.MatchString(id) || !seedPattern.MatchString(seed) {
|
||||
return "", errors.New("invalid world ID or seed")
|
||||
}
|
||||
@@ -147,16 +153,20 @@ func (c *Client) CreateWorld(ctx context.Context, id, seed string) (string, erro
|
||||
key := mapping(world, "id")
|
||||
if key != nil && key.Value == id {
|
||||
existing := mapping(world, "seed")
|
||||
if existing != nil && existing.Value == seed {
|
||||
existingKind := "survival"
|
||||
if k := mapping(world, "kind"); k != nil {
|
||||
existingKind = k.Value
|
||||
}
|
||||
if existing != nil && existing.Value == seed && existingKind == kind {
|
||||
return "World definition already committed; waiting for ArgoCD readiness.", nil
|
||||
}
|
||||
return "", errors.New("world ID already exists with a different seed")
|
||||
return "", errors.New("world ID already exists with a different seed or kind")
|
||||
}
|
||||
}
|
||||
if len(worlds.Content) >= 50 {
|
||||
return "", errors.New("operator world limit reached (50)")
|
||||
}
|
||||
worlds.Content = append(worlds.Content, &yaml.Node{Kind: yaml.MappingNode, Tag: "!!map", Content: []*yaml.Node{scalar("id"), scalar(id), scalar("seed"), scalar(seed), scalar("host"), scalar(public.Host)}})
|
||||
worlds.Content = append(worlds.Content, &yaml.Node{Kind: yaml.MappingNode, Tag: "!!map", Content: []*yaml.Node{scalar("id"), scalar(id), scalar("seed"), scalar(seed), scalar("host"), scalar(public.Host), scalar("kind"), scalar(kind)}})
|
||||
encoded, err := yaml.Marshal(&doc)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
@@ -74,6 +74,15 @@ func TestCreateWorldPreservesValuesAndRetries(t *testing.T) {
|
||||
if _, err = c.CreateWorld(context.Background(), "../bad", "42"); err == nil {
|
||||
t.Fatal("invalid ID accepted")
|
||||
}
|
||||
if _, err = c.CreateInstance(context.Background(), "hub-001", "50", "hub"); err != nil || !strings.Contains(current, "kind: hub") {
|
||||
t.Fatal("hub definition missing", err, current)
|
||||
}
|
||||
if _, err = c.CreateInstance(context.Background(), "hub-001", "50", "hub"); err != nil || puts != 3 {
|
||||
t.Fatal("hub retry duplicated instance", err)
|
||||
}
|
||||
if _, err = c.CreateWorld(context.Background(), "hub-001", "50"); err == nil {
|
||||
t.Fatal("existing hub changed to survival world")
|
||||
}
|
||||
}
|
||||
func TestGitOpsConfigurationValidation(t *testing.T) {
|
||||
for _, repository := range []string{"http://example.test/o/r", "https://token@example.test/o/r", "https://example.test/only-one", "https://example.test/../repo"} {
|
||||
|
||||
Reference in New Issue
Block a user