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.

314 lines
12KB

  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 "tilt"
  8. require_relative "tilts"
  9. require_relative "primitive_adds"
  10. puts "Shards of Power PDF generator"
  11. class ShardsOfPower
  12. FONT_SIZE_CHAPTER = 48
  13. FONT_SIZE_SECTION = 24
  14. FONT_SIZE_SUBSECTION = 18
  15. FONT_SIZE_BODY = 10
  16. attr_accessor :pdf, :number_name, :chapter_name, :chapter_title, :section_name, :spells, :conditions, :tilts
  17. def start_chapter(num, name)
  18. @number_name = num
  19. @chapter_name = name
  20. @chapter_title = "Chapter #{number_name}: #{chapter_name}"
  21. puts "Starting #{chapter_title}"
  22. pdf.start_new_page
  23. pdf.outline.update do
  24. puts "\tAdding #{@shards_of_power.chapter_title} on page #{page_number}"
  25. section(@shards_of_power.chapter_title, :destination => page_number)
  26. end
  27. puts "\tSetting font size"
  28. pdf.font_size FONT_SIZE_CHAPTER
  29. pdf.font "Abess"
  30. puts "\tPrinting chapter to document"
  31. pdf.text "Chapter #{number_name}: #{chapter_name}", :align => :center
  32. puts "\tRestoring body text"
  33. pdf.font "Goudy"
  34. pdf.font_size FONT_SIZE_BODY
  35. end
  36. def start_section(section_name)
  37. puts "Beginning section #{section_name}: "
  38. @section_name = section_name
  39. pdf.outline.add_subsection_to(chapter_title) do
  40. @pdf.outline.section section_name, :destination => @pdf.page_number
  41. end
  42. puts "\tSetting font size"
  43. pdf.font_size FONT_SIZE_SECTION
  44. pdf.text section_name, :align => :center
  45. puts "\tRestoring body text"
  46. pdf.font_size FONT_SIZE_BODY
  47. pdf.font "Goudy"
  48. end
  49. def roll_results(dramatic_failure:, failure:, success:, exceptional_success:)
  50. pdf.font_size FONT_SIZE_BODY
  51. pdf.font "Goudy"
  52. pdf.text "Roll Results", :style => :bold
  53. pdf.formatted_text [
  54. { :text => "Dramatic Failure: ", :styles => [:bold] },
  55. { :text => dramatic_failure }
  56. ]
  57. pdf.formatted_text [
  58. { :text => "Failure: ", :styles => [:bold] },
  59. { :text => failure }
  60. ]
  61. pdf.formatted_text [
  62. { :text => "Success: ", :styles => [:bold] },
  63. { :text => success }
  64. ]
  65. pdf.formatted_text [
  66. { :text => "Exceptional Success: ", :styles => [:bold] },
  67. { :text => exceptional_success }
  68. ]
  69. end
  70. def generate
  71. puts "Parsing spells..."
  72. @spells = Spell.spells
  73. @conditions = Condition.conditions
  74. @conditions.sort_by!(&:name)
  75. @tilts = Tilt.tilts
  76. @tilts.sort_by!(&:name)
  77. puts "Creating PDF object..."
  78. @pdf = Prawn::Document.new(:margin => 0)
  79. pdf.default_leading 5
  80. pdf.font_families.update(
  81. "Goudy" => {
  82. :normal => "goudy.ttf",
  83. :bold => "goudy-bold.ttf",
  84. :italic => "goudy-italic.ttf"
  85. },
  86. "Abess" => {
  87. :normal => "abess.ttf"
  88. },
  89. "Lilith" => {
  90. :normal => "lilith.ttf"
  91. }
  92. )
  93. pdf.outline.instance_variable_set(:@shards_of_power, self)
  94. puts "Importing cover..."
  95. pdf.image("cover.png", :width => 612, :height => 792)
  96. puts "Printing inner cover..."
  97. pdf.start_new_page(:margin => 50)
  98. pdf.font "Abess"
  99. pdf.font_size 72
  100. pdf.text "Shards of Power", :align => :center
  101. puts "\tShards of Power big text..."
  102. pdf.font "Goudy"
  103. pdf.font_size 36
  104. pdf.text "\nA compendium of spells, Conditions, Artifacts, and other interesting tidbits for Mage: the Awakening\n\n", :align => :center
  105. puts "\tDescription..."
  106. pdf.font_size 24
  107. pdf.text "Written by members of the /cofd/ Discord, edited by NEETzsche", :align => :center
  108. puts "\tMain credit..."
  109. pdf.outline.define do
  110. end
  111. start_chapter "One", "Introduction"
  112. pdf.column_box([0, pdf.cursor], :columns => 2, :width => pdf.bounds.width) do
  113. 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
  114. start_section "Tools Of Awakened Life"
  115. 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
  116. start_section "Chapters"
  117. 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
  118. start_section "Credits"
  119. spell_authors = spells.collect { |spell| spell.authors }.flatten.uniq.sort
  120. pdf.text "The following users have contributed to Shards of Power, in alphabetical order: #{spell_authors.to_list}"
  121. end
  122. start_chapter("Two", "Spells")
  123. spells.group_by(&:primary_arcanum).sort_by { |arcanum, spells| arcanum }.to_h.each do |arcanum, arcanum_spells|
  124. arcanum_name = arcanum.to_s.titleize
  125. puts "Compiling spells for #{arcanum_name}..."
  126. start_section("#{arcanum_name} Spells")
  127. pdf.column_box([0, pdf.cursor], :columns => 2, :width => pdf.bounds.width) do
  128. arcanum_spells.group_by(&arcanum).sort_by { |rating, spells| rating }.to_h.each do |rating, rating_spells|
  129. rating_title = "#{rating.to_dots} #{Spell::RANKS[rating - 1]} of #{arcanum_name}"
  130. puts "\tCompiling #{rating_title} spells..."
  131. pdf.outline.add_subsection_to("#{arcanum_name} Spells") do
  132. @pdf.outline.section rating_title, :destination => @pdf.page_number
  133. end
  134. pdf.font_size FONT_SIZE_SECTION
  135. pdf.text rating_title
  136. rating_spells.sort_by { |spell| spell.name }.each do |spell|
  137. puts "\t\tCompiling #{spell.full_title} by #{spell.authors.join(', ')}"
  138. pdf.outline.add_subsection_to(rating_title) do
  139. @pdf.outline.section spell.full_title, :destination => @pdf.page_number
  140. end
  141. spell_ary = [{:text => "#{spell.name} (", :font => "Lilith", :color => "004E6D", :size => FONT_SIZE_SUBSECTION}]
  142. pdf.font_size FONT_SIZE_BODY
  143. previous = false
  144. spell.arcana.each do |arcanum|
  145. spell_ary << {:text => ", ", :font => "Lilith", :color => "004E6D", :size => FONT_SIZE_SUBSECTION} if previous
  146. spell_ary << {:text => arcanum.to_s.titleize, :font => "Lilith", :color => "004E6D", :size => FONT_SIZE_SUBSECTION}
  147. spell_ary << {:text => spell.send(arcanum).to_dots, :color => "004E6D", :size => FONT_SIZE_SUBSECTION, :character_spacing => -5}
  148. previous = true
  149. end
  150. spell_ary << {:text => " )", :font => "Lilith", :styles => [], :color => "004E6D", :size => FONT_SIZE_SUBSECTION, :character_spacing => -3}
  151. pdf.formatted_text spell_ary
  152. pdf.formatted_text [
  153. {:text => "Practice: ", :styles => [:bold], :font => "Goudy"},
  154. {:text => spell.practice, :font => "Goudy"},
  155. ]
  156. pdf.formatted_text [
  157. {:text => "Primary Factor: ", :styles => [:bold], :font => "Goudy"},
  158. {:text => spell.primary_factor, :font => "Goudy"},
  159. ]
  160. pdf.formatted_text [
  161. {:text => "Withstand: ", :styles => [:bold], :font => "Goudy"},
  162. {:text => spell.withstand, :font => "Goudy"},
  163. ] if !spell.withstand.nil?
  164. pdf.formatted_text [
  165. {:text => "Cost: ", :styles => [:bold], :font => "Goudy"},
  166. {:text => spell.cost, :font => "Goudy"},
  167. ] if !spell.cost.nil?
  168. pdf.formatted_text [
  169. {:text => "Suggested Rote Skills: ", :styles => [:bold], :font => "Goudy"},
  170. {:text => spell.suggested_rote_skills.join(', '), :font => "Goudy"},
  171. ]
  172. pdf.formatted_text [
  173. {:text => spell.authors.length == 1 ? "Author: " : "Authors: ", :styles => [:bold], :font => "Goudy"},
  174. {:text => spell.authors.join(', '), :font => "Goudy"},
  175. ]
  176. pdf.text spell.rules_text, :inline_format => true
  177. spell.reaches.each do |reach|
  178. pdf.formatted_text [
  179. {:text => "+#{reach[0]} Reach: ", :styles => [:bold], :font => "Goudy"},
  180. {:text => reach[1], :font => "Goudy"},
  181. ]
  182. end
  183. spell.adds.each do |add|
  184. pdf.formatted_text [
  185. {: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"},
  186. {:text => add[:effect], :font => "Goudy"},
  187. ]
  188. end
  189. end
  190. end
  191. end
  192. pdf.start_new_page
  193. end
  194. start_chapter "Three", "Conditions & Tilts"
  195. start_section "Conditions"
  196. puts "Compiling Conditions..."
  197. pdf.column_box([0, pdf.cursor], :columns => 2, :width => pdf.bounds.width) do
  198. conditions.each do |condition|
  199. puts "\tCompiling #{condition.name}..."
  200. pdf.outline.add_subsection_to("Conditions") do
  201. @pdf.outline.section condition.name, :destination => @pdf.page_number
  202. end
  203. condition_ary = [{:text => condition.name, :font => "Lilith", :color => "004E6D", :size => FONT_SIZE_SUBSECTION}]
  204. pdf.formatted_text condition_ary
  205. pdf.text condition.rules_text, :inline_format => true
  206. pdf.text "<b>Possible Sources:</b> #{condition.possible_sources}", :inline_format => true if condition.possible_sources
  207. pdf.text "<b>Resolution:</b> #{condition.resolution}", :inline_format => true
  208. pdf.text "<b>Beat:</b> #{condition.beat}", :inline_format => true
  209. pdf.text "<b>#{condition.authors.size > 1 ? "Authors" : "Author"}:</b> #{condition.authors.to_list}", :inline_format => true
  210. end
  211. pdf.start_new_page
  212. end
  213. start_section "Tilts"
  214. puts "Compiling Tilts..."
  215. pdf.column_box([0, pdf.cursor], :columns => 2, :width => pdf.bounds.width) do
  216. tilts.each do |tilt|
  217. puts "\tCompiling #{tilt.full_title}..."
  218. pdf.outline.add_subsection_to("Tilts") do
  219. @pdf.outline.section tilt.full_title, :destination => @pdf.page_number
  220. end
  221. tilt_ary = [{:text => tilt.full_title, :font => "Lilith", :color => "004E6D", :size => FONT_SIZE_SUBSECTION}]
  222. pdf.formatted_text tilt_ary
  223. pdf.text tilt.rules_text, :inline_format => true
  224. pdf.text "<b>Effect:</b> #{tilt.effect}", :inline_format => true
  225. pdf.text "<b>Causing the Tilt:</b> #{tilt.causing}", :inline_format => true
  226. pdf.text "<b>Ending the Tilt:</b> #{tilt.ending}", :inline_format => true
  227. end
  228. end
  229. pdf.render_file("shards_of_power.pdf")
  230. end
  231. end
  232. shards_of_power = ShardsOfPower.new
  233. shards_of_power.generate