Skip to content

Commit

Permalink
Merge pull request elanthia-online#689 from MahtraDR/document_xml_parser
Browse files Browse the repository at this point in the history
[chore] Comment out un-used def, and add other comments
  • Loading branch information
mrhoribu authored Oct 28, 2024
2 parents c904b5d + 0599a28 commit 1d057a7
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions lib/xmlparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class XMLParser

def initialize
@buffer = String.new
@unescape = { 'lt' => '<', 'gt' => '>', 'quot' => '"', 'apos' => "'", 'amp' => '&' }
# @unescape = { 'lt' => '<', 'gt' => '>', 'quot' => '"', 'apos' => "'", 'amp' => '&' }
@bold = false
@active_tags = Array.new
@active_ids = Array.new
Expand Down Expand Up @@ -188,25 +188,25 @@ def make_scar_gsl
@scar_gsl = sprintf("0b0%02b%02b%02b%02b%02b%02b%02b%02b%02b%02b%02b%02b%02b%02b", @injuries['nsys']['scar'], @injuries['leftEye']['scar'], @injuries['rightEye']['scar'], @injuries['back']['scar'], @injuries['abdomen']['scar'], @injuries['chest']['scar'], @injuries['leftHand']['scar'], @injuries['rightHand']['scar'], @injuries['leftLeg']['scar'], @injuries['rightLeg']['scar'], @injuries['leftArm']['scar'], @injuries['rightArm']['scar'], @injuries['neck']['scar'], @injuries['head']['scar'])
end

def parse(line)
@buffer.concat(line)
loop {
if (str = @buffer.slice!(/^[^<]+/))
text(str.gsub(/&(lt|gt|quot|apos|amp)/) { @unescape[$1] })
elsif (str = @buffer.slice!(/^<\/[^<]+>/))
element = /^<\/([^\s>\/]+)/.match(str).captures.first
tag_end(element)
elsif (str = @buffer.slice!(/^<[^<]+>/))
element = /^<([^\s>\/]+)/.match(str).captures.first
attributes = Hash.new
str.scan(/([A-z][A-z0-9_\-]*)=(["'])(.*?)\2/).each { |attr| attributes[attr[0]] = attr[2] }
tag_start(element, attributes)
tag_end(element) if str =~ /\/>$/
else
break
end
}
end
# def parse(line)
# @buffer.concat(line)
# loop {
# if (str = @buffer.slice!(/^[^<]+/))
# text(str.gsub(/&(lt|gt|quot|apos|amp)/) { @unescape[$1] })
# elsif (str = @buffer.slice!(/^<\/[^<]+>/))
# element = /^<\/([^\s>\/]+)/.match(str).captures.first
# tag_end(element)
# elsif (str = @buffer.slice!(/^<[^<]+>/))
# element = /^<([^\s>\/]+)/.match(str).captures.first
# attributes = Hash.new
# str.scan(/([A-z][A-z0-9_\-]*)=(["'])(.*?)\2/).each { |attr| attributes[attr[0]] = attr[2] }
# tag_start(element, attributes)
# tag_end(element) if str =~ /\/>$/
# else
# break
# end
# }
# end

DECADE = 10 * 31_536_000

Expand All @@ -227,6 +227,8 @@ def parse_psm3_progressbar(kind, attributes)
PSM_3_DIALOG_IDS = ["Buffs", "Active Spells", "Debuffs", "Cooldowns"]

def tag_start(name, attributes)
# This is called once per element by REXML in games.rb
# https://ruby-doc.org/stdlib-2.6.1/libdoc/rexml/rdoc/REXML/StreamListener.html
begin
@active_tags.push(name)
@active_ids.push(attributes['id'].to_s)
Expand Down Expand Up @@ -613,6 +615,8 @@ def tag_start(name, attributes)
end

def text(text_string)
# This is called once per element with text in it by REXML in games.rb
# https://ruby-doc.org/stdlib-2.6.1/libdoc/rexml/rdoc/REXML/StreamListener.html
begin
# fixme: /<stream id="Spells">.*?<\/stream>/m
# $_CLIENT_.write(text_string) unless ($frontend != 'suks') or (@current_stream =~ /^(?:spellfront|inv|bounty|society)$/) or @active_tags.any? { |tag| tag =~ /^(?:compDef|inv|component|right|left|spell)$/ } or (@active_tags.include?('stream') and @active_ids.include?('Spells')) or (text_string == "\n" and (@last_tag =~ /^(?:popStream|prompt|compDef|dialogData|openDialog|switchQuickBar|component)$/))
Expand Down Expand Up @@ -781,6 +785,9 @@ def text(text_string)
end

def tag_end(name)
# This is called once per element by REXML in games.rb
# https://ruby-doc.org/stdlib-2.6.1/libdoc/rexml/rdoc/REXML/StreamListener.html

begin
if @game =~ /^DR/
if name == 'compass' and $nav_seen
Expand Down

0 comments on commit 1d057a7

Please sign in to comment.