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.

320 lines
12KB

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