
Procedurally Generating Books
This is a record of my day to day work on a project for the 2023 ProcJam game jam.
Day 0: preperations!
Acherons Archives: A PCG arcane bookshop
Inspired by a combination of games, Wilmott's Warehouse, Happy Humbles burger farm, Strange Horticulture etc I want to make a bookshop management prototype. But all the books are procedurally generated.
The bookshop gets deliveries of arcane books each evening
you have all night to arrange them on the shelves/tables etc.
At dawn the shop opens and characters come in requesting books
a book has various categories — the more of these you can match the better the pay. Firstly i need to define how the books will be generated, so Im going to define a few sets of parameters for this.
Potential book categories for generation
Publication Century:
1900s
1800s
1700s
1600s
Rarity:
1,2,3,4,5
Subjects: Books generally have 2 subjects
Oneiroscopy: dreams : closed eye, cloud, candle on plate
Astromancy: stars: stars, planets, constellations
Dendromancy: trees : trees/roots/acorns/seeds
Pyromancy: fire: fires, flames, embers, ovens
Necromancy: dead : bones, skulls, coffins
Umbramancy: shadows : shadows, cast by things
Lunascopy: moon: different moon shapes
Lampadomancy: light: lanterns, bulbs

I made a pinterest board for inspiration on how these books could look, But primarily I think they need to be color coded per subject and have a layout that allows for me to place and modify icons/patterns/imagery that also relates to the book subject/age/rarity
https://www.pinterest.co.uk/tomnullpointer/acheron-archives/
because the jam is only a week long, and I’m unsure of how much time I might get to focus on it I’m going to simplify the generation a little. Im intending to use pixel graphics and a sort of oldskool psx look for the game. This means I can hopefully produce the required parts with less hassle. I am probably going to do this by taking some icons i already own and processing them in photoshop to fit the required format i will use in the game.
Day 1: Setting things up
Unity setup
So Im going to be using Unity for this prototype, Ive actually been learning Unreal recently, but my familiarity and speed in unity is just too good for me to ignore for a jam. So I'm starting how i usually do, by defining rough data structures that I will need, singletons to manage access to data definition libraries and then I’m going to start making the gameobject prefabs I’ll need to build the 3d objects.
I tend to make use of enums and scriptable objects A LOT, when defining the parts for my systems, so I'm going to start there too.
Here's the class for defining a single book, its mostly enums.
public class C_BookDefClass
{
public string m_BookName;
public int m_BookRarity;
public E_Era m_BookEra;
public E_Subject m_BookSubjectA;
public E_Subject m_BookSubjectB;
public C_Book m_pC_Book;
}
This class will be built and filled by a “generator” script and then it will function as the basis for constructing the actual 3d book.
Since each book is going to have at least 2 subjects, I decided to make each subject have its own little scriptable object class that lists the associated colours and material that could be used to represent that subject — Ill expand this later, but I know I’ll need something like this for the 3d construction phase.
public class C_SO_SubjectResource : ScriptableObject
{
public E_Subject m_Subject;
public Material[] m_IconMats;
public Color[] m_Colors;
}
3D Book setup
The next thing I did was to try and decide on a 3d format for the books.
I know that I want to construct them in a sort of quilting 9-tile mosaic pattern. So i need a regular grid of sorts, and I want to be able to have guaranteed borders and a central divider that could be horizontal or vertical so a 5x5 grid looks like the minimum i can go for

Obviously this is a square! and the books are going to be rectangular, but I'm anticipating being able to just ratio up the Y axis and just work with each subsquare being a rectangle. Most books have a x to y of 1.5 so I'm going to aim for something like that.
The nest decision is what pixel res i want to use for the subcells, and the overall book. I need to base the full book on multiples of whatever the smallest dimension I can use for the subsquares (5x subsquares across), and I'm thinking 32x32 per cell, which makes the overall book 160 pixels. If I'm stretching by 1.5 height then 32 becomes 48, which is probably ok for pixel snapped rescaling.

Do i need the same sort of grid for the back of the books? I’m not sure yet, probably not. Books tend to have less elaborate back covers. But I’ll need something!
The actual subtile images I am making by taking icons i already bought from the asset store and then cropping/rescaling and tweaking to fit in a 32x32 format. I'm also going to be using just black and white icons to start with, again to save time, I can always add in gradients/more colours later.
So now I have a potential grid layout for the book cover, I want to focus on 2 elements in the generated design, ICONS and BORDERS. The icons will represent the books subject matter and the borders will frame the icons..
I'm going to focus on the borders first because I think they will be a bit harder to do..

First Problems!
Books are non-square, but if I want to be able to rotate the icons I'm using in the subsquares then I want those subsquares to be square! If I just scale the subcells (middle image) then the ration goes a bit off and things look stretched. So I tried to space out the actual anchors of each subcell (right image) which keeps the dimensions of each icon nice, but I get gaps in the borders and they don't meet the edges nicely. I have a few options — I can manually shift the border cells so that they hug the edges, I can make each cell a rectangle, or I can add another 2 rows of square cells in



In the end I'm opting for having 2 separate layers of decoration. One for the borders and another for the icons. This means I can save on some extra quads that would otherwise be taking up room. It also means I can potentially overlay layers.. I think this is a reasonable solution for now. I might add an extra cell into the margins if i feel I'm not getting enough value form the simpler setup


After some fiddling I've managed to get a basic generator up for the borders and background colours.
A while later I have added a similar generator 9 tile pattern setup for the icon area in the middle of the book. This is a set of reflected and rotated icons, which gives a specific geometric feel. I'm going to try and add some other alternative layout generators to not all the books have this centralised form.
Day 2: Landscape Layouts
Ok so I started working on a landscape layout, because I don’t want all the books to have the same symmetrical star-like patterns. I think this layout has to be simpler than the other one, it can handle less variation before it kind of breaks. The key thing here is to find enough icons to make the variations interesting based on the items picked. But I also want the icons to fit with the books subject. I also need the “star” icon layouts to fit with subject matter too. I think this is going to be tricky, just the challenge of finding/editing enough icons. The landscape ones I'm taking from the Isle Of Lore set I bought from the asset store a year or so ago. Hopefully there's enough in there for me to use for each subject.

So what subjects have I defined? Lets see them again — Its going to be tricky to find icons to match. Each subject needs to have a distinct colour way and a recognisable set of icons that links to its theme. Its tricky to get things that stand out but don't clash! As usual I will be changing a lot of the specifics on the fly, depending on what looks good and what icons I can pull together.
Oneiroscopy: dreams : closed eye, cloud, candle on plate — dark purple
Astromancy: stars: stars, planets, constellations — Light blue
Dendromancy: trees : trees/roots/acorns/seeds — Brown/green
Pyromancy: fire: fires, flames, embers, ovens — Orange
Necromancy: dead : bones, skulls, coffins — Dark red
Umbramancy: shadows : shadows, cast by things — Gray/ Dark blue
Lunascopy: moon: different moon shapes — Light grey yellow
Lampadomancy: light: lanterns, bulbs — Yellow
Here's a first pass at a landscape set for the pyromancy subject

And here's the necromancy set mixed with the pyro set

I’m starting to look at the star layout code again now, with a view to linking it to subject themes in the same way I did for the landscape layouts. Here's the WIP of the astromancy set

Ok Day 3
Lets get back to it!
I spent an hour or so finishing the astromancy star-layout set and making a pyromancy version

Now I can combine them for books that refer to both subjects.

I was going to move on to making the book titles but I thought I’d add the remaining 2 colour themes — Dendroscopy & Necroscopy. I still only have 4 of the potential 8 subjects, but I think it will have to do for now. I can always add the others later.


and a mix of these two

