ShardsOfPower/book_of_faces.rb

259 lines
12 KiB
Ruby
Raw Normal View History

2019-05-27 06:24:03 -04:00
require "prawn"
require "pry"
2019-05-27 15:02:07 -04:00
require_relative "spell"
require_relative "spells"
require_relative "primitive_adds"
2019-05-27 06:24:03 -04:00
puts "Book of Faces PDF generator"
class BookOfFaces
FONT_SIZE_CHAPTER = 48
FONT_SIZE_SECTION = 24
2019-05-27 15:02:07 -04:00
FONT_SIZE_SUBSECTION = 18
2019-05-27 15:20:48 -04:00
FONT_SIZE_BODY = 10
2019-05-27 06:24:03 -04:00
2019-05-27 15:02:07 -04:00
attr_accessor :pdf, :number_name, :chapter_name, :chapter_title, :section_name, :spells
2019-05-27 06:24:03 -04:00
def start_chapter(num, name)
@number_name = num
@chapter_name = name
@chapter_title = "Chapter #{number_name}: #{chapter_name}"
puts "Starting #{chapter_title}"
2019-05-27 15:02:07 -04:00
pdf.start_new_page
2019-05-27 06:24:03 -04:00
pdf.outline.update do
puts "\tAdding #{@book_of_faces.chapter_title} on page #{page_number}"
section(@book_of_faces.chapter_title, :destination => page_number)
end
puts "\tSetting font size"
pdf.font_size FONT_SIZE_CHAPTER
pdf.font "Abess"
puts "\tPrinting chapter to document"
pdf.text "Chapter #{number_name}: #{chapter_name}"
puts "\tRestoring body text"
pdf.font "Goudy"
pdf.font_size FONT_SIZE_BODY
end
def start_section(section_name)
2019-05-27 15:20:48 -04:00
puts "Beginning section #{section_name}: "
2019-05-27 06:24:03 -04:00
@section_name = section_name
pdf.outline.add_subsection_to(chapter_title) do
@pdf.outline.section section_name, :destination => @pdf.page_number
end
puts "\tSetting font size"
pdf.font_size FONT_SIZE_SECTION
pdf.text section_name
puts "\tRestoring body text"
pdf.font_size FONT_SIZE_BODY
pdf.font "Goudy"
end
def roll_results(dramatic_failure:, failure:, success:, exceptional_success:)
pdf.font_size FONT_SIZE_BODY
pdf.font "Goudy"
pdf.text "Roll Results", :style => :bold
pdf.formatted_text [
{ :text => "Dramatic Failure: ", :styles => [:bold] },
{ :text => dramatic_failure }
]
pdf.formatted_text [
{ :text => "Failure: ", :styles => [:bold] },
{ :text => failure }
]
pdf.formatted_text [
{ :text => "Success: ", :styles => [:bold] },
{ :text => success }
]
pdf.formatted_text [
{ :text => "Exceptional Success: ", :styles => [:bold] },
{ :text => exceptional_success }
]
end
def generate
2019-05-27 15:02:07 -04:00
puts "Parsing spells..."
@spells = Spell.spells
puts "Creating PDF object..."
2019-05-27 06:24:03 -04:00
@pdf = Prawn::Document.new(:margin => 0)
2019-05-27 15:20:48 -04:00
pdf.default_leading 5
2019-05-27 06:24:03 -04:00
pdf.font_families.update(
"Goudy" => {
:normal => "goudy.ttf",
:bold => "goudy-bold.ttf",
:italic => "goudy-italic.ttf"
},
"Abess" => {
:normal => "abess.ttf"
},
"Lilith" => {
:normal => "lilith.ttf"
}
)
pdf.outline.instance_variable_set(:@book_of_faces, self)
puts "Importing cover..."
pdf.image("cover.png", :width => 612, :height => 792)
puts "Printing inner cover..."
pdf.start_new_page(:margin => 75)
pdf.font "Abess"
pdf.font_size 72
pdf.text "The Book\nOf Faces", :align => :center
puts "\tBook Of Faces big text..."
pdf.font "Goudy"
pdf.font_size 36
pdf.text "\nA grimoire of spells, Gifts, Disciplines, Contracts, and other anomalies, with anecdotes and exposition from their in-game authors\n\n", :align => :center
puts "\tDescription..."
pdf.font_size 24
pdf.text "Written by members of the /cofd/ Discord, edited by NEETzsche", :align => :center
puts "\tMain credit..."
pdf.outline.define do
end
start_chapter "One", "Introduction"
start_section "Judging It By Its Cover"
pdf.text "This tome is an Artifact-grimoire with certain special properties. It easily weighs about thirty or so pounds from all of the paper within it. It is leather bound with a very visible face on its cover and no title listed; each time people look away and take another look at it, the face on it changes. Upon opening it, it appears anachronistic and mixed. Most of the pages are merely old paper, but some of them are papyrus scrolls that have been glued into it, while others are cuneiform tablets, and some are even touch screens. Upon inspection of this tome, it's clear it should be much bigger, and much heavier, than it actually is. A quill pen is attached to it by a string. Even though a quill pen normally would only be used with ink-on-paper, it appears to also work as a tool to etch into the cuneiform tablets, as a stylus for the touch screens, and whatever else someone manages to find in this tome. Its contents change upon future viewings, making it feel like an endless sea."
start_section "Exploring Its Contents"
pdf.text "If one were to open it up and start reading, the content would make no sense. It simply cannot be understood. No amount of knowledge on High Speech, First Tongue, or whatever other language of supernatural origin seems to decipher it. However, he who possesses this book may inscribe their meaningful experiences into it. Mages can Scribe Grimoire (Mage: the Awakening, p. 166) into it, except not only is it Lasting, but they may also place their improvised spells in it as though they were Rotes. They may also write their anecdotes, philosophy and experiences within this book, as long as they are sufficiently meaningful. Other supernatural entities like vampires or werewolves may list in explicit detail their Gifts, Disciplines, Contracts or other traits."
pdf.text "This action requires an hour of soul-searching, a successful roll on their equivalent Integrity rating, and a Beat. This Beat is consumed by the book; that Beat is gone forever."
roll_results(
:dramatic_failure => "Same as failure, but in addition to this, the Book of Faces is offended at the player's arrogance. It emits a piercing roar that deals one point of Resistant aggravated damage to everyone in the room.",
:failure => "The person attempting it gave the Book Of Faces dross. It gave it crap, nonsense. Emo scribblings and cockamamie shitposts. They do not get their Beat back; turns out, their life experience wasn't that useful after all. They may try again without penalty, but must sacrifice another Beat.",
:success => "The content the character submitted is of actual value, and it is accepted, incorporated into its pages.\n\nIf the roll succeeds, for the remainder of the scene, the character may at his discretion learn any of the Rotes (as long as they have the Arcanum prerequisites, and even if they were Improvised spells when they were put into the Book of Faces) and Disciplines, may have Gifts conferred upon them, and may enter into Contracts found therein. In mechanics terms, the character reads the Book of Faces extensively for a number of hours and spends their Experiences however they desire, focusing on the things they find most interesting. If they want to use the Book of Faces again in the future, they must make a second roll.",
:exceptional_success => "The willworker not only gives it valuable information, but demonstrates they are particularly capable of learning. They gain a full Experience point, but it can only be spent learning things from the Book of Faces"
)
2019-05-31 06:53:56 -04:00
start_section "Keeping It In One's Possession"
pdf.text "While the book might be extremely useful, and people would naturally want to maintain control over it for this reason, it also seems to have a mind of its own. The book has a magical habit of simply up and <i>disappearing</i>. Putting it on a bookshelf, in one's backpack, or even in a locked safe, doesn't seem to suffice to ensure it stays put. Both mundane and supernatural means of keeping it one's possession have a habit of failing. If left alone for very long, it just poofs, and finds its way into somebody else's possession.", :inline_format => true
pdf.text "After each use, whenever a person leaves the Book of Faces unattended, that person rolls Perception (Wits + Composure)."
roll_results(
:dramatic_failure => "Not only is the book lost, but its contents forgotten. It's like the previous owner never learned a thing. No Experience refund is issued. This is an exception to the normal Sanctity of Merits (or Sanctity of Anything) rule.",
:failure => "The Book of Faces disappears from this person's possession, to be found by somebody else later.",
:success => "The Book of Faces remains in the person's possession until its next use.",
:exceptional_success => "Not only does the Book of Faces remain in the person's possession, but their input is deemed particularly valuable. Their next use of the Book automatically succeeds."
)
2019-05-27 15:02:07 -04:00
start_chapter("Two", "Spells")
spells.group_by(&:primary_arcanum).sort_by { |arcanum, spells| arcanum }.to_h.each do |arcanum, arcanum_spells|
arcanum_name = arcanum.to_s.titleize
puts "Compiling spells for #{arcanum_name}..."
start_section("#{arcanum_name} Spells")
arcanum_spells.group_by(&arcanum).sort_by { |rating, spells| rating }.to_h.each do |rating, rating_spells|
rating_title = "#{rating.to_dots} #{Spell::RANKS[rating - 1]} of #{arcanum_name}"
puts "\tCompiling #{rating_title} spells..."
pdf.outline.add_subsection_to("#{arcanum_name} Spells") do
@pdf.outline.section rating_title, :destination => @pdf.page_number
end
2019-05-27 15:20:48 -04:00
pdf.font_size FONT_SIZE_SECTION
2019-05-27 15:02:07 -04:00
pdf.text rating_title
rating_spells.sort_by { |spell| spell.name }.each do |spell|
puts "\t\tCompiling #{spell.full_title} by #{spell.authors.join(', ')}"
2019-05-31 05:33:55 -04:00
pdf.outline.add_subsection_to(rating_title) do
@pdf.outline.section spell.full_title, :destination => @pdf.page_number
end
2019-05-27 15:02:07 -04:00
2019-05-27 15:20:48 -04:00
spell_ary = [{:text => "#{spell.name} (", :font => "Lilith", :color => "004E6D", :size => FONT_SIZE_SUBSECTION}]
2019-05-27 15:02:07 -04:00
pdf.font_size FONT_SIZE_BODY
2019-05-27 15:59:58 -04:00
previous = false
2019-05-27 15:02:07 -04:00
spell.arcana.each do |arcanum|
2019-05-27 15:59:58 -04:00
spell_ary << {:text => ", ", :font => "Lilith", :color => "004E6D", :size => FONT_SIZE_SUBSECTION} if previous
2019-05-27 15:20:48 -04:00
spell_ary << {:text => arcanum.to_s.titleize, :font => "Lilith", :color => "004E6D", :size => FONT_SIZE_SUBSECTION}
2019-05-27 15:59:58 -04:00
spell_ary << {:text => spell.send(arcanum).to_dots, :color => "004E6D", :size => FONT_SIZE_SUBSECTION, :character_spacing => -5}
previous = true
2019-05-27 15:02:07 -04:00
end
2019-05-27 15:59:58 -04:00
spell_ary << {:text => " )", :font => "Lilith", :styles => [], :color => "004E6D", :size => FONT_SIZE_SUBSECTION, :character_spacing => -3}
2019-05-27 15:02:07 -04:00
pdf.formatted_text spell_ary
pdf.formatted_text [
2019-05-27 15:20:48 -04:00
{:text => "Practice: ", :styles => [:bold], :font => "Goudy"},
2019-05-27 15:02:07 -04:00
{:text => spell.practice, :font => "Goudy"},
]
pdf.formatted_text [
2019-05-27 15:20:48 -04:00
{:text => "Primary Factor: ", :styles => [:bold], :font => "Goudy"},
2019-05-27 15:02:07 -04:00
{:text => spell.primary_factor, :font => "Goudy"},
]
pdf.formatted_text [
2019-05-27 15:20:48 -04:00
{:text => "Withstand: ", :styles => [:bold], :font => "Goudy"},
2019-05-27 15:02:07 -04:00
{:text => spell.withstand, :font => "Goudy"},
] if !spell.withstand.nil?
pdf.formatted_text [
2019-05-27 15:20:48 -04:00
{:text => "Suggested Rote Skills: ", :styles => [:bold], :font => "Goudy"},
2019-05-27 15:02:07 -04:00
{:text => spell.suggested_rote_skills.join(', '), :font => "Goudy"},
]
pdf.formatted_text [
2019-05-27 15:20:48 -04:00
{:text => spell.authors.length == 1 ? "Author: " : "Authors: ", :styles => [:bold], :font => "Goudy"},
2019-05-27 15:02:07 -04:00
{:text => spell.authors.join(', '), :font => "Goudy"},
]
2019-05-31 07:07:25 -04:00
pdf.text spell.rules_text, :inline_format => true
2019-05-27 15:02:07 -04:00
spell.reaches.each do |reach|
pdf.formatted_text [
2019-05-27 15:20:48 -04:00
{:text => "+#{reach[0]} Reach: ", :styles => [:bold], :font => "Goudy"},
2019-05-27 15:02:07 -04:00
{:text => reach[1], :font => "Goudy"},
]
end
2019-05-28 01:53:25 -04:00
spell.adds.each do |add|
pdf.formatted_text [
{:text => "#{add[:verb] ? add[:verb] : "Add"} #{add[:arcana].collect { |arcanum, rating| [arcanum, rating].to_arcanum_with_dots }.to_list(:separator => add[:separator])}: ", :styles => [:bold], :font => "Goudy"},
2019-05-28 01:53:25 -04:00
{:text => add[:effect], :font => "Goudy"},
]
end
2019-05-27 15:02:07 -04:00
end
end
2019-05-27 15:20:48 -04:00
pdf.start_new_page
2019-05-27 15:02:07 -04:00
end
2019-05-27 06:24:03 -04:00
pdf.render_file("book_of_faces.pdf")
end
end
book_of_faces = BookOfFaces.new
book_of_faces.generate