!% -~S
!% $OMIT_UNUSED_ROUTINES=1
!% $ZCODE_LESS_DICT_DATA=1

Constant Story      "Colours";
Constant Headline   "^A demonstration of using colours in PunyInform^";

Constant STATUSLINE_SCORE; Statusline score;

! Uncomment to add optional features to PunyInform
!Constant DEBUG;
Constant OPTIONAL_NO_DARKNESS;
!Constant RUNTIME_ERRORS = 0; ! 0, 1 or 2. 0 = smallest file, 2 = most info

! Define any library constants you need here, like MAX_SCORE, AMUSING_PROVIDED,
! MAX_CARRIED, SACK_OBJECT,  etc.

Constant INITIAL_LOCATION_VALUE = Library;

Include "globals.h";

#Ifv5;
Replace RestartSub;
#Endif;

Include "puny.h";

#Ifv5;
! Make sure we go back to the default colours, as a workaround
! for a bug in some interpreters, where the background doesn't
! automatically revert to its default colour on restart.
[ RestartSub;
	PrintMsg(MSG_RESTART_CONFIRM);
	if(YesOrNo()) {
		@set_colour CLR_DEFAULT CLR_DEFAULT;
		ClearScreen(WIN_ALL);
		@restart;
		return MSG_RESTART_FAILED;
	}
];
#Endif;

! Declare the colour constants we need to conveniently switch colours during the game
Constant MY_DEFAULT_FG = CLR_CYAN;
Constant MY_EMPHASIS_FG = CLR_WHITE;

Object Library "The Library"
	with
		description [;
			print "You are ";
			ChangeFgColour(MY_EMPHASIS_FG); ! This has no effect unless colours are active
			print "in ";
			ChangeFgColour(MY_DEFAULT_FG); ! This has no effect unless colours are active
			"a library.";
		];

Object -> Box "box"
	with
		name 'box',
		inside_description "It feels so nice, standing in the box.",
	has container open openable enterable;

[Initialise ozmoo_colours;
#Ifv5;
	if(OzmooColoursAvailable())
		ozmoo_colours = true;
	if(HDR_TERPFLAGS->0 & 1) {
		print "^^Would you like colour? ";
		if(YesOrNo()) {
			clr_on = true;
			clr_fg = MY_DEFAULT_FG; ! Defined in this program, right after including "puny.h"
			clr_bg = CLR_BLACK;
			if(ozmoo_colours)
				clr_fginput = CLR_OZMOO_LIGHT_GREEN; ! We choose to use one of the 8 extra colours in Ozmoo
			else
				clr_fginput = CLR_YELLOW; ! Don't set this, or set it to CLR_CURRENT, to keep input in same colour as normal text
			clr_fgstatus = CLR_RED; ! Don't set this, or set it to CLR_CURRENT, to keep statusline in same colour as normal text
		}
		ClearScreen(WIN_ALL);
	}
#Ifnot;
	ozmoo_colours = false;
#Endif;
	print "^^And so the story begins...^^";
];
