mse version: 0.3.6
short name: D&D
full name: 4th Edition
icon: card-back.png
position hint: 01

version: 2008-06-06

# By Randolph
# ugly hacking by Ander

init script:
	card_number := {
		position (
			of: card
			in: set
			order_by: { card.name }
		) + 1
	}
	card_count := {
		number_of_items(in: set)
	}
	text_filter :=
		# step 1 : remove all automatic tags
		tag_remove_rule(tag: "<sym-auto>") +
		tag_remove_rule(tag: "<i-auto>")   +
		# step 2a : reminder text for keywords
		expand_keywords_rule(
			default_expand: { chosen(choice:mode, set.automatic_reminder_text) },
			combine:        {
				if mode == "pseudo" then "<i-auto>{keyword}</i-auto>"
				else "{keyword}<atom-reminder-{mode}> ({process_english_hints(reminder)})</atom-reminder-{mode}>" }
			) +
		# step 2b : move action keywords' reminder text to the end of the line
		replace_rule(
			match: "(<atom-reminder-action>(?:(?!<kw-).)*</atom-reminder-action></kw[^>]*>)(((?!<atom-reminder| ?<kw-)[^\n(])+)",
			replace: "\\2\\1"
			) +
		# step 2c : remove duplicate reminder text
		replace_rule(
			match: "(<atom-reminder-[^>]*>[^)]+[)]</atom-reminder-[^>]*>)([^\n]+)\\1"
			replace: "\\2\\1"
			) +
		# step 3a : expand shortcut words ~ and CARDNAME
		replace_rule(
			match: "~|~THIS~|CARDNAME",
			in_context: "(^|[[:space:]]|\\()<match>", # TODO: Allow any punctuation before
			replace: "<atom-cardname></atom-cardname>"
			) +
		# step 3b : fill in atom fields
		tag_contents_rule(
			tag: "<atom-cardname>",
			contents: { if card_name=="" then "CARDNAME" else card_name }
			) +
		# step 4 : explict non mana symbols
		replace_rule(
			match: "\\][imosfuUbernpPt]+\\[",
			replace: {"<nosym>" + range_filter() + "</nosym>"} ) +
		# step 5 : add explict mana symbols
		replace_rule(
			match: "\\[[imosfuUbernpPt]+\\]",
			replace: {"<sym>" + range_filter() + "</sym>"} ) +
		# step 6 : italic reminder text
		replace_rule(
		 	match: "[(]([^)\n]|[(][^)\n]*[)])*[)]?",
			in_context: "(^|[[:space:]])<match>|<atom-keyword><match></",
		 	replace: "<i-auto>&</i-auto>") +
		# step 7 : Replace dot
		replace_rule(
			match: "\\*",
			replace: "<sym>$</sym>") +
		#replace_rule(
		#	match:
		#		"Hit: "
		#	replace:
		#		"<b>Hit:</b> ") +
		#replace_rule(
		#	match:
		#		"Miss: "
		#	replace:
		#		"<b>Miss:</b> ") +
		#replace_rule(
		#	match:
		#		"Effect: "
		#	replace:
		#		"<b>Effect:</b> ") +
		#replace_rule(
		#	match:
		#		"Trigger: "
		#	replace:
		#		"<b>Trigger:</b> ") +
		#replace_rule(
		#	match:
		#		"Primary Attack: "
		#	replace:
		#		"<b>Primary Attack:</b> ") +
		#replace_rule(
		#	match:
		#		"Secondary Attack: "
		#	replace:
		#		"<b>Secondary Attack:</b> ") +
		#replace_rule(
		#	match:
		#		"Tertiary Attack: "
		#	replace:
		#		"<b>Tertiary Attack:</b> ") +
		#replace_rule(
		#	match:
		#		"Primary Target: "
		#	replace:
		#		"<b>Primary Target:</b> ") +
		#replace_rule(
		#	match:
		#		"Secondary Target: "
		#	replace:
		#		"<b>Secondary Target:</b> ") +
		#replace_rule(
		#	match:
		#		"Tertiary Target: "
		#	replace:
		#		"<b>Tertiary Target:</b> ") +
		#replace_rule(
		#	match:
		#		"Attack: "
		#	replace:
		#		"<b>Attack:</b> ") +			
		#replace_rule(
		#	match:
		#		"Target: "
		#	replace:
		#		"<b>Target:</b> ") +
		#replace_rule(
		#	match:
		#		"Targets: "
		#	replace:
		#		"<b>Targets:</b> ") +
		# ACTION TYPE
		#replace_rule(
		#	match:"Standard Action "
		#	replace:"<b>Standard Action</b>     ") +
		#replace_rule(
		#	match:"Minor Action "
		#	replace:"<b>Minor Action</b>     ") +	
		#replace_rule(
		#	match:"Move Action "
		#	replace:"<b>Move Action</b>     ") +
		#replace_rule(
		#	match:"Immediate Reaction "
		#	replace:"<b>Immediate Reaction</b>     ") +
		#replace_rule(
		#	match:"Immediate Interrupt "
		#	replace:"<b>Immediate Interrupt</b>     ") +
		#replace_rule(
		#	match:"Free Action "
		#	replace:"<b>Free Action</b>     ") +
		# RANGE
		#replace_rule(
		#	match:" Melee or Ranged "
		#	replace:" <b>Melee</b> or <b>Ranged</b> ") +
		#replace_rule(
		#	match:"     Melee "
		#	replace:"     <b>Melee</b> ") +
		#replace_rule(
		#	match:"     Ranged "
		#	replace:"     <b>Ranged</b> ") +
		#replace_rule(
		#	match:"     Close "
		#	replace:"     <b>Close</b> ") +
		#replace_rule(
		#	match:"     Area "
		#	replace:"     <b>Area</b> ") +
		#replace_rule(
		#	match:"     Personal"
		#	replace:"     <b>Personal</b>") +
		#replace_rule(
		#	match:"Requirement: "
		#	replace:"<b>Requirement:</b> ") +
		#replace_rule(
		#	match:"Special: "
		#	replace:"<b>Special:</b> ") +
		#replace_rule(
		#	match:"<b>burst</b>"
		#	replace:"burst") +
		#replace_rule(
		#	match:"<b>blast</b>"
		#	replace:"blast") +
		#replace_rule(
		#	match:"<b>weapon</b>"
		#	replace:"weapon") +
		#replace_rule(
		#	match:"<b>or</b>"
		#	replace:"or") +
		# SUSTAIN
		#replace_rule(
		#	match:"Sustain Minor: "
		#	replace:"<b>Sustain Minor:</b> ") +
		#replace_rule(
		#	match:"Sustain Standard: "
		#	replace:"<b>Sustain Standard:</b> ") +
		#replace_rule(
		#	match:"Sustain Move: "
		#	replace:"<b>Sustain Move:</b> ") +
		# CLASS FEATURES
		#replace_rule(
		#	match:"Fey Pact: "
		#	replace:"<b>Fey Pact:</b> ") +
		#replace_rule(
		#	match:"Infernal Pact: "
		#	replace:"<b>Infernal Pact:</b> ") +
		#replace_rule(
		#	match:"Star Pact: "
		#	replace:"<b>Star Pact:</b> ") +
		#replace_rule(
		#	match:"Inspiring Presence: "
		#	replace:"<b>Inspiring Presence:</b> ") +
		#replace_rule(
		#	match:"Tactical Presence: "
		#	replace:"<b>Tactical Presence:</b> ") +
		#replace_rule(
		#	match:"Artful Dodger: "
		#	replace:"<b>Artful Dodger:</b> ") +
		#replace_rule(
		#	match:"Brutal Scoundrel: "
		#	replace:"<b>Brutal Scoundrel:</b> ") +
		#replace_rule(
		#	match:"Weapon: "
		#	replace:"<b>Weapon:</b> ") +
		curly_quotes
	flavor_text_filter :=
		tag_remove_rule(tag: "<i-flavor>")   +
		{ "<i-flavor>" + input + "</i-flavor>" } +
		curly_quotes
	super_type_filter :=
		tag_remove_rule(tag: "<word-list-") + { "<word-list-type>{input}</word-list-type>" }
	action_filter := sort_rule(order: "imosf")
	range_filter := sort_rule(order: "uUbernpPt")
	sub_type_filter :=
		tag_remove_rule(tag: "<word-list-") +
		replace_rule(match: " </soft>$", replace: "") + # remove trailing soft space
		tag_remove_rule(tag: "<soft") +
		{ list_type := if not is_racial(type) and not is_feat(type) and not is_feature(type) then "class"
				      first := ""
			if list_type != "" then (
				#if input != "" then input := input + "<soft> </soft>" # Add a new box at the end
				first + "<word-list-{list_type}>{ space_to_wltags(input) }</word-list-{list_type}>"
			) else first + input
		}
		
	is_racial	:= match_rule(match: "(?i)Racial")
	is_feat		:= match_rule(match: "(?i)Feat")
	is_attack	:= match_rule(match: "(?i)Attack")
	is_utility	:= match_rule(match: "(?i)Utility")
	is_feature	:= match_rule(match: "(?i)Feature")
	
	action_list_filter := {
		input :=
			if card.action_icon == "i" then "Immediate"
			else if card.action_icon == "m" then "Minor"
			else if card.action_icon == "o" then "Move"
			else if card.action_icon == "s" then "Standard"
			else if card.action_icon == "f" then "Free/Non-Action"
			else "Undefined"
	}

	range_list_filter := {
		input :=
			if card.range_icon == "u" then "Close Burst"
			else if card.range_icon == "U" then "Area Burst"
			else if card.range_icon == "b" then "Blast"
			else if card.range_icon == "e" then "Melee"
			else if card.range_icon == "r" then "Ranged"
			else if card.range_icon == "n" then "Melee & Ranged"
			else if card.range_icon == "t" then "Touch"
			else if card.range_icon == "p" then "Personal"
			else "Undefined"
	}

	sort_type_filter := {
		input :=
			card.type + " - " + card.frequency
			#if card.frequency == "At-Will" then input + " - At-Will"
			#else if card.frequency == "Encounter" then input + " - Encounter"
			#else if card.frequency == "Daily" then input + " - Daily"
			#else input
	}

	space_to_wltags := replace_rule(match:"( +|<soft> </soft>)",
					replace:{"</word-list-{list_type}>{_1}<word-list-{list_type}>"})
					
	space_to_comma := replace_rule(match:" ", replace:",")
	only_first     := replace_rule(match:" .*", replace:"")
	only_next      := replace_rule(match:"^[^ ]* ?", replace:"")	
	frequency_filter := tag_remove_rule(tag: "<word-list-") +
		{ 	"<word-list-frequency>{input}</word-list-frequency>" }

############################################################## Set fields
set field:
	type: info
	name: Set Information
set field:
	type: text
	name: title
	identifying: true
set field:
	type: text
	name: description
	multi line: true
set field:
	type: symbol
	name: symbol
	description: The symbol for this set, double click to edit

############################# Default style
default set style:
	title:
		padding left: 2
		font:
			size: 16

############################################################## Card fields
card field:
	type: text
	name: full name
	save value: false
	show statistics: false
	editable: false
	card list visible: true
	card list name: Name
	card list column: 1
	card list width: 150
	script: card.name
card field:
	type: text
	name: name
	card list visible: false
	identifying: true
	show statistics: false
	description: Power name
card field:
	type: image
	name: image
	show statistics: false
	description: Image
card field:
	type: text
	name: super type
	icon: stats/card_type.png
	position hint: 30
	editable: false
	card list visible: true
	card list width: 190
	card list column: 2
	card list name: Class/Race	
	script: super_type_filter(value)
card field:
	type: text
	name: sub type
	icon: stats/creature_type.png
	position hint: 31
	card list visible: true
	card list column: 3
	card list width: 60
	card list name: Type
	script: sub_type_filter(value, type:card.super_type)
	editable: false
card field:
	type: text
	name: level
	position hint: 32
	card list visible: true
	card list name: Level
	card list column: 4
	card list width: 40
card field:
	type: text
	name: type
	show statistics: false
	save value: false
	script:
		# Either just supertype, or subtype - supertype
		combined_editor(
			field1: card.super_type,
			separator1: " ",
			field2: card.sub_type,
			separator2: " ",
			field3: card.level,
			separator3: " "
			soft_before_empty: true,
			hide_when_empty:   false
		)
	description: The type of this card, type a space to go the sub type
card field:
	type: text
	name: sort type
	show statistics: false
	save value: false
	script:
		forward_editor(field:card.type)
		sort_type_filter(input: value)
	card list visible: true
	card list name: Power Class/Type/Level
	card list width: 195
	card list column: 12
card field:
	type: text
	name: descriptors
	icon: stats/creature_type.png
	position hint: 33
	script:
		if card.flags != "" then
		(
			combined_editor(
				field1: card.frequency,
				separator:" <sym>$</sym> ",
				field2: card.flags,
				soft_before_empty: true,
				hide_when_empty:   true
			)
		)
		else
			combined_editor(
				field1: card.frequency,
				separator:" ",
				field2: card.flags,
				soft_before_empty: true,
				hide_when_empty:   true
			)
card field:
	type: text
	name: frequency
	position hint: 34
	card list visible: true
	card list name: Frequency
	card list column: 5
	card list width: 80	
	editable: false
	script: frequency_filter(value)
card field:
	type: text
	name: flags
	position hint: 35
	card list name: Keywords
	card list column: 10
	editable: false
############################# Text box
card field:
	type: text
	name: rule text
	multi line: true
	script: text_filter(input: value, card_name: card.name)
	show statistics: false
	card list column: 11
	card list name: Rules Text
	description: Rules text
card field:
	type: text
	name: flavor text
	multi line: true
	script: flavor_text_filter(value)
	show statistics: false
	card list column: 12
	card list name: Flavor Text
	description: Flavor text
# New fields for D&D power cards
card field:
	type: text
	name: source
	multi line: true
	script: color_dot_filter(input: value)
	show statistics: false
	description: Power classification, ex: "Fighter Attack 1"
card field:
	type: text
	name: source2
	show statistics: false
card field:
	type: text
	name: action
	multi line: true
	card list visible: true
	card list column: 6
	card list name: Action
	script: 
		#forward_editor(field: card.action_icon)
		action_list_filter(input: value)
	#text_filter(input: value, card_name: card.name)
	show statistics: false
	description: Action type used to initiate power, ex: "Standard"
card field:
	type: text
	name: actionword
	editable: false
	save value: false
	default: "Action"
	show statistics: false
card field:
	type: text
	name: action icon
	script: action_filter(input: value)
	show statistics: false
	description: Action required: (s)tandard, m(o)ve, (m)inor, (i)mmediate or (f)ree
card field:
	type: text
	name: range
	multi line: true
	card list visible: true
	card list column: 7
	card list name: Range/Area
	script:
		range_list_filter(input: value)
	#text_filter(input: value, card_name: card.name)
	show statistics: false
	description: Attack method, ex: "Area burst"
card field:
	type: text
	name: range icon
	script: range_filter(input: value)
	show statistics: false
	description: Attack method: m(e)lee, (r)anged, melee a(n)d ranged, (b)last, close b(u)rst, ranged b(U)rst, (p)ersonal or (t)ouch
card field:
	type: text
	name: rangevalue
	multi line: true
	show statistics: false
	description: If the attack has a range, this is the distance in squares
card field:
	type: text
	name: attack
	multi line: true
	card list visible: true
	card list column: 8
	card list name: Attack/Defense
	script: text_filter(input: value, card_name: card.name)
	show statistics: false
	description: Attack resolution, ex: "Str vs. AC"
card field:
	type: text
	name: defense
	show statistics: false
card field:
	type: text
	name: illus
	editable: false
	save value: false
	default: "Illus."
	show statistics: false
card field:
	type: text
	name: illustrator
	show statistics: false
	description: Illustrator
card field:
	type: text
	name: sustainword
	editable: false
	save value: false
	default: "Sustain"
	show statistics: false
card field:
	type: text
	name: sustain
	show statistics: false
	description: Action required to sustain the power
card field:
	type: text
	name: name2
	show statistics: false
	description: Secondary name field
card field:
	type: choice
	name: watermark
	show statistics: false
	choice: None
	choice: Arcane
	choice: Divine
	choice: Martial
	choice: Primal
	choice: Psionic
	choice: Shadow
card field:
	type: text
	name: box_label1
	show statistics: false
card field:
	type: text
	name: box_label2
	show statistics: false
card field:
	type: text
	name: box_label3
	show statistics: false
card field:
	type: text
	name: box_label4
	show statistics: false	
card field:
	type: text
	name: box_label5
	show statistics: false
card field:
	type: choice
	name: background
	save value: true
	choice: Green
	choice: Red
	choice: 
		name: Black
		line below: true
	choice: Orange
	choice: Orange2
	choice: Orange3
	choice: Orange4
	choice:
		name: Blue
		line below: true
	choice: Grey
	choice: Gold
	choice: Silver
	choice: Iron
	initial: Empty	

############################# Card sorting / numbering
card field:
	type: text
	name: card number
	save value: false
	script: card_number() + "/" + card_count()
	sort script: card.card_number
	card list visible: true
	card list column: 15
	card list width: 70
	card list name: #
	card list alignment: right
	editable: false
	show statistics: false

############################################################## Card list
card list color script:
	input := card.background
	if input == "Black" then rgb(0,0,0)
	else if input == "Red" then rgb(168,0,0)
	else if input == "Green" then rgb(0,128,0)
	else if input == "Blue" then rgb(0,30,158)
	else if input == "Gold" then rgb(190,150,70)
	else if input == "Silver" then rgb(140,140,140)
	else if input == "Iron" then rgb(50,50,60)
	else if input == "Grey" then rgb(100,100,100)
	else rgb(230,140,20)
############################################################## Word lists
word list:
	name: frequency
	word: At-Will
	word: Encounter
	word: Daily
	word: Special
word list:
	name: type
	word: Cleric
	word: Fighter
	word: Paladin
	word: Ranger
	word: Rogue
	word: Warlock (All)
	word: Warlock (Fey)
	word: Warlock (Infernal)
	word: Warlock (Star)
	word: Warlord
	word: 
		name: Wizard
		line below: true
	word: Dragonborn
	word: Dwarf
	word: Eladrin
	word: Elf
	word: Half-Elf
	word: Halfling
	word: Human
	word:
		name: Tiefling
		line below: true
	word: Feat
word list:
	name: class
	word: Attack
	word: Utility
	word: Racial
	word: Feature
	word: Feat
############################################################## Auto replace
auto replace:
	match: (C)
	replace: ©
auto replace:
	match: AE
	replace: Æ
	whole word: false
auto replace:
	match: TM
	replace: ™
	whole word: false
auto replace:
	match: --
	replace: —
auto replace:
	# note the spaces
	match:
		 - 
	replace:
		 — 
