<h1 id="stack">Stack</h1>
<p><a href="https://docs.haskellstack.org/en/stable/README/">Stack</a> is a cross-platform program for developing Haskell projects. It features:</p>
<ul>
<li>Installing GHC automatically, in an isolated location.</li>
<li>Installing packages needed for your project.</li>
<li>Building your project.</li>
<li>Testing your project.</li>
<li>Benchmarking your project.</li>
</ul>
<p>Follow <a href="https://docs.haskellstack.org/en/stable/README/">installation instructions</a> to get it installed in your system.</p>
<h1 id="starting-a-new-project">Starting a new project</h1>
<p>Our game will be called Treasure Dungeon. After installing stack, we'll open a new terminal window, change into some suitable directory and use stack to create our project: <code>stack new treasure-dungeon rio</code>.</p>
<p>This will create directory <code>treasure-dungeon</code> and initialize it by using <code>rio</code> template. <a href="https://hackage.haskell.org/package/rio">rio</a> is a standard library that I have recently started using. There's a <a href="https://www.fpcomplete.com/haskell/library/rio/">tutorial</a> available if you want to learn more about it. We'll cover only very basics while writing the game.</p>
<h2 id="package.yaml">package.yaml</h2>
<p>Next step is to modify the project settings for the project that was created for us. Have a look at license file and change that to your liking. Then open up <code>package.yaml</code> and edit some of the metadata:</p>
<ul>
<li><code>git</code> this should point to your public repository</li>
<li><code>license</code> this has machine readable info about the license terms</li>
<li><code>author</code> here you should fill in your info</li>
<li><code>maintainer</code> this is the person currently maintaining the package</li>
<li><code>copyright</code> Copyright information</li>
<li><code>executablebles</code> this section lists executable, you may want to edit the name</li>
</ul>
<p>I have a repository at <a href="https://codeberg.org/Tuula/treasure-dungeon">codeberg</a> if you want to have a look what settings I ended up with.</p>
<h2 id="stack.yaml">stack.yaml</h2>
<p>Having finished with <code>package.yaml</code>, save it and start editing <code>stack.yaml</code>. Here we change only one setting: - resolver: lts-18.27, this specifies which set of libraries to use. These are fetched from <a href="https://www.stackage.org/">Stackage</a>.</p>
<p>Final step is to edit <code>README.md</code> to suit your needs.</p>
<h1 id="using-stack">Using stack</h1>
<p>Now we can work on our project. Lets start by building it: <code>stack build</code>. This will build the example code. There's one library and one executable there. If everything went correctly, we can start our executable with <code>stack exec -- treasure-dungeon</code>. This should print a little message on screen and exit. We can also turn on verbose logging, by starting the project with <code>stack exec -- treasure-dungeon --verbose 2&gt; log.txt</code>.</p>
<p>Another useful command is <code>stack test</code>, which will compile and run tests for the project. There's couple simple ones as an example created by the template.</p>
<p>And if you want to clean up your project of intermediate files and exes, you can use <code>stack clean</code>.</p>
<h1 id="project-structure">Project structure</h1>
<p>Final thing before finishing, let's have a look at the project structure. There's three directories: <code>app</code>, <code>src</code> and <code>test</code>.</p>
<p><code>app</code> contains code for our executable. This is where we will be placing big portion of the code, mainly one that deals with user interactions.</p>
<p><code>src</code> contains code for our library. This is where we will be placing code that codifies rules of the game. We want to keep this part of the code oblivious about outside world, like screens, user input and such.</p>
<p><code>test</code> this is where tests live. We aren't going to do much with them most likely.</p>
<h1 id="in-closing">In closing</h1>
<p>We started our card game project. It doesn't do much yet, but we already have an executable that we can build and run. Next time we'll look into how to roll a new character and get them equipped before venturing into treasure dungeon.</p>
<p>ad astra!</p>
