Advertisement
Guest User

Magic Set Editor Cockatrice XML Exporter

a guest
Jan 27th, 2013
1,191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.35 KB | None | 0 0
  1. mse version: 0.3.8
  2. short name: Cockatrice
  3. full name: Cockatrice Exporter
  4. position hint: 006
  5. icon: icon.png
  6. version: 2013-01-27
  7. installer group: magic/Export/cockatrice
  8.  
  9. depends on:
  10.     package: magic.mse-game
  11.     version: 2009-07-23
  12.  
  13. game: magic
  14. file type: *.xml|*.xml|*.*|*.*
  15.  
  16. # By LtEntropy
  17. # Written by modifying the forum export template
  18. # Modified code which was based on code by Idle Muse, Innuendo and Seeonee
  19.  
  20. option field:
  21.     type: text
  22.     name: setcode
  23.     description: Enter the setcode (ie SOM, DKA, RTR etc)
  24. option field:
  25.     type: text
  26.     name: longname
  27.     description: Enter the set name (ie Scars of Mirrodin, Return to Ravnica etc)
  28. script:
  29.     # Formats rules text w/ only italic tags.
  30.     forum_rules_filter_plain := replace@(match:"[(]", replace:"[i](")+
  31.         replace@(match:"[)]", replace: ")[/i]")
  32.     # Count the number of paragraphs to detect number of walker abilities.
  33.     paragraph_count := replace@(match:"\n", replace:"•")+
  34.         filter_text@(match:"•")
  35.     write_normal := {
  36.         "\n\<card>"
  37.         +"\n\<name>"+card.name+"\</name>"
  38.         +"\n\<set>"+options.setcode+"\</set>"
  39.         +"\n\<manacost>"+card.casting_cost+"\</manacost>"
  40.         +"\n\<type>"+card.type+"\</type>"
  41.         +"\n\<pt>"+card.pt+"\</pt>"
  42.         +"\n\<tablerow>1\</tablerow>"
  43.         +"\n\<text>"+card.rule_text+"\</text>"
  44.         +"\n\</card>\n"
  45.         }
  46.     write_walker := {
  47.         "\n\<card>"
  48.         +"\n\<name>"+card.name+"\</name>"
  49.         +"\n\<set>"+options.setcode+"\</set>"
  50.         +"\n\<manacost>"+card.casting_cost+"\</manacost>"
  51.         +"\n\<type>"+card.type+"\</type>"
  52.         +"\n\<pt>"+card.pt+"\</pt>"
  53.         +"\n\<tablerow>1\</tablerow>"
  54.         +"\n\<loyalty>"+card.loyalty+"\</loyalty>"
  55.         +"\n\<text>"
  56.         # The First Ability
  57.         +"\n"+card.loyalty_cost_1
  58.             +(if card.loyalty_cost_1 !="" then ": ")
  59.             +forum_rules_filter_plain(split_text(match:"\n", card.rule_text).0)
  60.         # The Second Ability
  61.         +(if contains(paragraph_count(card.rule_text), match:"•") then "\n")
  62.             +card.loyalty_cost_2
  63.             +(if card.loyalty_cost_2 !="" then ": ")
  64.             +(if contains(paragraph_count(card.rule_text), match:"•") then forum_rules_filter_plain(split_text(match:"\n", card.rule_text).1))
  65.         # The Third Ability
  66.         +(if contains(paragraph_count(card.rule_text), match:"••") then "\n")
  67.             +card.loyalty_cost_3
  68.             +(if card.loyalty_cost_3 !="" then ": ")
  69.             +(if contains(paragraph_count(card.rule_text), match:"••") then forum_rules_filter_plain(split_text(match:"\n", card.rule_text).2))
  70.         # The Fourth Ability
  71.         +(if contains(paragraph_count(card.rule_text), match:"•••") then "\n")
  72.             +card.loyalty_cost_4
  73.             +(if card.loyalty_cost_4 !="" then ": ")
  74.             +(if contains(paragraph_count(card.rule_text), match:"•••") then forum_rules_filter_plain(split_text(match:"\n", card.rule_text).3))
  75.         +"\n\</text>"
  76.         +"\n\</card>\n"
  77.             }
  78.     write_leveler := {
  79.         "\n\<card>"
  80.         +"\n\<name>"+card.name+"\</name>"
  81.         +"\n\<set>"+options.setcode+"\</set>"
  82.         +"\n\<manacost>"+card.casting_cost+"\</manacost>"
  83.         +"\n\<type>"+card.type+"\</type>"
  84.         +"\n\<pt>"+card.pt+"\</pt>"
  85.         +"\n\<tablerow>1\</tablerow>"
  86.         +"\n\<text>"
  87.         # The First Textbox
  88.         +"\n"+forum_rules_filter_plain(card.rule_text)
  89.             +(if card.pt !="" then " (")+card.pt+")"
  90.         # The Second Textbox
  91.         +"\n[LEVEL "+card.level_1+"]: "
  92.             +forum_rules_filter_plain(card.rule_text_2)
  93.             +(if card.pt_2 !="" then " (")+card.pt_2+")"
  94.         # The Third Textbox
  95.         +"\n"+(if card.level_2 !="" then "[LEVEL "+card.level_2+"]: ")
  96.             +forum_rules_filter_plain(card.rule_text_3)
  97.             +(if card.pt_3 !="" then " (")+card.pt_3+")"
  98.         +"\n\</text>"
  99.         +"\n\</card>\n"
  100.             }
  101.     write_split := {
  102.         "\n\<card>"
  103.         +"\n\<name>"+card.name+" // "+card.name_2+"\</name>"
  104.         +"\n\<set>"+options.setcode+"\</set>"
  105.         +"\n\<manacost>"+card.casting_cost+"\</manacost>"
  106.         +"\n\<type>"+card.type+"\</type>"
  107.         +"\n\<pt>"+card.pt+"\</pt>"
  108.         +"\n\<tablerow>1\</tablerow>"
  109.         +"\n\<text>"+card.rule_text_2+"\n---\n"+card.rule_text_2+"\</text>"
  110.         +"\n\</card>\n"
  111.             }
  112.     write_flip := {
  113.         "\n\<card>"
  114.         +"\n\<name>"+card.name+"\</name>"
  115.         +"\n\<set>"+options.setcode+"\</set>"
  116.         +"\n\<manacost>"+card.casting_cost+"\</manacost>"
  117.         +"\n\<type>"+card.type+"\</type>"
  118.         +"\n\<pt>"+card.pt+"\</pt>"
  119.         +"\n\<tablerow>1\</tablerow>"
  120.         +"\n\<text>"+card.rule_text+"\n---\n"+card.rule_text_2+"\</text>"
  121.         +"\n\</card>\n"
  122.         +"\n\<card>"
  123.         +"\n\<name>"+card.name_2+"\</name>"
  124.         +"\n\<set>"+options.setcode+"\</set>"
  125.         +"\n\<manacost>"+card.casting_cost_2+"\</manacost>"
  126.         +"\n\<type>"+card.type_2+"\</type>"
  127.         +"\n\<pt>"+card.pt_2+"\</pt>"
  128.         +"\n\<tablerow>1\</tablerow>"
  129.         +"\n\<text>"+card.rule_text_2+"\n---\n"+card.rule_text+"\</text>"
  130.         +"\n\</card>\n"
  131.             }
  132.     write_card := { if contains(card.shape, match:"token") or contains(card.shape, match:"rulestip") then ""
  133.         else if contains(card.shape, match:"split") then write_split()
  134.         else if card.name_2 != "" then write_flip()
  135.         else if card.loyalty != "" then write_walker()
  136.         else if contains(card.shape, match:"leveler") then write_leveler()
  137.         else write_normal()
  138.         }
  139.     write_cards := to_text(for each card in sort_list(cards, order_by: {input.card_number}) do write_card())
  140.     to_string("<?xml version='1.0' encoding='UTF-8'?>\n"
  141.          +"<cockatrice_carddatabase version='2'>\n"
  142.          +"<sets>\n"
  143.          +"<set>\n"
  144.          +"<name>"+options.setcode+"</name>\n"
  145.          +"<longname>"+options.longname+"</longname>\n"
  146.          +"</set>\n"
  147.          +"</sets>\n"
  148.          +"<cards>\n"+write_cards+"\n"
  149.          +"</cards>\n"
  150.          +"</cockatrice_carddatabase>\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement