-- Copyright 2013 Evan Laforge
-- This program is distributed under the terms of the GNU General Public
-- License 3.0, see COPYING or http://www.gnu.org/licenses/gpl-3.0.txt

-- | One-time startup initialization tasks.
module App.LoadConfig where
import qualified Util.Log as Log
import qualified Ui.Style as Style
import qualified Ui.StyleC as StyleC
import qualified Ui.Symbol as Symbol
import qualified Ui.SymbolC as SymbolC

import Global


-- | Tell the UI layer about the given Symbols.  Warnings are logged for
-- Symbols that couldn't be loaded.
symbols :: [Symbol.Symbol] -> IO ()
symbols :: [Symbol] -> IO ()
symbols [Symbol]
syms = forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Symbol]
syms forall a b. (a -> b) -> a -> b
$ \Symbol
sym -> do
    [Font]
missing <- Symbol -> IO [Font]
SymbolC.insert Symbol
sym
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Font]
missing) forall a b. (a -> b) -> a -> b
$
        forall (m :: * -> *). (Stack, LogMonad m) => Text -> m ()
Log.warn forall a b. (a -> b) -> a -> b
$ Text
"failed to load symbol " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> Text
showt (Symbol -> Text
Symbol.name Symbol
sym)
            forall a. Semigroup a => a -> a -> a
<> Text
", fonts not found: " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> Text
showt [Font]
missing

styles :: [Style.Style] -> IO ()
styles :: [Style] -> IO ()
styles [Style]
style_table = forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_
    [ StyleId -> Style -> IO ()
StyleC.insert_style (Word8 -> StyleId
Style.StyleId Word8
n) Style
style
    | (Word8
n, Style
style) <- forall a b. [a] -> [b] -> [(a, b)]
zip [Word8
0..] [Style]
style_table
    ]