Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

avatar source realm

Readme View source

Settler avatars

This realm's one job is to show off a Settler as a small picture, for anyone who asks. If an account owns a Settler, this is the place that draws it.

This realm doesn't own or store anything itself; it just looks up a Settler and draws it, on the spot, whenever it's asked to. Keeping it separate means any other realm or web app on Gno.land can show someone's Settler next to their name, in a forum post, a leaderboard, or a profile, without having to know anything about how the art is put together. They just ask this realm for the picture.

The Settlers nft realm is what actually hands out the gnomes and keeps track of who owns what.

Usage Example

This gives you a Settler image next to the address, ready to write into your own Markdown:

1import "gno.land/r/g17khqpukees4237dtn3astzapmp462vjhsz6st4/settlers/avatar"
2
3func RenderUser(addr address) string {
4	// Size: 32x32 px, Transparent background: true
5	return avatar.Markdown(addr, 32, true) + " " + addr.String()
6}

Markdown returns nothing if the address has no Settler, so there's no need to check first. SVG and URI work the same way, and give you the raw picture instead, if that's what you need.

Constants 1

const MinSize, MaxSize

1const (
2	// MinSize is the minimum size allowed for an avatar in pixels.
3	MinSize = 32
4
5	// MaxSize is the maximum size allowed for an avatar in pixels.
6	MaxSize = 2048
7)
source

Variables 1

var Notice, NoticeType, RealmPath, admin, goSnippet, gnokeySnippet

 1var (
 2	// Notice is a realm-wide message the admin can post at any time, shown at the top of the page.
 3	// It never affects SVG, URI or Markdown, it is purely informational.
 4	Notice string
 5
 6	// NoticeType is the style Notice is shown as.
 7	NoticeType mdalert.Type
 8
 9	// Realm path is the path of this realm.
10	RealmPath string
11
12	// Admin account for the realm, only valid to post or clear realm-wide notices.
13	admin *ownable.Ownable
14
15	// Go snippet is the Go usage example.
16	goSnippet string
17
18	// Gnokey snippet is the gnokey example.
19	gnokeySnippet string
20)
source

Functions 7

func Markdown

Action
1func Markdown(addr address, size int, transparent bool) string
source

Markdown returns the avatar of an address as a Markdown image, or an empty text if it has none:

Example
1![Settler #12](data:image/svg+xml;charset=utf-8,...)

The size and transparent are the same as in SVG.

func Render

1func Render(path string) string
source

Render renders the realm.

By default renders what this realm is, how to use it, and some avatars.

Paths:

  • `svg/{address}`: The SVG of the Settler of an address.
  • `md/{address}`: The Markdown that Markdown returns for an address, rendered, with the same parameters.

func SVG

Action
1func SVG(addr address, size int, transparent bool) string
source

SVG returns the SVG document of the Settler of an address, or an empty text if it has none.

The size is the width and height in pixels of the square image, from 32 to 2048 (multiples of 32 keep every art pixel as a whole number of screen pixels). A size of 0 or less leaves out the width and the height, so that the image scales to its container. If transparent is true, the image has no background.

func SetNotice

crossing Action
1func SetNotice(cur realm, alertType mdalert.Type, msg string)
source

SetNotice posts a realm-wide message, shown at the top of the page.

func TransferAdmin

crossing Action
1func TransferAdmin(cur realm, newAdmin address)
source

TransferAdmin makes another account the admin. Only the admin can call it.

func URI

Action
1func URI(addr address, size int, transparent bool) string
source

URI returns the image of the Settler of an address as a "data:image/svg+xml;charset=utf-8," URI, that can be used as the source of an image or as the address of a Markdown image, or an empty text if it has none. The size and transparent are the same as in SVG.

Imports 12

Source Files 4