-- $Name: Princess Asurja's Morning$
-- $Version: 2.0.0$
-- $Author: Khaelenmore Thaal & Sabra Naikomy$
-- $Info: Help Asurja handle her morning plans$

require 'fmt';
require 'noinv';
require 'lib/cutscene';
require 'lib/link';
require 'lib/music';
require 'lib/locale';
if instead.tiny then
  require 'lib/tiny/stubs';
else
  require 'lib/dire/theme';
end;

include 'game';
include 'settings';

fmt.quotes = false;
fmt.filter = function(r)
    local utf8 = (std.ref 'game'.codepage == 'UTF-8' or std.ref 'game'.codepage == 'utf-8')
    
    if utf8 then
        r = r:gsub('_"','«'):gsub('"_',"»");
        r = r:gsub('"([^"]*)"', translate_now("common_locale", 'quotes'));
        r = r:gsub(',,','„'):gsub("''",'”');
    end;
    
    r = r:gsub('<tab>', fmt.nb('    '));
    
    return r;
end;

std.phrase_show = false;
std.strip_call = false;

game.timer = function(s)
    music_player:tick();
    return false;
end;

function random_phrase(phrases)
  return phrases[rnd(#phrases)];
end;

game.use = function(s)
    return translate_now('use_locale', random_phrase({
    'use_1',
    'use_2',
    'use_3',
    'use_4',
    'use_5',
    'use_6'
  }));
end;

game.act = game.use;

room {
    {
      _spr = false;
    };
    nam = 'main';
    pic = function(s)
      if not s._spr and not instead.tiny then
        s._spr = sprite.new('images/cover_' .. image_suffix .. '.png'):scale(image_scale, image_scale, 1);
      end;
      return s._spr;
    end;
    disp = translate('menu_locale', 'full_title');
    noinv = true;
    notime = true;
    decor = translate('main', 'intro_text');
    way = {
        path {translate('menu_locale', 'start_game'), 'bedroom'};
        path {translate('menu_locale', 'intro'), 'intro1'};
        path {translate('menu_locale', 'about'), 'about'};
        path {translate('menu_locale', 'settings'), 'settings'};
        path {translate('menu_locale', 'quit'), 'quit'};
    };
}

room {
  nam = 'quit';
  onenter = function(s)
    instead.menu('exit');
    return false;
  end;
}

room {
    nam = 'about';
    noinv = true;
    notime = true;
    disp = translate('menu_locale', 'full_title');
    -- TODO fonts
    decor = function(s)
      return fmt.b(translate_now('menu_locale', 'credits_author') .. ':^') ..
        'Khaelenmore Thaal^^' ..
        fmt.b(translate_now('menu_locale', 'credits_engine') .. ':^') ..
        'INSTEAD, Петр Косых ({$link https://github.com/instead-hub/instead/})^^' ..
        fmt.b(translate_now('menu_locale', 'credits_art') .. ':^') ..
        'Sabra Naikomy ({$link https://naikomy.art/})^^' ..
        fmt.b(translate_now('menu_locale', 'credits_testing') .. ':^') ..
        'Lucky Ook, Mystery Shopper, Sabra Naikomy, Артур А., Борис Тимофеев^^' ..
        fmt.b(translate_now('menu_locale', 'credits_music') .. ':^') ..
        'Mozart, Piano Sonata No. 16 in C major, K. 545, Movements 1 & 2^' ..
        'Midi notes by Bernd Krueger ({$link http://piano-midi.de/})^' ..
        'CC-BY-SA 3.0 DE ({$link https://creativecommons.org/licenses/by-sa/3.0/de/deed.en})^' ..
        'Rendered into ogg format by Khaelenmore Thaal^^' ..
        fmt.b(translate_now('menu_locale', 'credits_fonts') .. ':^') ..
        'Bad Script, by Gaslight ({$link https://github.com/alexeiva/badscript})^' ..
        'Liberation Sans ({$link https://github.com/liberationfonts/liberation-fonts})^^' ..
        fmt.b(translate_now('menu_locale', 'credits_thanks'));
    end;
    way = {
        path {translate('common_locale', 'back'), 'main'};
    };
}

function init()
  if not prefs.cursor_scale then
    prefs.cursor_scale = false;
  end;
  
  if not prefs.text_input then
    prefs.text_input = true;
  end;
  
  if not prefs.completed then
    prefs.completed = false;
  end;
  
  if not prefs.font_scale then
    prefs.font_scale = false;
  end;
  
  if not prefs.inventory_scale then
    prefs.inventory_scale = false;
  end;
  
  if not prefs.text_alignment then
    prefs.text_alignment = 1;
  end;
  
  if not prefs.text_padding then
    prefs.text_padding = 1;
  end;
  
  if not prefs.text_interval then
    prefs.text_interval = 1;
  end;
  
  if not prefs.text_width then
    prefs.text_width = 100;
  end;
end;

function start(load)
  if not load then
      lifeon('watch');
      take('settings_menu');
      take('watch');
      take('task_list');
      
      timer:set(1000);
      music_player.loop = true;
      music_player:play_next('music/mozart_1.ogg');
      music_player:play_next('music/mozart_2.ogg');
  end;
  
  if not instead.tiny then
    diretheme.set_scale(get_graphic_scale());
    set_theme();
  end;
end;
