// Event handlers we can assign outside of the case statements

defer main-event-new-session noop
defer main-event-do-select noop
defer main-event-do-info noop
defer main-event-do-esc noop
defer main-event-do-title noop
defer main-event-do-options noop
defer main-event-do-save noop
defer main-event-do-load noop
defer main-event-loaded-session noop

defer main-event-do-save-custchars noop
defer main-event-do-load-custchars noop

defer main-event-road-start noop
defer main-event-road-resume noop
defer main-event-road-tick noop
defer main-event-road-periodic noop
defer main-event-road-end noop

defer main-event-mission-setup noop
defer main-event-mission-start noop
defer main-event-mission-tick noop
defer main-event-mission-periodic noop
defer main-event-mission-edge noop
defer main-event-mission-location-leave noop
defer main-event-mission-killed noop
defer main-event-mission-end noop

defer main-event-cyoa-start noop
defer main-event-cyoa-resume noop
defer main-event-cyoa-end noop

defer main-event-social-moment noop

defer textfill-vehicle-tab noop
defer textfill-stats-tab noop

0 	enum GAME_STATE_NONE
	enum GAME_STATE_MISSION
	enum GAME_STATE_DRIVING
drop

0 value game-state

voc{ textfill
	: +cr cr$ +textfill ;
	: +chr $chr +textfill ;
	: +text postpone +textfill ; immediate
	: +purple 0x f4 $chr +text ;
	: +blue 0x f1 $chr +text ;
	: +green 0x f2 $chr +text ;
	: +red 0x f3 $chr +text ;
	: +white 0x f0 $chr +text ;
}

: handle-textfill
	case
		TEXTFILL_VEHICLE_TAB of textfill-vehicle-tab endof
		TEXTFILL_STATS_TAB of textfill-stats-tab endof
	endcase
;

: main-handler
	case
		// *** UI events

		MAIN_EVENT_NEW of
			main-event-new-session endof

		MAIN_EVENT_DO_TITLE of
			main-event-do-title endof
		MAIN_EVENT_DO_OPTIONS of
			main-event-do-options endof
		MAIN_EVENT_DO_SELECT of
			main-event-do-select endof
		MAIN_EVENT_DO_INFO of
			main-event-do-info endof
		MAIN_EVENT_DO_ESC of
			main-event-do-esc endof
		MAIN_EVENT_DO_LOAD of
			main-event-do-load endof
		MAIN_EVENT_DO_SAVE of
			main-event-do-save endof
		MAIN_EVENT_LOADED of
			main-event-loaded-session endof

		MAIN_EVENT_DO_SAVE_CUSTCHARS of
			main-event-do-save-custchars endof
		MAIN_EVENT_DO_LOAD_CUSTCHARS of
			main-event-do-load-custchars endof


		// *** Mission events
		MAIN_EVENT_MISSION_SETUP of
//			"--> MAIN_EVENT_MISSION_SETUP" print
			main-event-mission-setup endof
		MAIN_EVENT_MISSION_START of
//			"--> MAIN_EVENT_MISSION_START" print
			main-event-mission-start endof
		MAIN_EVENT_MISSION_TICK of
			main-event-mission-tick endof
		MAIN_EVENT_MISSION_PERIODIC of
			main-event-mission-periodic endof
		MAIN_EVENT_MISSION_EDGE_LEAVE of
			main-event-mission-edge endof
		MAIN_EVENT_MISSION_LOCATION_LEAVE of
			main-event-mission-location-leave endof
		MAIN_EVENT_MISSION_KILLED of
			main-event-mission-killed endof
		MAIN_EVENT_MISSION_END of
			main-event-mission-end endof

		// *** Road events
		MAIN_EVENT_DRIVING_START of
			1 to game-state
			main-event-road-start endof
		MAIN_EVENT_DRIVING_RESUME of
			main-event-road-resume endof
		MAIN_EVENT_DRIVING_PERIODIC of
			main-event-road-periodic endof
		MAIN_EVENT_DRIVING_TICK of
			main-event-road-tick endof
		MAIN_EVENT_DRIVING_END of
			main-event-road-end endof

		MAIN_EVENT_TEXTFILL of handle-textfill endof

		MAIN_EVENT_CYOA_START of
			main-event-cyoa-start endof
		MAIN_EVENT_CYOA_RESUME of
			main-event-cyoa-resume endof
		MAIN_EVENT_CYOA_END of
			main-event-cyoa-end endof

		// *** Other
		MAIN_EVENT_SOCIAL_MOMENT of
			main-event-social-moment endof
	endcase
;

last main-event-handler!

