nook

package module
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2021 License: MIT Imports: 3 Imported by: 0

README

Nook

Go Reference

Nook exports basic information for characters that appear in the video game series Animal Crossing.

Specifically this package centers on the organisation and classification of residents versus villagers, as well as defining the common attributes between them.

Residents in the context of this package are Animal Crossing characters that cannot be invited as home owners within the players town, city, or island. Residents perform a special role within the world and often are quest givers. An example of a Resident would be Isabelle, Tom Nook or Guliver.

Villagers are Animal Crossing characters that can be invited to stay in the players town, city or island, and make up the larger world population. Characters such as Alfonso, Tabby and Eggbert are all examples of Villagers. Villagers can be given gifts, have personalities and homes.

This package separates and organises Animal Crossing characters by their animal type. This is a requirement due to the large number of characters there are in the series, and that some characters overlap with other components in name. An example of this is the name Petunia, who is both a Cow and a Rhinoceros. Another example is Snooty, which is the name of one of the wolves and a personality type.

The information for this package has largely been sourced from various Wiki pages across the internet.

All contributions and corrections are welcome and encouraged.

Go

This package can be added as a dependency using Go's package manager.

Install

Adding the package.

go get -u github.com/lindsaygelle/nook

Docker

This code can be run and executed from within a Docker Container. Below are the instructions to use the provided Dockerfile as the development and testing environment.

Building

Building the Container.

docker build . -t nook
Running

Developing and running Go from within the Container.

docker run -it --rm --name nook nook

A docker-compose.yml file has also been added for convience.

Contents

Nook at the package level only exports the concrete types consumed by this package. The philosophy was to keep each package extensible, without the concern of searching through various subpackages to find all types that make up the package. Through this, ideally, the pattern will keep the imports relatively straightforward and simple. It should also allow each child package to focus on using only the known set of building blocks to create its exports, and limit the exposure to coding towards circular dependencies. Most of the decisions were shaped by the content of the Animal Crossing series, versus developer preference. For example, the initial concept was to have all characters live at the root package, but name conflicts, data types, and maintance became an issue. Having each character exist in its own directory was also attempted, but imports became confusing. All recommendations welcome, but for now this appears to be the best trade off.

Usage

The nook package can be used as the starting point for your own Animal Crossing program. By default all current Animal Crossing characters are provided. These can be imported by referencing the type of animal and the characters name.

package main

import (
	"encoding/json"
	"fmt"

	"github.com/lindsaygelle/nook"
	"github.com/lindsaygelle/nook/character/cat"
)

func main() {
	for _, cat := range []nook.Villager{cat.Ankha, cat.Tabby} {
		b, err := json.Marshal(cat)
		if err != nil {
			panic(err)
		}
		fmt.Println(string(b))
	}
}

Characters are also exported in bulk. These can be accessed by using the animal type and the villagers or residents variable.

package main

import (
	"fmt"

	"github.com/lindsaygelle/nook/character/dog"
	"golang.org/x/text/language"
)

func main() {
	for _, villager := range dog.Villagers {
		fmt.Println(fmt.Sprintf("%s is a villager in Animal Crossing", villager.Name.Must(language.AmericanEnglish).Value))
	}
	for _, resident := range dog.Residents {
		fmt.Println(fmt.Sprintf("%s is a resident in Animal Crossing", resident.Name.Must(language.AmericanEnglish).Value))
	}
}

Another example creating a simple API.

package main

import (
	"encoding/json"
	"net/http"

	"github.com/lindsaygelle/nook"
	"github.com/lindsaygelle/nook/character/cat"
	"github.com/lindsaygelle/nook/character/dog"
	"github.com/lindsaygelle/nook/character/wolf"
)

func rootHandler(w http.ResponseWriter, r *http.Request) {
	w.WriteHeader(http.StatusOK)
	w.Write(nil)
}

func createVillagersHandler(villagers nook.Villagers) http.HandlerFunc {
	b, err := json.Marshal(villagers)
	if err != nil {
		panic(err)
	}
	return func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/json;charset=utf-8")
		w.WriteHeader(http.StatusOK)
		w.Write(b)
	}
}

func main() {
	http.HandleFunc("/", rootHandler)
	http.HandleFunc("/cats", createVillagersHandler(cat.Villagers))
	http.HandleFunc("/dogs", createVillagersHandler(dog.Villagers))
	http.HandleFunc("/wolves", createVillagersHandler(wolf.Villagers))
	http.ListenAndServe(":8080", nil)
}

Extending

Nook was built with extensibility in mind. The simplest way to add to the functionality of the package is to import the concrete type and apply the required changes or functionality.

Below is an example of adding functionality to the nook.Villager type.

package main

import (
	"fmt"

	"github.com/lindsaygelle/nook"
	"github.com/lindsaygelle/nook/character/alligator"
	"golang.org/x/text/language"
)

var (
	alligators = []nook.Villager{
		alligator.Alfonso,
		alligator.Alli}
)

type Villager struct {
	nook.Villager
}

func (v Villager) Greet() string {
	name := v.Name.Must(language.AmericanEnglish).Value
	phrase := v.Phrase.Must(language.AmericanEnglish).Value
	return fmt.Sprintf("%s! My name is %s. Nice to meet you.", phrase, name)
}

func makeVillager(villager nook.Villager) Villager {
	return Villager{villager}
}

func makeVillagers(villagers ...nook.Villager) []Villager {
	v := make([]Villager, len(villagers))
	for i, villager := range villagers {
		v[i] = makeVillager(villager)
	}
	return v
}

func main() {
	villagers := makeVillagers(alligators...)
	for _, villager := range villagers {
		fmt.Println(villager.Greet())
	}
}

Another example is adding an outfit to one of your favourite Animal Crossing villagers.

package main

import (
	"bytes"
	"encoding/json"
	"fmt"

	"github.com/lindsaygelle/nook"
	"github.com/lindsaygelle/nook/character/duck"
	"golang.org/x/text/language"
)

type Outfit struct {
	Name nook.Languages
}

type Villager struct {
	nook.Villager
	Outfit Outfit
}

var (
	outfitFrogTeeAmericanEnglish = nook.Name{
		Language: language.AmericanEnglish, Value: "Frog Tee"}
)

var (
	outfitFrogTeeName = nook.Languages{
		language.AmericanEnglish: outfitFrogTeeAmericanEnglish}
)

var (
	outfitFrogTee = Outfit{
		Name: outfitFrogTeeName}
)

var (
	Scoot = newVillager(duck.Scoot, outfitFrogTee)
)

func newVillager(villager nook.Villager, outfit Outfit) Villager {
	return Villager{
		Villager: villager,
		Outfit:   outfit}
}

func main() {
	buffer := new(bytes.Buffer)
	encoder := json.NewEncoder(buffer)
	encoder.SetIndent("", "\t")
	err := encoder.Encode(Scoot)
	if err != nil {
		panic(err)
	}
	fmt.Println(buffer.String())
}

Documentation

Overview

Nook exports basic information for characters that appear in the video game series Animal Crossing.

Specifically this package centers on the organisation and classification of residents versus villagers, as well as defining the common attributes between them.

Residents in the context of this package are Animal Crossing characters that cannot be invited as home owners within the players town, city, or island. Residents perform a special role within the world and often are quest givers. An example of a Resident would be Isabelle, Tom Nook or Guliver.

Villagers are Animal Crossing characters that can be invited to stay in the players town, city or island, and make up the larger world population. Characters such as Alfonso, Tabby and Eggbert are all examples of Villagers. Villagers can be given gifts, have personalities and homes.

This package separates and organises Animal Crossing characters by their animal type. This is a requirement due to the large number of characters there are in the series, and that some characters overlap with other components in name. An example of this is the name Petunia, who is both a Cow and a Rhinoceros. Another example is Snooty, which is the name of one of the wolves and a personality type.

The information for this package has largely been sourced from various Wiki pages across the internet.

All contributions and corrections are welcome and encouraged.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Animal

type Animal struct {
	Key  Key
	Name Languages
}

Animal is the animal type of an Animal Crossing character.

type Birthday

type Birthday struct {
	Day   uint8
	Month time.Month
}

Birthday is the Animal Crossing characters birthday information.

func (Birthday) Ok

func (v Birthday) Ok() bool

Ok returns a boolean indicating whether the Birthday information is complete.

type Character

type Character struct {
	Animal

	Birthday Birthday
	Code     Code
	Key      Key
	Gender   Gender
	Name     Languages
}

Character is a representation of the common attributes for Animal Crossing characters.

type Code

type Code struct {
	Value string
}

Code is the unique identifier assigned to an Animal Crossing character. Codes are based on the data mined from the various Animal Crossing games.

func (Code) Ok

func (v Code) Ok() bool

Ok returns a boolean indicating whether the Code information is complete.

type Gender

type Gender struct {
	Name Languages
}

Gender is the gender of an Animal Crossing character.

type Key added in v0.2.0

type Key string

Key is a language agnostic name for a value.

type Languages

type Languages map[language.Tag]Name

Languages is a collection of language information.

func (Languages) Add

func (v Languages) Add(name Name)

Add adds a Name to the collection. Add uses Name.Language as the key to be retrieved from the Languages.

func (Languages) Del

func (v Languages) Del(key language.Tag) bool

Del removes a Name from Languages using the argument key.

func (Languages) Each

func (v Languages) Each(fn func(language.Tag, Name))

Each performs a for-each loop across Languages, executing the argument function for the Name at the current key.

func (Languages) EachWithBreak

func (v Languages) EachWithBreak(fn func(language.Tag, Name) bool)

Each performs a for-each loop across Languages, executing the argument function for the Name at the current key. Unlike Languages.Each it is possible to break out of the loop by returning true as a callback.

func (Languages) Get

func (v Languages) Get(key language.Tag) (Name, bool)

Get returns a Name from Languages using the argument key. Returns an additional boolean indicating whether the Name was found.

func (Languages) Has

func (v Languages) Has(key language.Tag) bool

Has returns a boolean indicating whether the Name exists for the argument key.

func (Languages) Must

func (v Languages) Must(key language.Tag) Name

Must returns a Name from Languages using the argument key. Unlike Languages.Get, Languages.Must panics on the condition a Name cannot be retrieved for the given key.

type Name

type Name struct {
	Language language.Tag
	Value    string
}

Name is the name of a value in a specific language.

func (Name) Ok

func (v Name) Ok() bool

Ok returns a boolean indicating whether the Name information is complete.

type Personality

type Personality struct {
	Name Languages
}

Personality is an Animal Crossing character personality type.

type Resident

type Resident struct {
	Character
}

Resident is the representation of an Animal Crossing character that performs special roles within the players town, city or island. Characters that are Residents cannot be invited to live within the players world, but inhabit the world indirectly. Residents and are often merchants, administrators or quest givers. Examples of characters that are residents are Tom Nook the raccoon, Isabelle the dog or Gulliver the seagull.

type Residents

type Residents map[Key]Resident

Residents is a collection of Resident.

func (Residents) Add

func (v Residents) Add(resident Resident)

Add adds a Resident to the collection.

func (Residents) Del

func (v Residents) Del(key Key) bool

Del removes a Resident from Residents using the argument key.

func (Residents) Each

func (v Residents) Each(fn func(Key, Resident))

Each performs a for-each loop across Residents, executing the argument function for the Resident at the current key.

func (Residents) EachWithBreak

func (v Residents) EachWithBreak(fn func(Key, Resident) bool)

Each performs a for-each loop across Residents, executing the argument function for the Resident at the current key. Unlike Residents.Each it is possible to break out of the loop by returning true.

func (Residents) Get

func (v Residents) Get(key Key) (Resident, bool)

Get returns a Resident from Residents using the argument key. Returns an additional boolean indicating whether the Resident was found.

func (Residents) Has

func (v Residents) Has(key Key) bool

Has returns a boolean indicating whether the Resident exists for the argument key.

func (Residents) Must

func (v Residents) Must(key Key) Resident

Must returns a Resident from Residents using the argument key. Unlike Residents.Get, Residents.Must panics on the condition a Resident cannot be retrieved for the given key.

type Villager

type Villager struct {
	Character

	Personality Personality
	Phrase      Languages
}

Villager is the representation of an Animal Crossing character that can be invited to live within the players town, city or island. Characters that are Villagers can be home owners and befriend the player. The player can exchange gifts and decorations with any Villager character. All Villagers have personalities and unique phrases that accompany them. Examples of characters that are villagers are Tabby the cat, Snooty the wolf and Alfonso the alligator.

type Villagers

type Villagers map[Key]Villager

Villagers is a collection of Villager.

func (Villagers) Add

func (v Villagers) Add(villager Villager)

Add adds a Villager to the collection.

func (Villagers) Del

func (v Villagers) Del(key Key) bool

Del removes a Villager from Villagers using the argument key.

func (Villagers) Each

func (v Villagers) Each(fn func(Key, Villager))

Each performs a for-each loop across Villagers, executing the argument function for the Villager at the current key.

func (Villagers) EachWithBreak

func (v Villagers) EachWithBreak(fn func(Key, Villager) bool)

Each performs a for-each loop across Villagers, executing the argument function for the Villager at the current key. Unlike Villagers.Each it is possible to break out of the loop by returning true.

func (Villagers) Get

func (v Villagers) Get(key Key) (Villager, bool)

Get returns a Villager from Villagers using the argument key. Returns an additional boolean indicating whether the Villager was found.

func (Villagers) Has

func (v Villagers) Has(key Key) bool

Has returns a boolean indicating whether the Villager exists for the argument key.

func (Villagers) Must

func (v Villagers) Must(key Key) Villager

Must returns a Villager from Villagers using the argument key. Unlike Villagers.Get, Villagers.Must panics on the condition a Villager cannot be retrieved for the given key.

Directories

Path Synopsis
Package animal exports the various types of animals found in the Animal Crossing series.
Package animal exports the various types of animals found in the Animal Crossing series.
Package character exports the key values for Animal Crossing characters.
Package character exports the key values for Animal Crossing characters.
cat
cow
dog
fox
owl
pig
Package gender exports the various genders of characters found in the Animal Crossing series.
Package gender exports the various genders of characters found in the Animal Crossing series.
Package personality exports the various personality types of villagers found in the Animal Crossing series.
Package personality exports the various personality types of villagers found in the Animal Crossing series.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL