Import custom books (experimental)

Discuss modding questions and implementation details.
User avatar
TheLacus
Posts: 958
Joined: Wed Sep 14, 2016 6:22 pm
Contact:

Import custom books (experimental)

Post by TheLacus » Tue Jul 30, 2019 8:09 am

Recently relased alpha build introduces support for custom books, in addition to replacement for classic books which was already available. This feature is still considered experimental but is provided as opt-in to receive early feedback from interested mod creators. For general informations on books modding see modding/books.

How to enable
Open ini setting file, search [Experimental] section and set

Code: Select all

CustomBooksImport=True
How to import from loose files
  1. Place a new book file with .TXT extension inside StreamingAssets/Books. Example: StreamingAssets/Books/ExampleBook.TXT.
  2. Create a json file inside StreamingAssets/Books/Mapping. Example: StreamingAssets/Books/Mapping/ExampleBooksPack.json.
    This file must contain an array of objects, one for each book that is to be announced to the game.

    Code: Select all

    [{
       "Name": "ExampleBook.TXT",
       "Title": "An Example Book"
       "ID": 1531909675
    }]
    
    Name is the filename without extension.
    Title is a readable name for the book, shown in game. The reason to have it here is to access it without loading the entire book resource.
    ID An unique ID for the book between 1 and 2147483647 (generate with google).
    IsUnique If true this book is not found inside random loots or bookshelves and must be made available directly by mods.
    WhenVarSet Book is available only when this global variable is set.
How to import from mods
Custom books can be provided from mods (.dfmod) simulating loose files structure. Specifically, place mapping json files inside a directory that ends with Books/Mapping.
For example, you should have something like this:

Code: Select all

<root>/ReadMe.txt
<root>/ExampleMod.dfmod.json
<root>/modsettings.json
<root>/Books/ExampleBook.TXT
<root>/Books/Mapping/ExampleBooksPack.json
What to expect
  • Custom books can be read from booshelves.
  • Custom books can be found inside random loots and added to inventory as items. If mod provider is removed, books inside inventory become unreadable claiming to be ruined.
  • Custom books can be made available by mods

    Code: Select all

    GameManager.Instance.PlayerEntity.Items.AddItem(ItemBuilder.CreateBook("ExampleBook"));
    
Attachments
CustomBookInGame.png
CustomBookInGame.png (142.48 KiB) Viewed 2192 times
CustomBookEditor.png
CustomBookEditor.png (36.38 KiB) Viewed 2192 times
Mod System documentation - Learn how to create mods for Daggerfall Unity.
Modder Discussion - General help and discussion for the mod system.
Github Issues - Submit a bug report for the game, including the mod system.

azmanian
Posts: 12
Joined: Tue Aug 13, 2019 12:59 am

Re: Import custom books (experimental)

Post by azmanian » Tue Aug 13, 2019 11:44 am

*chronicling the histories of the Illiac's noble families intensifies* :D

BansheeXYZ
Posts: 508
Joined: Fri Oct 23, 2015 8:19 pm

Re: Import custom books (experimental)

Post by BansheeXYZ » Tue Aug 13, 2019 12:49 pm

I'm interested, except... if you play near 1080p (and most people do), it's kinda hard to read a whole book in what is essentially a size 36 yellow font. 5x scaling only looks good in a twitter thumbnail. So it'd be great to have scaling options for the old ui for enhanced readability. Doom is a 320x200 game as well. Play gzdoom you'll see that not only can choose your own scalings, the default is "adaptive" which makes sure the old HUD/messages doesn't get scaled to 5x just because you bumped the resolution 5x.

User avatar
Hazelnut
Posts: 1587
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Import custom books (experimental)

Post by Hazelnut » Sun Sep 08, 2019 6:02 pm

I'd like to add a book for the Archaeologists guild with some details and locations of guild halls. When is this feature likely to move from experimental?

User avatar
TheLacus
Posts: 958
Joined: Wed Sep 14, 2016 6:22 pm
Contact:

Re: Import custom books (experimental)

Post by TheLacus » Sun Sep 08, 2019 7:06 pm