Title Generation
So now I've got the icon generators in a state I’m happy with, I started to work on the title generator. As usual, I thought about going really complex and implementing some proper language stuff. But in the end I've opted for a bunch of word tables, specific to each theme — and then a set of 5 or so different sentence constructors.
For example I have
“The adjective noun & the adjective noun”
“The adjective noun at/of/from the locationpartA LocationPartB”
PersonNameA PersonNameB notes/poems/essays on adjective noun”
And so on, with a bunch of smaller variants within and some grammar sense included so it will mostly make sense. I need to make word tables for all the themes (4 so far) and then run a lot of generations just to check there's no really bad combinations. Its making some nice evocative phrases already, but its also making some pretty funny ones. I think I will leave these in because they are still believable, even if they are pretty silly.

Tomorrow I really should try and get to the point where the books are actually 3d objects I can spawn in a game world!
Day 4
Today I really wanted to get started with the 3d aspect of the project. But First I felt I needed to fill in the remaining book theme word tables. That meant mainly finding Astromancy and Necromancy adjectives/nouns.
Here's an example of the sort of material I'm using here
Necromancy Nouns
corpse, cadaver, carcass, remains, body, relic, corpse, skeleton, corpus, deceased dog, carrion bird, dead body, ash pile, reliquiae, relic, shell, remnant, debris, hulk, shrine, dead animal, human remains, dead man, bonepile, zombie,skull, femur, ulna, nameless corpse, empty shell, Urn, Tombstone, Crypt, Charnel Pit, Crematorium, Morgue, Mortuary, Sacrifice, Plague Pit, shambler, wraith, phantom, ghost, ghoul, golem, beat, raven, crow, reaper, coffin, sarcophagus, grave, shroud
Necromancy Adjectives
departed, deceased, late, lifeless, perished, fallen, inanimate, demised, lost, insensate, insentient, slain, slaughtered, breathless, inert, killed, murdered, still, cold, exanimate, lamented, unanimated, wasted, asleep, cadaverous, mortified, spiritless, buried, liquidated, silent, doomed, perishing, moribund, mortal, poisoned, near-death, fading, sinking, terminal, ghostly, declining, decaying, failing, foundering, withering, waning, crumbling, atrophying, sinking, declining, gravebound, disintegrating, fey, succumbing, collapsing, fated, passing, half-dead, expiring, dire
Along with my previous 5+ sentence construction types this gives me a decent range of results. I’d like to improve it later, but its certainly fine for now.

So the next step was to make the books properly 3D, I just did a bunch of edits to the model and added some pages and a spine. I'm probably going to add some more info to these later, but again they are ok for now.

So now I can generate these things in a 3d space. I spent a few mins mocking up a quick 3d environment to try it out…
I spent most of the afternoon making the player able to carry, rotate, drop and throw the books. You can also put them on a shelf and it will try to snap the placed item onto the shelf next to its leftmost neighbour. It needs some refinement and I should probably do some different versions for table layouts or similar, but its probably ok for now. Books also have the title on their spine now, and they come is slightly varying sizes.


Day 5
So today I spent most of the time laying out the shop, putting shelves in, and creating a sort of delivery portal where the books will arrive. I've put in a mystical grandfather clock which shows the current in-game time. Each time it rolls around to dusk the next batch of books are delivered.

And when dawn arrives, the shops shutters roll up and customers appear. I haven’t got the customers making any requests yet though.

Of course I was advised that as this is a magic bookshop it needs a cat sitting by a roaring fire, so I wasted an hour or so making this..

Finally, I decided to stress test the generator, and although it had no problem creating 1700 books , when they are all piled up in one place the game framerate crawls to like 15fps. I don't think you'd ever have this many books and when they are actually shelved the FPS is a lot smoother. I suppose I could put a cap on deliveries once you hit a maximum capacity of some sort.

This is officially the end of my mon-friday sprint on this jam. There's a few days over the weekend before the official end date, but I'm not sure how much work I will put into the prototype before the closing date of next Monday. However I’d really like to finish enough to make it playable, and if its fun I’d like to expand on it at a later date.







