package cond

import "git.teletypegames.org/engines/inkwell/cond"

Package cond holds the adventure-specific conditions: the ones that need more of the game than the inkbase.State in the Ctx. Each one type-asserts ctx.Game to the narrow host interface it requires — InventoryChecker for HasItem and SelectedItem, SceneChecker for InScene, StageChecker for OnStage, OnWorld and Started — and an inkwell *Game satisfies all of them. Games normally use the re-exports in the root inkwell package, which take the entity itself (a *Scene, an *Item) rather than its name.

The generic conditions and the combinators (Not, And, Or, Flag, VarEq, Knows) live in the inkbase/condition package.

Conditions

A condition is stateless and evaluated lazily, every time it is asked — in an If action, in a dialog choice's Show, in a widget's When, in a trigger, in an achievement. Nothing is cached, so a condition always answers for the game as it stands.

Given is the one that is a struct rather than a constructor, and it is there for the place a condition is read most: a dialog choice, where "only if the player holds the tape and has not been told yet" is two stacked fields rather than a call tree:

Show: inkwell.Given{
	Item:    mysteryTape,
	NotFlag: "dex_told",
},

Every field set on a Given has to hold — Flag raised, NotFlag not, Item in the inventory, NotItem not, Var equal to Is — so a Given is an And of its fields, an empty Given holds always, and Or(Given{…}, Given{…}) is still how alternatives read.

Index

Functions

func HasItem

func HasItem(name string) inkbase.Condition

HasItem is true while the named item is in the inventory.

func InScene

func InScene(name string) inkbase.Condition

InScene is true while the named scene is the current one.

func OnStage

func OnStage(stage any) inkbase.Condition

OnStage is true while the given Stage is the one showing. The argument is a *Stage pointer; identity comparison is used.

func OnWorld

func OnWorld() inkbase.Condition

OnWorld is true while the Stage showing is the world.

func SelectedItem

func SelectedItem(name string) inkbase.Condition

SelectedItem is true while the named item is the one in hand.

func Started

func Started() inkbase.Condition

Started is true once a session exists: the world has been begun or loaded.

Types

type Given

type Given struct {
	// Flag must be raised; NotFlag must not be.
	Flag    string
	NotFlag string
	// Item must be in the inventory; NotItem must not be.
	Item    *item.Item
	NotItem *item.Item
	// Var must compare equal to Is, by Go's own ==. Is alone means nothing;
	// Var alone compares the variable to nil.
	Var string
	Is  any
}

Given is a Condition written as a literal: every field that is set has to hold, and an empty Given holds always. It is the shape a dialog choice or a widget reads best in -- one struct, the requirements stacked -- where the combinators would spell the same thing as a call tree.

func (Given) Eval
func (given Given) Eval(ctx *inkbase.Ctx) bool

Eval reports whether every set field of given holds in ctx: the flags raised or not on ctx.State, the items in the inventory or not, and the variable equal to Is. An Item or NotItem condition is false when ctx.Game cannot answer InventoryChecker.

type InventoryChecker

type InventoryChecker interface {
	InventoryHas(name string) bool
	InventorySelected() string
}

InventoryChecker is the slice of *Game that HasItem and SelectedItem need.

type SceneChecker

type SceneChecker interface {
	CurrentScene() string
}

SceneChecker is the slice of *Game that InScene needs.

type StageChecker

type StageChecker interface {
	CurrentStagePtr() any
	OnWorldStage() bool
	Started() bool
}

StageChecker is the slice of *Game that OnStage, OnWorld and Started need.