packages feed

mischief-assets-0.1.0.0: test/Main.hs

{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Main where

import Control.Monad
import Data.Text qualified as T
import Linear (V2)
import Mischief.Assets
import Mischief.ECS

newtype SomeAsset = SomeAsset {vec :: V2 Float}
  deriving (Generic, KdlAsset, Component, Show)

instance Asset SomeAsset where
  type Saveable SomeAsset = False
  loadAsset = loadKdl "a"

-- instance Asset SomeAsset where
--   loadAsset = loadKdl "a"

data MyCollection = MyCollection
  { someImage :: AssetRef Image,
    someAssets :: [KdlRef SomeAsset],
    someMap :: KdlCollection SomeAsset
  }
  deriving (Generic, KdlAsset, Component, Show)

instance Asset MyCollection where
  type Saveable MyCollection = False
  loadAsset = loadKdl "collection"

main :: IO ()
main = do
  app <- newApp
  setAssetSource "test" app
  addPlugin @P app
  runApp app

data P

instance Plugin P where
  init = do
    void $ load @SomeAsset "a.kdl"

    -- whenLoaded' (Ref @MyCollection "collection.kdl") $ warn . T.show

    systems dummy & schedule @Update
    void $ spawn $ Observer loadedA

  deps = [dep @FileWatcherPlugin]

dummy :: System ()
dummy = pure ()

loadedA :: OnLoad SomeAsset -> System ()
loadedA (OnLoad a) = [q|a. SomeAsset|] & qinfo T.show & query_