Chronicles of Darkness grimoire-Artifact PDF https://git.lain.church/TheStranjer/ShardsOfPower
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

286 lines
11KB

  1. require "prawn"
  2. require "pry"
  3. require_relative "spell"
  4. require_relative "spells"
  5. require_relative "condition"
  6. require_relative "conditions"
  7. require_relative "primitive_adds"
  8. puts "Shards of Power PDF generator"
  9. class ShardsOfPower
  10. FONT_SIZE_CHAPTER = 48
  11. FONT_SIZE_SECTION = 24
  12. FONT_SIZE_SUBSECTION = 18
  13. FONT_SIZE_BODY = 10
  14. attr_accessor :pdf, :number_name, :chapter_name, :chapter_title, :section_name, :spells, :conditions
  15. def start_chapter(num, name)
  16. @number_name = num
  17. @chapter_name = name
  18. @chapter_title = "Chapter #{number_name}: #{chapter_name}"
  19. puts "Starting #{chapter_title}"
  20. pdf.start_new_page
  21. pdf.outline.update do
  22. puts "\tAdding #{@shards_of_power.chapter_title} on page #{page_number}"
  23. section(@shards_of_power.chapter_title, :destination => page_number)
  24. end
  25. puts "\tSetting font size"
  26. pdf.font_size FONT_SIZE_CHAPTER
  27. pdf.font "Abess"
  28. puts "\tPrinting chapter to document"
  29. pdf.text "Chapter #{number_name}: #{chapter_name}", :align => :center
  30. puts "\tRestoring body text"
  31. pdf.font "Goudy"
  32. pdf.font_size FONT_SIZE_BODY
  33. end
  34. def start_section(section_name)
  35. puts "Beginning section #{section_name}: "
  36. @section_name = section_name
  37. pdf.outline.add_subsection_to(chapter_title) do
  38. @pdf.outline.section section_name, :destination => @pdf.page_number
  39. end
  40. puts "\tSetting font size"
  41. pdf.font_size FONT_SIZE_SECTION
  42. pdf.text section_name, :align => :center
  43. puts "\tRestoring body text"
  44. pdf.font_size FONT_SIZE_BODY
  45. pdf.font "Goudy"
  46. end
  47. def roll_results(dramatic_failure:, failure:, success:, exceptional_success:)
  48. pdf.font_size FONT_SIZE_BODY
  49. pdf.font "Goudy"
  50. pdf.text "Roll Results", :style => :bold
  51. pdf.formatted_text [
  52. { :text => "Dramatic Failure: ", :styles => [:bold] },
  53. { :text => dramatic_failure }
  54. ]
  55. pdf.formatted_text [
  56. { :text => "Failure: ", :styles => [:bold] },
  57. { :text => failure }
  58. ]
  59. pdf.formatted_text [
  60. { :text => "Success: ", :styles => [:bold] },
  61. { :text => success }
  62. ]
  63. pdf.formatted_text [
  64. { :text => "Exceptional Success: ", :styles => [:bold] },
  65. { :text => exceptional_success }
  66. ]
  67. end
  68. def generate
  69. puts "Parsing spells..."
  70. @spells = Spell.spells
  71. @conditions = Condition.conditions
  72. @conditions.sort_by!(&:name)
  73. puts "Creating PDF object..."
  74. @pdf = Prawn::Document.new(:margin => 0)
  75. pdf.default_leading 5
  76. pdf.font_families.update(
  77. "Goudy" => {
  78. :normal => "goudy.ttf",
  79. :bold => "goudy-bold.ttf",
  80. :italic => "goudy-italic.ttf"
  81. },
  82. "Abess" => {
  83. :normal => "abess.ttf"
  84. },
  85. "Lilith" => {
  86. :normal => "lilith.ttf"
  87. }
  88. )
  89. pdf.outline.instance_variable_set(:@shards_of_power, self)
  90. puts "Importing cover..."
  91. pdf.image("cover.png", :width => 612, :height => 792)
  92. puts "Printing inner cover..."
  93. pdf.start_new_page(:margin => 50)
  94. pdf.font "Abess"
  95. pdf.font_size 72
  96. pdf.text "Shards of Power", :align => :center
  97. puts "\tShards of Power big text..."
  98. pdf.font "Goudy"
  99. pdf.font_size 36
  100. pdf.text "\nA compendium of spells, Conditions, Artifacts, and other interesting tidbits for Mage: the Awakening\n\n", :align => :center
  101. puts "\tDescription..."
  102. pdf.font_size 24
  103. pdf.text "Written by members of the /cofd/ Discord, edited by NEETzsche", :align => :center
  104. puts "\tMain credit..."
  105. pdf.outline.define do
  106. end
  107. start_chapter "One", "Introduction"
  108. pdf.column_box([0, pdf.cursor], :columns => 2, :width => pdf.bounds.width) do
  109. pdf.text "Like every supernatural entity in the Chronicles of Darkness, there is a boundless breadth and depth of topics to discuss within them. The Awakened are by no stretch of the imagination an exception to this rule. This book does not dare claim that this will cover all of them, but it does dare to cover the broad strokes on a certain subtopic of the lives of those touched by the Supernal who still reside in the Fallen World: their toolkit.\n\n<b>Mage: the Awakening</b> covered the broadest strokes on Awakened life in general, but there is so much more to the means by which Mages conduct their affairs and pursue their Obsessions that simply is not covered in that volume. There will be yet more that this one fails to consider. However, it is designed to touch on the high level ideas, and dig into some of the specifics for them, leaving you, the reader compelled, and hopefully, inspired as to where to explore next.", :inline_format => true
  110. start_section "Tools Of Awakened Life"
  111. pdf.text "This book is meant to be used as a toolkit. Each of the spells are modular, and for the most part do not operate off of each other. You, as the Storyteller or player, are meant to take the things you find fun, interesting and compelling while leaving the things you find silly, improper, or frustrating behind. This line of thought naturally extends to all of the Conditions, optional Arcana principles, alternative Relinquishment methods, and so on.\n\nThis book was written on a rolling basis by a number of people. It is a compilation, that accumulated over time. It did not get created overnight. As such, by the time you receive this file, there is a good likelihood that it's still in development, which means there might be more up-to-date versions of it, and additionally it may be open to input for your spells, your Artifacts, and your optional rules. The invite code at the time of publication is <b>Cx3JBpB</b>.", :inline_format => true
  112. start_section "Chapters"
  113. pdf.text "There are multiple chapters in this book. Each of them covers a specific set of topics.\n\n<b>Chapter One</b> is ithe Introduction. It is what you are reading now. It gives the mission statement, the credits, and a few other key details before you get into the spells and the Conditions.\n\n<b>Chapter Two</b> is the megagrimoire. It is a grimoire of grimoires, much like the book that White Wolf released when they still called themselves that, and is a combined set of spells that the players of this community have mutually agreed are at least somewhat reasonable. Many of us helped each other write these spells. All of their names will be listed in them, alphabetically.\n\n<b>Chapter Three: Conditions & Tilts</b> discusses new Conditions and Tilts that can be imposed by spells, or by other means, such as dramatic failures.", :inline_format => true
  114. start_section "Credits"
  115. spell_authors = spells.collect { |spell| spell.authors }.flatten.uniq.sort
  116. pdf.text "The following users have contributed to Shards of Power, in alphabetical order: #{spell_authors.to_list}"
  117. end
  118. start_chapter("Two", "Spells")
  119. spells.group_by(&:primary_arcanum).sort_by { |arcanum, spells| arcanum }.to_h.each do |arcanum, arcanum_spells|
  120. arcanum_name = arcanum.to_s.titleize
  121. puts "Compiling spells for #{arcanum_name}..."
  122. start_section("#{arcanum_name} Spells")
  123. pdf.column_box([0, pdf.cursor], :columns => 2, :width => pdf.bounds.width) do
  124. arcanum_spells.group_by(&arcanum).sort_by { |rating, spells| rating }.to_h.each do |rating, rating_spells|
  125. rating_title = "#{rating.to_dots} #{Spell::RANKS[rating - 1]} of #{arcanum_name}"
  126. puts "\tCompiling #{rating_title} spells..."
  127. pdf.outline.add_subsection_to("#{arcanum_name} Spells") do
  128. @pdf.outline.section rating_title, :destination => @pdf.page_number
  129. end
  130. pdf.font_size FONT_SIZE_SECTION
  131. pdf.text rating_title
  132. rating_spells.sort_by { |spell| spell.name }.each do |spell|
  133. puts "\t\tCompiling #{spell.full_title} by #{spell.authors.join(', ')}"
  134. pdf.outline.add_subsection_to(rating_title) do
  135. @pdf.outline.section spell.full_title, :destination => @pdf.page_number
  136. end
  137. spell_ary = [{:text => "#{spell.name} (", :font => "Lilith", :color => "004E6D", :size => FONT_SIZE_SUBSECTION}]
  138. pdf.font_size FONT_SIZE_BODY
  139. previous = false
  140. spell.arcana.each do |arcanum|
  141. spell_ary << {:text => ", ", :font => "Lilith", :color => "004E6D", :size => FONT_SIZE_SUBSECTION} if previous
  142. spell_ary << {:text => arcanum.to_s.titleize, :font => "Lilith", :color => "004E6D", :size => FONT_SIZE_SUBSECTION}
  143. spell_ary << {:text => spell.send(arcanum).to_dots, :color => "004E6D", :size => FONT_SIZE_SUBSECTION, :character_spacing => -5}
  144. previous = true
  145. end
  146. spell_ary << {:text => " )", :font => "Lilith", :styles => [], :color => "004E6D", :size => FONT_SIZE_SUBSECTION, :character_spacing => -3}
  147. pdf.formatted_text spell_ary
  148. pdf.formatted_text [
  149. {:text => "Practice: ", :styles => [:bold], :font => "Goudy"},
  150. {:text => spell.practice, :font => "Goudy"},
  151. ]
  152. pdf.formatted_text [
  153. {:text => "Primary Factor: ", :styles => [:bold], :font => "Goudy"},
  154. {:text => spell.primary_factor, :font => "Goudy"},
  155. ]
  156. pdf.formatted_text [
  157. {:text => "Withstand: ", :styles => [:bold], :font => "Goudy"},
  158. {:text => spell.withstand, :font => "Goudy"},
  159. ] if !spell.withstand.nil?
  160. pdf.formatted_text [
  161. {:text => "Cost: ", :styles => [:bold], :font => "Goudy"},
  162. {:text => spell.cost, :font => "Goudy"},
  163. ] if !spell.cost.nil?
  164. pdf.formatted_text [
  165. {:text => "Suggested Rote Skills: ", :styles => [:bold], :font => "Goudy"},
  166. {:text => spell.suggested_rote_skills.join(', '), :font => "Goudy"},
  167. ]
  168. pdf.formatted_text [
  169. {:text => spell.authors.length == 1 ? "Author: " : "Authors: ", :styles => [:bold], :font => "Goudy"},
  170. {:text => spell.authors.join(', '), :font => "Goudy"},
  171. ]
  172. pdf.text spell.rules_text, :inline_format => true
  173. spell.reaches.each do |reach|
  174. pdf.formatted_text [
  175. {:text => "+#{reach[0]} Reach: ", :styles => [:bold], :font => "Goudy"},
  176. {:text => reach[1], :font => "Goudy"},
  177. ]
  178. end
  179. spell.adds.each do |add|
  180. pdf.formatted_text [
  181. {: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"},
  182. {:text => add[:effect], :font => "Goudy"},
  183. ]
  184. end
  185. end
  186. end
  187. end
  188. pdf.start_new_page
  189. end
  190. start_chapter "Three", "Conditions & Tilts"
  191. start_section "Conditions"
  192. puts "Compiling Conditions..."
  193. pdf.column_box([0, pdf.cursor], :columns => 2, :width => pdf.bounds.width) do
  194. conditions.each do |condition|
  195. puts "\tCompiling #{condition.name}..."
  196. pdf.outline.add_subsection_to("Conditions") do
  197. @pdf.outline.section condition.name, :destination => @pdf.page_number
  198. end
  199. condition_ary = [{:text => condition.name, :font => "Lilith", :color => "004E6D", :size => FONT_SIZE_SUBSECTION}]
  200. pdf.formatted_text condition_ary
  201. pdf.text condition.rules_text
  202. pdf.text "<b>Possible Sources:</b> #{condition.possible_sources}", :inline_format => true if condition.possible_sources
  203. pdf.text "<b>Resolution:</b> #{condition.resolution}", :inline_format => true
  204. pdf.text "<b>Beat:</b> #{condition.beat}", :inline_format => true
  205. pdf.text "<b>#{condition.authors.size > 1 ? "Authors" : "Author"}:</b> #{condition.authors.to_list}", :inline_format => true
  206. end
  207. end
  208. pdf.render_file("shards_of_power.pdf")
  209. end
  210. end
  211. shards_of_power = ShardsOfPower.new
  212. shards_of_power.generate