diff --git a/docs/index.adoc b/docs/index.adoc index 3e12a95..f51cd00 100644 --- a/docs/index.adoc +++ b/docs/index.adoc @@ -310,6 +310,14 @@ Include several of these somehwere in your book and instruct the player to close image::images/dicetable.png[align="center"] +[#dicefooter] +=== Dice Footer + +Add the `:asciihero-dice-footer: ` attribute to generate and render two dice showing random numbers in the footer of every page containing a segment. +The `` is used as the seed for generating the random dice numbers. + +image::images/dicefooter.png[align="center"] + == Exporting Exporting means to convert your AsciiHero document and turn it into something that is appropriate for reading by anyone. @@ -481,31 +489,41 @@ If you are new to both, it's recommended to use the link:https://docs.asciidocto |Name |Allowable Values |Modifiable |API/CLI Only |Notes |`asciihero-combat-attributes` -| _comma-separated list of attributes_ -| Yes -| No -| List of attributes for enemies when rendering a combat block. +|_comma-separated list of attributes_ +|Yes +|No +|List of attributes for enemies when rendering a combat block. + +|`asciihero-dice-footer` +|`` +|Yes +|No +|Add a pair of dice to the footer of every page containing segments. +The `` is used as the seed for the random dice. +See <> for more information. |`asciihero-shuffle-algorithm` |`none` + `random` |Yes |No -|Algorithm to use when shuffling the segments in the document. See <> for more information. +|Algorithm to use when shuffling the segments in the document. +See <> for more information. |`asciihero-shuffle-seed` |`` + `` |Yes |No -|Seed to use for the random shuffle. Using the same seed guarantees the same order every time you render your gamebook. +|Seed to use for the random shuffle. +Using the same seed guarantees the same order every time you render your gamebook. |`asciihero-segment-title` |`title` + `number` -| Yes -| No -| Sets whether to show segment as titles (for debugging), or number (default). +|Yes +|No +|Sets whether to show segment as titles (for debugging), or number (default). |=== [#macros] diff --git a/examples/dice_footer/dice_footer.adoc b/examples/dice_footer/dice_footer.adoc new file mode 100644 index 0000000..fd54c01 --- /dev/null +++ b/examples/dice_footer/dice_footer.adoc @@ -0,0 +1,68 @@ += Dice Footer +:doctype: book +:asciihero-shuffle-style: random +:asciihero-shuffle-seed: 1234 +:icons: font +:asciihero-dice-footer: 1234 + +== Introduction + +If you set `:asciihero-dice-footer: true` it will add 2 random `d6` dice to the footer of each page. +Your readers can use this in a pinch if they don't have any dice handy! + +[.gameplay] +== Gameplay + +[.segment] +=== segment_1 + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque interdum mauris quam, ut congue magna imperdiet at. Nunc ipsum turpis, pretium et congue vel, dictum eu ex. Integer tristique posuere ipsum, vel mattis nisi eleifend nec. Vivamus vitae sem ligula. Fusce ac nunc et massa viverra finibus. Vestibulum molestie quam sit amet pretium fermentum. Nunc posuere rutrum dolor eu tempus. Donec arcu ligula, consequat a enim nec, tincidunt hendrerit ipsum. Morbi quis metus leo. Cras a neque interdum, convallis ligula ut, convallis lacus. Phasellus efficitur tellus id orci sagittis, iaculis elementum ligula facilisis. Suspendisse blandit malesuada tellus, nec rutrum orci euismod sed. Integer dignissim eu arcu id ornare. + +[.segment] +=== segment_2 + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque interdum mauris quam, ut congue magna imperdiet at. Nunc ipsum turpis, pretium et congue vel, dictum eu ex. Integer tristique posuere ipsum, vel mattis nisi eleifend nec. Vivamus vitae sem ligula. Fusce ac nunc et massa viverra finibus. Vestibulum molestie quam sit amet pretium fermentum. Nunc posuere rutrum dolor eu tempus. Donec arcu ligula, consequat a enim nec, tincidunt hendrerit ipsum. Morbi quis metus leo. Cras a neque interdum, convallis ligula ut, convallis lacus. Phasellus efficitur tellus id orci sagittis, iaculis elementum ligula facilisis. Suspendisse blandit malesuada tellus, nec rutrum orci euismod sed. Integer dignissim eu arcu id ornare. + +[.segment] +=== segment_3 + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque interdum mauris quam, ut congue magna imperdiet at. Nunc ipsum turpis, pretium et congue vel, dictum eu ex. Integer tristique posuere ipsum, vel mattis nisi eleifend nec. Vivamus vitae sem ligula. Fusce ac nunc et massa viverra finibus. Vestibulum molestie quam sit amet pretium fermentum. Nunc posuere rutrum dolor eu tempus. Donec arcu ligula, consequat a enim nec, tincidunt hendrerit ipsum. Morbi quis metus leo. Cras a neque interdum, convallis ligula ut, convallis lacus. Phasellus efficitur tellus id orci sagittis, iaculis elementum ligula facilisis. Suspendisse blandit malesuada tellus, nec rutrum orci euismod sed. Integer dignissim eu arcu id ornare. + +[.segment] +=== segment_4 + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque interdum mauris quam, ut congue magna imperdiet at. Nunc ipsum turpis, pretium et congue vel, dictum eu ex. Integer tristique posuere ipsum, vel mattis nisi eleifend nec. Vivamus vitae sem ligula. Fusce ac nunc et massa viverra finibus. Vestibulum molestie quam sit amet pretium fermentum. Nunc posuere rutrum dolor eu tempus. Donec arcu ligula, consequat a enim nec, tincidunt hendrerit ipsum. Morbi quis metus leo. Cras a neque interdum, convallis ligula ut, convallis lacus. Phasellus efficitur tellus id orci sagittis, iaculis elementum ligula facilisis. Suspendisse blandit malesuada tellus, nec rutrum orci euismod sed. Integer dignissim eu arcu id ornare. + +[.segment] +=== segment_5 + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque interdum mauris quam, ut congue magna imperdiet at. Nunc ipsum turpis, pretium et congue vel, dictum eu ex. Integer tristique posuere ipsum, vel mattis nisi eleifend nec. Vivamus vitae sem ligula. Fusce ac nunc et massa viverra finibus. Vestibulum molestie quam sit amet pretium fermentum. Nunc posuere rutrum dolor eu tempus. Donec arcu ligula, consequat a enim nec, tincidunt hendrerit ipsum. Morbi quis metus leo. Cras a neque interdum, convallis ligula ut, convallis lacus. Phasellus efficitur tellus id orci sagittis, iaculis elementum ligula facilisis. Suspendisse blandit malesuada tellus, nec rutrum orci euismod sed. Integer dignissim eu arcu id ornare. + +[.segment] +=== segment_6 + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque interdum mauris quam, ut congue magna imperdiet at. Nunc ipsum turpis, pretium et congue vel, dictum eu ex. Integer tristique posuere ipsum, vel mattis nisi eleifend nec. Vivamus vitae sem ligula. Fusce ac nunc et massa viverra finibus. Vestibulum molestie quam sit amet pretium fermentum. Nunc posuere rutrum dolor eu tempus. Donec arcu ligula, consequat a enim nec, tincidunt hendrerit ipsum. Morbi quis metus leo. Cras a neque interdum, convallis ligula ut, convallis lacus. Phasellus efficitur tellus id orci sagittis, iaculis elementum ligula facilisis. Suspendisse blandit malesuada tellus, nec rutrum orci euismod sed. Integer dignissim eu arcu id ornare. + +[.segment] +=== segment_7 + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque interdum mauris quam, ut congue magna imperdiet at. Nunc ipsum turpis, pretium et congue vel, dictum eu ex. Integer tristique posuere ipsum, vel mattis nisi eleifend nec. Vivamus vitae sem ligula. Fusce ac nunc et massa viverra finibus. Vestibulum molestie quam sit amet pretium fermentum. Nunc posuere rutrum dolor eu tempus. Donec arcu ligula, consequat a enim nec, tincidunt hendrerit ipsum. Morbi quis metus leo. Cras a neque interdum, convallis ligula ut, convallis lacus. Phasellus efficitur tellus id orci sagittis, iaculis elementum ligula facilisis. Suspendisse blandit malesuada tellus, nec rutrum orci euismod sed. Integer dignissim eu arcu id ornare. + +[.segment] +=== segment_8 + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque interdum mauris quam, ut congue magna imperdiet at. Nunc ipsum turpis, pretium et congue vel, dictum eu ex. Integer tristique posuere ipsum, vel mattis nisi eleifend nec. Vivamus vitae sem ligula. Fusce ac nunc et massa viverra finibus. Vestibulum molestie quam sit amet pretium fermentum. Nunc posuere rutrum dolor eu tempus. Donec arcu ligula, consequat a enim nec, tincidunt hendrerit ipsum. Morbi quis metus leo. Cras a neque interdum, convallis ligula ut, convallis lacus. Phasellus efficitur tellus id orci sagittis, iaculis elementum ligula facilisis. Suspendisse blandit malesuada tellus, nec rutrum orci euismod sed. Integer dignissim eu arcu id ornare. + +[.segment] +=== segment_9 + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque interdum mauris quam, ut congue magna imperdiet at. Nunc ipsum turpis, pretium et congue vel, dictum eu ex. Integer tristique posuere ipsum, vel mattis nisi eleifend nec. Vivamus vitae sem ligula. Fusce ac nunc et massa viverra finibus. Vestibulum molestie quam sit amet pretium fermentum. Nunc posuere rutrum dolor eu tempus. Donec arcu ligula, consequat a enim nec, tincidunt hendrerit ipsum. Morbi quis metus leo. Cras a neque interdum, convallis ligula ut, convallis lacus. Phasellus efficitur tellus id orci sagittis, iaculis elementum ligula facilisis. Suspendisse blandit malesuada tellus, nec rutrum orci euismod sed. Integer dignissim eu arcu id ornare. + +[.segment] +=== segment_10 + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque interdum mauris quam, ut congue magna imperdiet at. Nunc ipsum turpis, pretium et congue vel, dictum eu ex. Integer tristique posuere ipsum, vel mattis nisi eleifend nec. Vivamus vitae sem ligula. Fusce ac nunc et massa viverra finibus. Vestibulum molestie quam sit amet pretium fermentum. Nunc posuere rutrum dolor eu tempus. Donec arcu ligula, consequat a enim nec, tincidunt hendrerit ipsum. Morbi quis metus leo. Cras a neque interdum, convallis ligula ut, convallis lacus. Phasellus efficitur tellus id orci sagittis, iaculis elementum ligula facilisis. Suspendisse blandit malesuada tellus, nec rutrum orci euismod sed. Integer dignissim eu arcu id ornare. + +== The End + +TODO diff --git a/examples/dice_footer/dice_footer.pdf b/examples/dice_footer/dice_footer.pdf new file mode 100644 index 0000000..60f6888 Binary files /dev/null and b/examples/dice_footer/dice_footer.pdf differ diff --git a/src/extensions.js b/src/extensions.js index f732e4c..080722f 100644 --- a/src/extensions.js +++ b/src/extensions.js @@ -1,5 +1,47 @@ const seedrandom = require('seedrandom') +// diceFooterProcessor processes all sections to add a hidden section with die +// numbers. The last set of hidden dice sections are then shown in the footer +// of the page. +function diceFooterProcessor () { + const self = this + + const dice = [ + "", + "icon:dice-one[]", + "icon:dice-two[]", + "icon:dice-three[]", + "icon:dice-four[]", + "icon:dice-five[]", + "icon:dice-six[]", + ] + + self.process(function (doc) { + if (!doc.hasAttribute('asciihero-dice-footer')) { + return + } + + const seed = doc.getAttribute('asciihero-dice-footer') + const rng = seedrandom(seed) + + const segmentNodes = doc.findBy({ role: 'segment' }) + + let sectionIndex = 0 + for (const index in segmentNodes) { + const node = segmentNodes[index] + + // NOTE: We probably should probably just rely on default autoId behaviour here... + if (node.getId().startsWith('_')) { + node.setId(node.title) + } + + const rndInt1 = Math.floor(rng() * 6) + 1 + const rndInt2 = Math.floor(rng() * 6) + 1 + self.parseContent(node, `[.footer-die]#${dice[rndInt1]} ${dice[rndInt2]}#`) + } + }) +} + // segmentTreeProcessor processes all sections with the `segment` style by // assigning them the right IDs and seting a numeric title. function segmentTreeProcessor () { @@ -341,5 +383,6 @@ module.exports.register = function (registry) { this.treeProcessor(segmentTreeProcessor) this.treeProcessor(choicesTreeProcessor) this.treeProcessor(shuffleTreeProcessor) + this.treeProcessor(diceFooterProcessor) }) } diff --git a/src/styles/base.css b/src/styles/base.css index 0d85139..dc40144 100644 --- a/src/styles/base.css +++ b/src/styles/base.css @@ -133,6 +133,30 @@ table.dicetable td p { width: 32px; } +/******************************************************************************* +* Dice Footer + ******************************************************************************/ +.footer-die { + display: none; + font-size: 1.5em; +} + +.footer-die { + position: running(footer-die); +} + +@page gameplay :right { + @bottom-center { + content: element(footer-die, first) + } +} + +@page gameplay :left { + @bottom-center { + content: element(footer-die, first) + } +} + /******************************************************************************* * Counter ******************************************************************************/