Hazelnut wrote:
Sun Sep 08, 2019 6:02 pm
I'd like to add a book for the Archaeologists guild with some details and locations of guild halls. When is this feature likely to move from experimental?
I want to be cautious and avoid changes to core game before confirmation that there are no regressions. It works fine in my tests so i'm happy to enable this feature for all after someone actually release a book and no bugs are found.
Mod System documentation - Learn how to create mods for Daggerfall Unity.
Modder Discussion - General help and discussion for the mod system.
Github Issues - Submit a bug report for the game, including the mod system.

User avatar
Hazelnut
Posts: 1587
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Import custom books (experimental)

Post by Hazelnut » Sun Sep 08, 2019 7:27 pm

If I put a book into the mod and the books setting is not enabled, will that possibly cause issues? That's my concern I suppose.

User avatar
TheLacus
Posts: 958
Joined: Wed Sep 14, 2016 6:22 pm
Contact:

Re: Import custom books (experimental)

Post by TheLacus » Mon Sep 09, 2019 12:16 pm

Hazelnut wrote:
Sun Sep 08, 2019 7:27 pm
If I put a book into the mod and the books setting is not enabled, will that possibly cause issues? That's my concern I suppose.
No, it should be fine ;)
Mod System documentation - Learn how to create mods for Daggerfall Unity.
Modder Discussion - General help and discussion for the mod system.
Github Issues - Submit a bug report for the game, including the mod system.

User avatar
Hazelnut
Posts: 1587
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Import custom books (experimental)

Post by Hazelnut » Mon Sep 09, 2019 12:26 pm

Great. Will do this in a couple of weeks when I get back. Should hopefully be a good test case.

User avatar
Uncanny_Valley
Posts: 138
Joined: Mon Mar 23, 2015 5:47 pm

Re: Import custom books (experimental)

Post by Uncanny_Valley » Sat Sep 28, 2019 1:48 am

Currently this doesn't work.

In DaggerfallWorkshop.Game.Items.ItemBuilder.CreateBook(string fileName), it starts by adding a filename extension to the name, which will result that it wont find the book in BookMappingEntries (where the name is stored without extension).

You do however want to add the file extension in BookReplacement.TryImportBook(string name, BookFile book), probably after the DaggerfallUnity.Settings.AssetInjection check.

After these changes, you can make the book appear in your inventory. using

Code: Select all

"GameManager.Instance.PlayerEntity.Items.AddItem(ItemBuilder.CreateBook("ExampleBook"));" 
But the doesn't get the correct price and it doesn't set the name of the book, it only becomes "Book by unknown Author".

And lastly, if you have a mod that adds a book. It will do so even if the mod is de-activated in the mod loader.

User avatar
TheLacus
Posts: 958
Joined: Wed Sep 14, 2016 6:22 pm
Contact:

Re: Import custom books (experimental)

Post by TheLacus » Sat Sep 28, 2019 1:43 pm

Uncanny_Valley wrote:
Sat Sep 28, 2019 1:48 am
Currently this doesn't work.

In DaggerfallWorkshop.Game.Items.ItemBuilder.CreateBook(string fileName), it starts by adding a filename extension to the name, which will result that it wont find the book in BookMappingEntries (where the name is stored without extension).

You do however want to add the file extension in BookReplacement.TryImportBook(string name, BookFile book), probably after the DaggerfallUnity.Settings.AssetInjection check.

After these changes, you can make the book appear in your inventory. using

Code: Select all

"GameManager.Instance.PlayerEntity.Items.AddItem(ItemBuilder.CreateBook("ExampleBook"));" 
But the doesn't get the correct price and it doesn't set the name of the book, it only becomes "Book by unknown Author".

And lastly, if you have a mod that adds a book. It will do so even if the mod is de-activated in the mod loader.
It wasn't needed to provide the extension at first, but i rethinked that because one day we might want to support readable formats like json in addition to format used by classic books, or at least i believe Intekarma suggested that possibility once.
I forgot to update the guide above, sorry for that. If you make a mapping file with this content, custom book is imported automatically and available from bookshelves unless IsUnique flag is set.

Code: Select all

[
    {
        "Name": "ExampleBook.TXT",
        "Title": "An Example Book",
        "ID": 1531909675
    }
]
Mod System documentation - Learn how to create mods for Daggerfall Unity.
Modder Discussion - General help and discussion for the mod system.
Github Issues - Submit a bug report for the game, including the mod system.

Post Reply