require "prawn" require "pry" require_relative "spell" require_relative "spells" require_relative "primitive_adds" puts "Book of Faces PDF generator" class BookOfFaces FONT_SIZE_CHAPTER = 48 FONT_SIZE_SECTION = 24 FONT_SIZE_SUBSECTION = 18 FONT_SIZE_BODY = 10 attr_accessor :pdf, :number_name, :chapter_name, :chapter_title, :section_name, :spells def start_chapter(num, name) @number_name = num @chapter_name = name @chapter_title = "Chapter #{number_name}: #{chapter_name}" puts "Starting #{chapter_title}" pdf.start_new_page 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) puts "Beginning section #{section_name}: " @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 puts "Parsing spells..." @spells = Spell.spells puts "Creating PDF object..." @pdf = Prawn::Document.new(:margin => 0) pdf.default_leading 5 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 obviously of supernatural origin even by its first glance. It is plain even to the dumb; it practically glows with an undefined supernatural aura. 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" ) 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 disappearing. 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." ) start_section "Its True Origin" pdf.text "There is quite a bit of dispute about the origin of the Book of Faces. A number of Awakened have insisted that only an entity deep in the labyrinths of Pandemonium could have conceived of this, but some Lost claim it is definitely some kind of Prop. Uratha typically haven't weighed in on this topic, but when they have, they surmised more than insisted that one of the more potent spirits of information or identity concocted it. Very few Kindred weigh in as well, but those few who do typically hail from the Ordo Dracul, and just as typically hautily guffaw at the thought that something other than some Methuselah Elder of great and terrible wisdom would contrive such a cruelly useful tome. Other supernatural entities have their own explanations, but as with so many things, the truth is not really known by anybody." 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 pdf.font_size FONT_SIZE_SECTION pdf.text rating_title rating_spells.sort_by { |spell| spell.name }.each do |spell| puts "\t\tCompiling #{spell.full_title} by #{spell.authors.join(', ')}" pdf.outline.add_subsection_to(rating_title) do @pdf.outline.section spell.full_title, :destination => @pdf.page_number end spell_ary = [{:text => "#{spell.name} (", :font => "Lilith", :color => "004E6D", :size => FONT_SIZE_SUBSECTION}] pdf.font_size FONT_SIZE_BODY previous = false spell.arcana.each do |arcanum| spell_ary << {:text => ", ", :font => "Lilith", :color => "004E6D", :size => FONT_SIZE_SUBSECTION} if previous spell_ary << {:text => arcanum.to_s.titleize, :font => "Lilith", :color => "004E6D", :size => FONT_SIZE_SUBSECTION} spell_ary << {:text => spell.send(arcanum).to_dots, :color => "004E6D", :size => FONT_SIZE_SUBSECTION, :character_spacing => -5} previous = true end spell_ary << {:text => " )", :font => "Lilith", :styles => [], :color => "004E6D", :size => FONT_SIZE_SUBSECTION, :character_spacing => -3} pdf.formatted_text spell_ary pdf.formatted_text [ {:text => "Practice: ", :styles => [:bold], :font => "Goudy"}, {:text => spell.practice, :font => "Goudy"}, ] pdf.formatted_text [ {:text => "Primary Factor: ", :styles => [:bold], :font => "Goudy"}, {:text => spell.primary_factor, :font => "Goudy"}, ] pdf.formatted_text [ {:text => "Withstand: ", :styles => [:bold], :font => "Goudy"}, {:text => spell.withstand, :font => "Goudy"}, ] if !spell.withstand.nil? pdf.formatted_text [ {:text => "Suggested Rote Skills: ", :styles => [:bold], :font => "Goudy"}, {:text => spell.suggested_rote_skills.join(', '), :font => "Goudy"}, ] pdf.formatted_text [ {:text => spell.authors.length == 1 ? "Author: " : "Authors: ", :styles => [:bold], :font => "Goudy"}, {:text => spell.authors.join(', '), :font => "Goudy"}, ] pdf.text spell.rules_text, :inline_format => true spell.reaches.each do |reach| pdf.formatted_text [ {:text => "+#{reach[0]} Reach: ", :styles => [:bold], :font => "Goudy"}, {:text => reach[1], :font => "Goudy"}, ] end 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"}, {:text => add[:effect], :font => "Goudy"}, ] end end end pdf.start_new_page end pdf.render_file("book_of_faces.pdf") end end book_of_faces = BookOfFaces.new book_of_faces.generate