Guidebook

Guidebook

6M Downloads

[Suggestion] File Fragmentation

Shazuli opened this issue ยท 7 comments

commented

Hi!

This isn't part of HTML and is more related to JavaScript, but it would be nice to have a way to fragment a book's chapters/pages into different documents. I have written about three chapters now and have over 300 lines of code, its kind of getting ridiculous.
My suggestion is that when you use the include tag, it will if it finds chapter/section/p tags add that into the main document as an element.

From this:
<section>
	<title>Hardware</title>
	<p>Like all good computers, we are going to need a box to store all components.</p>
	<big_recipe>
		<stack item="minecraft:iron_ingot"/>
		<stack item="opencomputers:material" meta="7"/>
		<stack item="minecraft:iron_ingot"/>

		<stack item="minecraft:iron_bars"/>
		<stack ore="chestWood"/>
		<stack item="minecraft:iron_bars"/>

		<stack item="minecraft:iron_ingot"/>
		<stack item="opencomputers:material" meta="4"/>
		<stack item="minecraft:iron_ingot"/>


		<stack item="opencomputers:case1"/>
	</big_recipe>
</section>
To this:
<include ref="gbook:xml/hardware.xml" />
This could be beneficial when you have to repeat certain paragraphs or long codes. If this is already part of the mod and I missed it, let me apologize in advance.
commented

Technically you could use a template library for that... except templates generate panels so probably not what you want...

I guess I can make the <include> tag more flexible... but, why would you need to repeat entire paragraphs without changing their text at all? It seems strange to me that someone would need to include the same exact contents more than once...

Side note: you can load recipes from the recipe registry, by name or by output item, meaning you don't have to hardcode them using the templates:

<recipe type="gbook:crafting" key="minecraft:iron_pickaxe"/>
<recipe type="gbook:crafting" key="minecraft:quartz_block"/>
<recipe type="shaped">
    <recipe.result>
        <stack item="minecraft:comparator"/>
    </recipe.result>
</recipe>

I really need to work on improving the documentation... :P

commented

When I try to use the recipe tag to show a recipe from a different mod, my game crashes. Vanilla shaped recipes work fine, but whenever I try to, for example, show a recipe from OpenComputers my game instantly crashes after I have reloaded the resources and won't boot up again until I've reverted the changes.

https://paste.dimdev.org/akesemupor.txt

commented

Well that is a bug no one told me about and I would have liked to know earlier.... looking into it... :P

commented

Update: Your other method of doing a recipe doesn't crash the game:

<recipe type="shaped">
    <recipe.result>
        <stack item="opencomputers:screen1"/>
    </recipe.result>
</recipe>

Trying to do a template for shaped recipes:

<template id="shaped">
	<recipe type="shaped">
		<recipe.result>
			<stack item='<element index="0">'/>
		</recipe.result>
	</recipe>
</template>
commented

Uhm... no that's not how XML works... you can't just insert an element inside a string.

I don't support replacing attributes in a template, only tags. So you could do instead:

<template id="shaped">
  <recipe type="shaped">
    <recipe.result>
      <element index="0"/>
    </recipe.result>
  </recipe>
</template>

Which would be used like

<shaped>
  <stack item="opencomputers:screen1"/>
</shaped>

Which is not that much shorter than just using the recipe tag directly...

commented

Hmm, my game crashes again now that I use your code. It works if I don't call it but when I do it crashes when I reload the resources.

https://paste.dimdev.org/kaxetosoxe.txt

commented

Yes there's some bug in my code, I'll take a look as soon as I can...