Reformat to use a words file rather than babble
This commit is contained in:
parent
5f732bd6c5
commit
58f9d8baf2
3 changed files with 43 additions and 10 deletions
|
@ -40,6 +40,7 @@ services:
|
||||||
- PORT=9090
|
- PORT=9090
|
||||||
- DATA_PATH=/mnt/rove-server
|
- DATA_PATH=/mnt/rove-server
|
||||||
- ROVE_ACCOUNTANT_GRPC=rove-accountant:9091
|
- ROVE_ACCOUNTANT_GRPC=rove-accountant:9091
|
||||||
|
- WORDS_FILE=data/words_alpha.txt
|
||||||
volumes:
|
volumes:
|
||||||
- persistent-data:/mnt/rove-server:rw
|
- persistent-data:/mnt/rove-server:rw
|
||||||
command: [ "./script/wait-for-it.sh", "rove-accountant:9091", "--", "./rove-server"]
|
command: [ "./script/wait-for-it.sh", "rove-accountant:9091", "--", "./rove-server"]
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
package game
|
package game
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strings"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
@ -13,7 +14,6 @@ import (
|
||||||
"github.com/mdiluz/rove/pkg/bearing"
|
"github.com/mdiluz/rove/pkg/bearing"
|
||||||
"github.com/mdiluz/rove/pkg/maths"
|
"github.com/mdiluz/rove/pkg/maths"
|
||||||
"github.com/mdiluz/rove/pkg/vector"
|
"github.com/mdiluz/rove/pkg/vector"
|
||||||
"github.com/tjarratt/babble"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// World describes a self contained universe and everything in it
|
// World describes a self contained universe and everything in it
|
||||||
|
@ -35,15 +35,37 @@ type World struct {
|
||||||
|
|
||||||
// Mutex to lock around command operations
|
// Mutex to lock around command operations
|
||||||
cmdMutex sync.RWMutex
|
cmdMutex sync.RWMutex
|
||||||
|
|
||||||
|
// Set of possible words to use for names
|
||||||
|
words []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var wordsFile = os.Getenv("WORDS_FILE")
|
||||||
|
|
||||||
// NewWorld creates a new world object
|
// NewWorld creates a new world object
|
||||||
func NewWorld(size, chunkSize int) *World {
|
func NewWorld(size, chunkSize int) *World {
|
||||||
|
|
||||||
|
// Try and load the words file
|
||||||
|
var lines []string
|
||||||
|
if file, err := os.Open(wordsFile); err != nil {
|
||||||
|
log.Printf("Couldn't read words file [%s], running without words: %s\n", wordsFile, err)
|
||||||
|
} else {
|
||||||
|
defer file.Close()
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
for scanner.Scan() {
|
||||||
|
lines = append(lines, scanner.Text())
|
||||||
|
}
|
||||||
|
if scanner.Err() != nil {
|
||||||
|
log.Printf("Failure during word file scan: %s\n", scanner.Err())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return &World{
|
return &World{
|
||||||
Rovers: make(map[uuid.UUID]Rover),
|
Rovers: make(map[uuid.UUID]Rover),
|
||||||
CommandQueue: make(map[uuid.UUID]CommandStream),
|
CommandQueue: make(map[uuid.UUID]CommandStream),
|
||||||
Incoming: make(map[uuid.UUID]CommandStream),
|
Incoming: make(map[uuid.UUID]CommandStream),
|
||||||
Atlas: atlas.NewAtlas(size, chunkSize),
|
Atlas: atlas.NewAtlas(size, chunkSize),
|
||||||
|
words: lines,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,15 +88,17 @@ func (w *World) SpawnRover() (uuid.UUID, error) {
|
||||||
rover := Rover{
|
rover := Rover{
|
||||||
Id: uuid.New(),
|
Id: uuid.New(),
|
||||||
Attributes: RoverAttributes{
|
Attributes: RoverAttributes{
|
||||||
|
|
||||||
Speed: 1.0,
|
Speed: 1.0,
|
||||||
Range: 5.0,
|
Range: 5.0,
|
||||||
|
Name: "rover",
|
||||||
// Set the name randomly
|
|
||||||
Name: strings.ReplaceAll(babble.NewBabbler().Babble(), "'s", ""),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Assign a random name if we have words
|
||||||
|
if len(w.words) > 0 {
|
||||||
|
rover.Attributes.Name = fmt.Sprintf("%s-%s", w.words[rand.Intn(len(w.words))], w.words[rand.Intn(len(w.words))])
|
||||||
|
}
|
||||||
|
|
||||||
// Spawn in a random place near the origin
|
// Spawn in a random place near the origin
|
||||||
rover.Attributes.Pos = vector.Vector{
|
rover.Attributes.Pos = vector.Vector{
|
||||||
X: w.Atlas.ChunkSize/2 - rand.Intn(w.Atlas.ChunkSize),
|
X: w.Atlas.ChunkSize/2 - rand.Intn(w.Atlas.ChunkSize),
|
||||||
|
|
|
@ -21,6 +21,8 @@ apps:
|
||||||
plugs:
|
plugs:
|
||||||
- network
|
- network
|
||||||
- network-bind
|
- network-bind
|
||||||
|
environment:
|
||||||
|
WORDS_FILE : "$SNAP/data/words_alpha.txt"
|
||||||
rove-accountant:
|
rove-accountant:
|
||||||
command: bin/rove-accountant
|
command: bin/rove-accountant
|
||||||
plugs:
|
plugs:
|
||||||
|
@ -41,8 +43,14 @@ parts:
|
||||||
- gcc-multilib
|
- gcc-multilib
|
||||||
override-pull: |
|
override-pull: |
|
||||||
snapcraftctl pull
|
snapcraftctl pull
|
||||||
snapcraftctl set-version $(git describe --always --long --dirty --tags)
|
version=$(git describe --always --long --dirty --tags)
|
||||||
|
sed -i "s/undefined/$version/" pkg/version/version.go
|
||||||
|
snapcraftctl set-version $version
|
||||||
git describe --exact-match --tags HEAD 2> /dev/null && snapcraftctl set-grade "stable" || snapcraftctl set-grade "devel"
|
git describe --exact-match --tags HEAD 2> /dev/null && snapcraftctl set-grade "stable" || snapcraftctl set-grade "devel"
|
||||||
sed -i "s/undefined/$(git describe --always --long --dirty --tags)/" pkg/version/version.go
|
|
||||||
|
copy-data:
|
||||||
# TODO: Server needs /usr/share/dict/words
|
plugin: dump
|
||||||
|
source-type: local
|
||||||
|
source: data
|
||||||
|
organize:
|
||||||
|
'*.txt' : data/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue