attr

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2016 License: BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Overview

The attr (attributes) package implements all of the functionality for objects in a WolfMUD world. All objects are instances of the Thing type. To these instances various attributes are added depending on the functionality required. The functionality of an object may be changed at runtime by adding or removing attributes.

A Thing can be searched for specific Attribute types using finders. All finders return a typed nil in the event of the specific Attribute type not being found. Returning a typed nil such as (*Alias)(nil) allows the finder to be chained to any other methods taking the a pointer to the Attribute type as a receiver. For example:

if attr.FindAlias(t).HasAlias("test") {
	// do something...
}

If you need to check specifically if the finder returns nil, compare the returned value to the typed nil:

if a := attr.FindAlias(t); a == (*Alias)(nil) {
	// do something...
}

Or if available use the Found method:

if !attr.FindAlias(t).Found() {
	// do something...
}

All methods that take a pointer to an Attribute as a receiver are expected to be able to handle a nil receiver unless otherwise stated.

All typed nils should be of the same type as the default implementation for the type. For example the has.Alias interface has attr.Alias as the default implementation, therefore the typed nil should also be of type *Alias.

While it may seem unusual to return a typed nil it simplifies and reduces a lot of code in WolfMUD.

Index

Constants

View Source
const (
	North byte = iota
	Northeast
	East
	Southeast
	South
	Southwest
	West
	Northwest
	Up
	Down
)

Constants for direction indexes. These can be used for the Link, AutoLink, Unlink and AutoUnlink methods. If these constants are modified probably need to update the Return function as well.

Variables

This section is empty.

Functions

func DumpFmt

func DumpFmt(format string, args ...interface{}) string

func FindAlias

func FindAlias(t has.Thing) has.Alias

FindAlias searches the attributes of the specified Thing for attributes that implement has.Alias returning the first match it finds or a *Alias typed nil otherwise.

func FindAllDescription

func FindAllDescription(t has.Thing) (matches []has.Description)

FindAllDescription searches the attributes of the specified Thing for attributes that implement has.Description returning all that match. If no matches are found an empty slice will be returned.

func FindExits

func FindExits(t has.Thing) has.Exits

FindExits searches the attributes of the specified Thing for attributes that implement has.Exits returning the first match it finds or a *Exits typed nil otherwise.

func FindInventory

func FindInventory(t has.Thing) has.Inventory

FindInventory searches the attributes of the specified Thing for attributes that implement has.Inventory returning the first match it finds or a *Inventory typed nil otherwise.

func FindLocate

func FindLocate(t has.Thing) has.Locate

FindLocate searches the attributes of the specified Thing for attributes that implement has.Locate returning the first match it finds or a *Locate typed nil otherwise.

func FindName

func FindName(t has.Thing) has.Name

FindName searches the attributes of the specified Thing for attributes that implement has.Name returning the first match it finds or a *Name typed nil otherwise.

func FindNarrative

func FindNarrative(t has.Thing) has.Narrative

FindNarrative searches the attributes of the specified Thing for attributes that implement has.Narrative returning the first match it finds or a *Narrative typed nil otherwise.

func FindPlayer

func FindPlayer(t has.Thing) has.Player

FindPlayer searches the attributes of the specified Thing for attributes that implement has.Player returning the first match it finds or a *Player typed nil otherwise.

func FindStart

func FindStart(t has.Thing) has.Start

FindStart searches the attributes of the specified Thing for attributes that implement has.Start returning the first match it finds or a *Start typed nil otherwise.

func FindVetoes

func FindVetoes(t has.Thing) has.Vetoes

FindVetoes searches the attributes of the specified Thing for attributes that implement has.Vetoes returning the first match it finds or a *Vetoes typed nil otherwise.

func FindWriting

func FindWriting(t has.Thing) has.Writing

FindWriting searches the attributes of the specified Thing for attributes that implement has.Writing returning the first match it finds or a *Writing typed nil otherwise.

func Return

func Return(direction byte) byte

Return calculates the opposite/return direction for the direction given. This is handy for calculating things like normal exits where if you go north you return by going back south. It is also useful for implementing ranged weapons, thrown weapons and spells. For example if you fire a bow west the person will see the arrow come from the east (from their perspective).

Types

type Alias

type Alias struct {
	Attribute
	// contains filtered or unexported fields
}

Alias implements an attribute for referring to a Thing. An alias is a single word used to refer to things. Things may have more than one alias. For example a sword may have the aliases 'SWORD' and 'SHORTSWORD'. Given these aliases a player may use commands such as:

GET SWORD
EXAMINE SHORTSWORD
DROP SHORTSWORD

TODO: Need to implement alias prefixes. This would allow us to distinguish between two similar items with the same alias. For example if there are two coins, one copper and one silver, we could use either "GET COPPER COIN" or "GET SILVER COIN". If there is only one coin then "GET COIN" would be sufficient. See also BUG about aliases being single words.

func NewAlias

func NewAlias(aliases ...string) *Alias

NewAlias returns a new Alias attribute initialised with the specified aliases. The specified aliases are automatically uppercased when stored.

func (*Alias) Aliases

func (a *Alias) Aliases() (aliases []string)

Aliases returns a []string of all the aliases for an Alias attribute. If there are no aliases an empty slice will be returned.

func (*Alias) Dump

func (a *Alias) Dump() []string

func (*Alias) Found

func (a *Alias) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Alias) HasAlias

func (a *Alias) HasAlias(alias string) (found bool)

HasAlias checks the passed string for a matching alias. Returns true if a match is found otherwise false.

func (*Alias) Unmarshal

func (*Alias) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Alias attribute.

type Attribute

type Attribute struct {
	// contains filtered or unexported fields
}

Attribute implements a stub for other attributes. Any types providing attributes can embed this type instead of implementing their own Parent and SetParent methods.

func (*Attribute) Marshal

func (a *Attribute) Marshal(attr has.Attribute) []byte

FOR DEVELOPMENT ONLY SO WE DON'T HAVE TO IMPLEMENT Marshal ON ALL THE ATTRIBUTES AT ONCE. REMOVE AS SOON AS ALL ATTRIBUTES UPDATED.

func (*Attribute) Parent

func (a *Attribute) Parent() has.Thing

Parent returns the Thing that the Attribute has been added to.

func (*Attribute) SetParent

func (a *Attribute) SetParent(t has.Thing)

SetParent is used to set the Thing that the Attribute has been added to. If it is not currently added to a Thing nil is returned. This method is automatically called by the Thing Add method.

type Description

type Description struct {
	Attribute
	// contains filtered or unexported fields
}

Description implements an attribute for describing Things. Things can have multiple descriptions or other attributes that implement the has.Description interface to add additional information to descriptions.

func NewDescription

func NewDescription(description string) *Description

NewDescription returns a new Description attribute initialised with the specified description.

func (*Description) Description

func (d *Description) Description() string

Description returns the descriptive string of the attribute.

func (*Description) Dump

func (d *Description) Dump() []string

func (*Description) Found

func (d *Description) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Description) Unmarshal

func (*Description) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Description attribute.

type Exits

type Exits struct {
	Attribute
	// contains filtered or unexported fields
}

Exits implements an attribute describing exits for the eight compass points north, northeast, east, southeast, south, southwest, west and northwest as well as the directions up and down and where they lead to. Exits are usually in pairs, for example one north and one back south. You can have one way exits or return exits that do not lead back to where you came from.

func NewExits

func NewExits() *Exits

NewExits returns a new Exits attribute with no exits set. Exits should be added to the attribute using the Link and AutoLink methods. The reason exits cannot be set during initialisation like most other attributes is that all 'locations' have to be setup before they can all be linked together.

func (e *Exits) AutoLink(direction byte, to has.Inventory)

AutoLink links the given exit, calculates the opposite return exit and links that automatically as well - as long as the parent Thing of the to Inventory has an Exits attribute.

func (e *Exits) AutoUnlink(direction byte)

AutoUnlink unlinks the given exit, calculates the opposite return exit and unlinks that automatically as well.

BUG(diddymus): Does not check that exit A links to B and B links back to A. For example a maze may have an exit going North from A to B but going South from B takes you to C instead of back to A as would be expected!

func (*Exits) Dump

func (e *Exits) Dump() []string

func (*Exits) Found

func (e *Exits) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Exits) LeadsTo

func (e *Exits) LeadsTo(direction byte) has.Inventory

LeadsTo returns the Inventory of the location found by taking a specific exit. If a particular direction leads nowhere nil will be returned.

func (e *Exits) Link(direction byte, to has.Inventory)

Link links the given exit direction to the given Inventory. If the given direction was already linked the exit will be overwritten - in effect the same as unlinking the exit first and then relinking it.

func (*Exits) List

func (e *Exits) List() string

List will return a string listing the exits you can see. For example:

You can see exits east, southeast and south.

func (*Exits) NormalizeDirection

func (*Exits) NormalizeDirection(name string) (direction byte, err error)

NormalizeDirection takes a long or short variant of a direction name in any case and returns the direction.

So 'N', 'NORTH', 'n', 'north', 'North' and 'NoRtH' all return the constant NORTH which is 0.

If the direction name given cannot be normalized, maybe because it is invalid, a non-nil error will be returned.

func (*Exits) Surrounding

func (e *Exits) Surrounding() []has.Inventory

Surrounding returns an Inventory slice of all locations immediatly reachable from the current location. The cuurent location is specified by the receiver. If there are no immediatly reachable locations an empty slice will be returned.

func (*Exits) ToName

func (*Exits) ToName(direction byte) (name string)

ToName returns the lowercased long name of a direction or an empty string if the direction is invalid.

func (e *Exits) Unlink(direction byte)

Unlink sets the exit for the given direction to nil. It does not matter if the given direction was not linked in the first place.

func (*Exits) Unmarshal

func (*Exits) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Exits attribute.

func (*Exits) Within

func (e *Exits) Within(moves int) (locations [][]has.Inventory)

Within returns all of the locations within the given number of moves from the location specified by the receiver. It is 3D and will follow up and down exits as well. The locations are returned as a slice of Inventory slices. The first slice represents the cwnumber of moves. The second slice is all locations within that number of moves. The first slice, moves 0, is always the current location.

Assume the following map of the Tavern and surrounding locations:

 ____________________________________________________________
|1             |3             |5              |6             |
|  Fireplace       Entrance     Between           Bakery     |
|                               Tavern/Bakery                |
|__                         __|__           __|______________|
|2              4             |7              |8             |
|  Common Room     Bar        | Street outside    Pawn Shop  |
|                             | Pawn Shop                    |
|______________|______________|__           __|______________|
               |10            |9              |
               |   Outside      Fountain      |
               |   Armourer     Square        |
               |______________|_______________|

If we are at location 7 on the map then Within(2) will return all locations within 2 moves:

 [][]has.Inventory{
	[]has.Inventory{ 7 },					// Within 0 moves of location 7
	[]has.Inventory{ 5, 8, 9 },   // Within 1 move of location 7
	[]has.Inventory{ 6, 3, 10 },  // Within 2 moves of location 7
 }

The above numbers e.g. 5,8,9 refer to the map locations. In reality they would actually be references to has.Inventory interface types.

See cmd/sneeze.go for an example of using the Within method.

type Inventory

type Inventory struct {
	Attribute

	internal.BRL
	// contains filtered or unexported fields
}

Inventory implements an attribute for container inventories. The most common container usage is for locations and rooms as well as actual containers like bags, boxes and inventories for mobiles. WolfMUD does not actually define a specific type for locations. Locations are simply Things that have Inventory and usually Exits attributes.

For a complete description of narratives see the Narrative attribute type.

NOTE: The contents slice is split into two parts. Things with a Narrative attribute are added to the begenning of the slice. All other Things are appended to the end of the slice. Which items are narrative and which are not is tracked by split:

narattives := contents[:split]
other := contents[split:]

countNarratives := split
countOther := len(contents) - split

BUG(diddymus): Inventory capacity is not implemented yet.

func NewInventory

func NewInventory(t ...has.Thing) *Inventory

NewInventory returns a new Inventory attribute initialised with the specified Things as initial contents.

BUG(diddymus): NewInventory should use proper copies of the Things passed. Until Attribute and Thing implement a Copy method we can't do that. Implementing a Copy method instead of building a reflect deep copy is more desirable as it will allow us to fine tune exactly what is copied and how it is copied when duplicating a Thing.

func (*Inventory) Add

func (i *Inventory) Add(t has.Thing)

Add puts the specified Thing into the Inventory. If the Thing needs to know where it is - because it implements the has.Locate interface - we update where the Thing is to point to the Inventory.

func (*Inventory) Contents

func (i *Inventory) Contents() []has.Thing

Contents returns a 'copy' of the Inventory non-narrative contents. That is a copy of the slice containing has.Thing interface headers. Therefore the Inventory contents may be indirectly manipulated through the copy but changes to the actual slice are not possible - use the Add and Remove methods instead.

func (*Inventory) Crowded

func (i *Inventory) Crowded() (crowded bool)

func (*Inventory) Dump

func (i *Inventory) Dump() (buff []string)

func (*Inventory) Empty

func (i *Inventory) Empty() bool

Empty returns true if there are no non-Narrative items else false.

func (*Inventory) Found

func (i *Inventory) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Inventory) List

func (i *Inventory) List() string

List returns a string describing the non-narrative contents of an Inventory. The format of the string is dependant on the number of items. If the Inventory is empty:

It is empty.

A single item only:

It contains xxx.

Multiple items:

It contains:
	Item
	Item
	Item
	...

If the inventory cannot be listed an empty string will be returned.

func (*Inventory) Remove

func (i *Inventory) Remove(t has.Thing) has.Thing

Remove tries to take the specified Thing from the Inventory. If the Thing is removed successfully it is returned otherwise nil is returned. If the Thing needs to know where it is - because it implements the has.Locate interface - we update where the Thing is to nil as it is now nowhere.

TODO: A slice is fine for conveniance and simplicity but maybe a linked list would be better?

func (*Inventory) Search

func (i *Inventory) Search(alias string) has.Thing

Search returns the first Inventory Thing that matches the alias passed. If no matches are found nil is returned.

func (*Inventory) Unmarshal

func (*Inventory) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Inventory attribute.

type Locate

type Locate struct {
	Attribute
	// contains filtered or unexported fields
}

Locate implements an attribute that refers to the Inventory of where something is. When a Thing changes the Inventory it is contained in and has a Locate attribute SetWhere should be called to update the reference. This attribute only needs to be added to things that need to know where they are. For example a player needs to know where they are so that they can move themselves.

func NewLocate

func NewLocate(i has.Inventory) *Locate

NewLocate returns a new Locate attribute initialised to refer to the passed Inventory. Passing nil is a valid reference and is usually treated as being nowhere.

func (*Locate) Dump

func (l *Locate) Dump() []string

func (*Locate) Found

func (l *Locate) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Locate) SetWhere

func (l *Locate) SetWhere(i has.Inventory)

SetWhere is used to set the Inventory where 'we' are. Passing nil is a valid reference and is usually treated as being nowhere. The current reference can be retrieved by calling Where.

NOTE: This is called automatically by the Inventory Add and Remove methods.

func (*Locate) Unmarshal

func (*Locate) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Locate attribute. At the moment Locate attributes are created internally so return an untyped nil so we get ignored.

func (*Locate) Where

func (l *Locate) Where() (where has.Inventory)

Where returns the Inventory where 'we' are. Returning nil is a valid reference and is usually treated as being nowhere. The current reference should be set by calling SetWhere.

type Name

type Name struct {
	Attribute
	// contains filtered or unexported fields
}

func NewName

func NewName(n string) *Name

Name implements an attribute for naming Things. It is used when referring to or listing Things. For example if there is a sword it could have the name of 'a sword'. Then manipulating it you could see the following messages:

You see a sword here.
You pick up a sword.
You examine a sword.
You start to wield a sword.

Messages such as the examples would typically be general messages with a placeholder for the name of the Thing. For example:

You see %s here.
You pick up %s.
You examine %s.
You start to wield %s.

It is therefore important to take this into consideration when choosing names for Things.

func (*Name) Dump

func (n *Name) Dump() []string

func (*Name) Found

func (n *Name) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Name) Name

func (n *Name) Name(preset string) string

Name returns the name stored in the attribute. If the receiver is nil or the name is an empty string the specified preset will be returned instead. This allows for a generic preset name such as someone, something or somewhere to be returned for things without names.

func (*Name) Unmarshal

func (*Name) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Name attribute.

type Narrative

type Narrative struct {
	Attribute
}

Narrative implements an attribute to mark non-removable content. It allows creators to cater to the more discerning adventurer by providing content that is not spoon fed to them. Narrative content is usually mentioned or discoverable from text descriptions. For example:

You are in the corner of a common room in the Dragon's Breath tavern. There
is a fire burning away merrily in an ornate fireplace giving comfort to
weary travellers. Shadows flicker around the room, changing light to
darkness and back again. To the south the common room extends and east the
common room leads to the tavern entrance.

From such a description it would be reasonable for someone to want to example the fireplace although there would be no "You see a fireplace here." when listing the items at the location. Should someone try to examine the fireplace they are rewarded with:

This is a very ornate fireplace carved from marble. Either side a dragon
curls downward until the head is below the fire looking upward, giving the
impression that they are breathing fire.

While anything that can normally be put into an inventory can be put into a narrative, nothing should be directly removable. However everything in a narrative still works as expected - readable things are still readable and containers can have things put in them as well as removed. As an example consider this brief description:

You are standing next to a small fish pond. Paths lead off north, south and
west deeper into the gardens.

Examining the pond - in this case a simple inventory - reveals its content:

This is a small fish pond. It contains a fish of gold.

Taking the fish from the pond and examining it reveals:

This is a small fish made from solid gold.

A much more satisfying reward for being curious :)

NOTE: At the moment narrative content should not be removeable for the simple reason that descriptions are mostly static - for now(?). So removing something would therefore invalidate the descriptive text.

func NewNarrative

func NewNarrative() *Narrative

NewNarrative returns a new Narrative attribute.

func (*Narrative) Dump

func (n *Narrative) Dump() (buff []string)

func (*Narrative) Found

func (n *Narrative) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Narrative) ImplementsNarrative

func (*Narrative) ImplementsNarrative()

ImplementsNarrative is a marker method so that we can specifically identify a Narrative.

func (*Narrative) Unmarshal

func (*Narrative) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Narrative attribute.

type Player

type Player struct {
	Attribute
	io.Writer
	has.PromptStyle
}

Player implements an attribute for associating a Thing with a Writer used to return data to the associated client.

func NewPlayer

func NewPlayer(w io.Writer) *Player

NewPlayer returns a new Player attribute initialised with the specified Writer which is used to send data back to the associated client.

func (*Player) Dump

func (p *Player) Dump() []string

func (*Player) Found

func (p *Player) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Player) SetPromptStyle

func (p *Player) SetPromptStyle(new has.PromptStyle) (old has.PromptStyle)

SetPromptStyle is used to set the current prompt style and returns the previous prompt style. This is so the previous prompt style can be restored if required later on.

func (*Player) Unmarshal

func (*Player) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Player attribute. At the moment Player attributes are created internally so return an untyped nil so we get ignored.

func (*Player) Write

func (p *Player) Write(b []byte) (n int, err error)

Write writes the specified byte slice to the associated client.

type Start

type Start struct {
	Attribute
}

Start implements an attribute for tagging a Thing as a starting location.

func NewStart

func NewStart() *Start

NewStart returns a new Start attribute. When a new Start attribute is created it is also registered automatically.

TODO: Implement starting locations that are only usable by specific players. For example only dwarves should start in the dwarven home, or thieves in the thieves guild.

func (*Start) Dump

func (s *Start) Dump() []string

func (*Start) Found

func (s *Start) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Start) Pick

func (*Start) Pick() has.Inventory

Pick returns the Inventory of a randomly selected starting location.

func (*Start) Unmarshal

func (*Start) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Start attribute.

type Thing

type Thing struct {
	// contains filtered or unexported fields
}

Thing is a container for Attributes. Everything in WolfMUD is constructed by creating a Thing and then adding Attributes to it which implement specific functionality.

func NewThing

func NewThing(a ...has.Attribute) *Thing

NewThing returns a new Thing initialised with the specified Attributes. Attributes can also be dynamically modified using Add and Remove methods.

func (*Thing) Add

func (t *Thing) Add(a ...has.Attribute)

Add is used to add the passed Attributes to a Thing. When an Attribute is added its parent is set to reference the Thing it was added to. This allows an Attribute to find and query the parent Thing about other Attributes the Thing may have.

func (*Thing) Attrs

func (t *Thing) Attrs() []has.Attribute

Attrs returns all of the Attributes a Thing has as a slice of has.Attribute. This is commonly used to range over all of the Attributes of a Thing instead of using a finder for a specific type of Attribute.

func (*Thing) Close

func (t *Thing) Close()

Close is used to clean-up/release references to all Attribute for a Thing. When a Thing is finished with calling Close helps the garbage collector to reclaim objects. It can also help to break cyclic references that could prevent garbage collection.

func (*Thing) Dump

func (t *Thing) Dump() (buff []string)

func (*Thing) Remove

func (t *Thing) Remove(a ...has.Attribute)

Remove is used to remove the passed Attributes from a Thing. When an Attribute is removed its parent it set to nil. There is no indication if an Attribute cannot actually be removed.

func (*Thing) Unmarshal

func (t *Thing) Unmarshal(recno int, record recordjar.Record)

Unmarshal unmarshals a Thing from a recordjar record containing all of the Attribute to be added. The recno is the record number in the recordjar for this record. It is passed so that we can give informative messages if errors are found. If the record number is not known -1 should be passed instead.

type Veto

type Veto struct {
	// contains filtered or unexported fields
}

Veto implements a veto for a specific command. Veto need to be added to a Vetoes list using NewVetoes.

func NewVeto

func NewVeto(cmd string, msg string) *Veto

NewVeto returns a new Veto attribute initialised for the specified command with the specified message text. The command is a normal command such as GET and DROP and will automatically be uppercased. The message text should indicate why the command was vetoed such as "You can't drop the sword. It seems to be cursed". Referring to specific items - such as the sword in the example - is valid as a Veto is for a specific known Thing.

func (*Veto) Command

func (v *Veto) Command() string

Command returns the command associated with the Veto.

func (*Veto) Dump

func (v *Veto) Dump() (buff []string)

func (*Veto) Message

func (v *Veto) Message() string

Message returns the message associated with the Veto.

type Vetoes

type Vetoes struct {
	Attribute
	// contains filtered or unexported fields
}

Vetoes implement an attribute for lists of Veto preventing commands for a Thing that would otherwise be valid. For example you could Veto the drop command if a very sticky item is picked up :)

func NewVetoes

func NewVetoes(veto ...has.Veto) *Vetoes

NewVetoes returns a new Vetoes attribute initialised with the specified Vetos.

func (*Vetoes) Check

func (v *Vetoes) Check(cmd ...string) has.Veto

Check checks if any of the passed commands are vetoed. The first matching Veto found is returned otherwise nil is returned.

func (*Vetoes) Dump

func (v *Vetoes) Dump() (buff []string)

func (*Vetoes) Found

func (v *Vetoes) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Vetoes) Unmarshal

func (*Vetoes) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Vetoes attribute.

type Writing

type Writing struct {
	Attribute
	// contains filtered or unexported fields
}

Writing implements an attribute that allows for writing to be put onto any Thing so that it can be read.

TODO: Writing currently assumes the text is written onto a Thing. However it could also be carved, burnt, painted, etc. onto a Thing. It also assumes the text is in a common language known to all. If language were implemented we could write in common, elvish, dwarfish, ancient runes, secret code or anything else with the text only being readable by those who know the relevant language. See also the Writing Description method.

func NewWriting

func NewWriting(w string) *Writing

NewWriting returns a new Writing attribute initialised with the specified writing/text.

func (*Writing) Description

func (w *Writing) Description() string

Description automatically adds the specified text to the description of a Thing that has a has.Writing attribute.

FIXME: This should return a message based on the type of writing: runes, painting, carving etc. See also TODO for the Writing type.

func (*Writing) Dump

func (w *Writing) Dump() []string

func (*Writing) Found

func (w *Writing) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Writing) Unmarshal

func (*Writing) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Writing attribute.

func (*Writing) Writing

func (w *Writing) Writing() (writing string)

Writing returns the text that has been written.

Notes

Bugs

  • Aliases are expected be single words only, otherwise they probably won't work correctly and cause all sorts of weird problems and behaviour. See also TODO about prefixes.

  • Does not check that exit A links to B and B links back to A. For example a maze may have an exit going North from A to B but going South from B takes you to C instead of back to A as would be expected!

  • Inventory capacity is not implemented yet.

  • NewInventory should use proper copies of the Things passed. Until Attribute and Thing implement a Copy method we can't do that. Implementing a Copy method instead of building a reflect deep copy is more desirable as it will allow us to fine tune exactly what is copied and how it is copied when duplicating a Thing.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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