From ed72a947a6c97804c1eef5b80bfa49d99f7d7586 Mon Sep 17 00:00:00 2001 From: Haru Date: Fri, 8 Nov 2013 07:18:40 +0100 Subject: Item DB overhaul http://hercules.ws/board/topic/2954-item-db-file-structure-overhaul - Item db was changed to libconfig format. - This new format is larger than the original format, but it's less subject to conflicts when some items are edited and the file gets updated. - It is no longer necessary to specify fields with no value, and only the actually used fields are specified. - Items scripts (especially the long ones) are made more readable by splitting them into multiple lines, with proper indentation. - A converter perl script is provided in the tools directory (and a link to the web-based version of the same script canbe found in the above forum topic) - All of this was made possible thanks to Ind, Yommy. Signed-off-by: Haru --- tools/itemdbconverter.pl | 194 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100755 tools/itemdbconverter.pl (limited to 'tools') diff --git a/tools/itemdbconverter.pl b/tools/itemdbconverter.pl new file mode 100755 index 000000000..747f9e84f --- /dev/null +++ b/tools/itemdbconverter.pl @@ -0,0 +1,194 @@ +#!/usr/bin/perl +# +# Copyright (c) Hercules Dev Team, licensed under GNU GPL. +# See the LICENSE file +# Base Author: Haru @ http://hercules.ws +# +# This script converts an item_db(2).txt to the new item_db(2).conf format. +# usage example: perl tools/itemdbconverter.pl < db/item_db2.txt > db/item_db2.conf +# +use strict; +use warnings; + +sub prettifyscript ($) { + my ($orig) = @_; + $orig =~ s/^[\s\t]*//; $orig =~ s/[\s\t]*$//; + return '' unless $orig =~ /[^\s\t]/; + my ($p, $script) = ($orig, ''); + my ($curly, $lines, $comment) = (2, 0, 0); + my ($linebreak, $needindent) = (0, 0); + while ($p =~ /[^\s\t]/) { + $linebreak = 0; + if ($comment && $p =~ s|^\s*\*/\s*||) { + $comment = 0; + next; + } elsif ($p =~ s/^\s*({)\s*//) { + $curly++ unless $comment; + $comment++ if $comment; + $script .= " "; + $linebreak = 1; + $lines++; + } elsif ($p =~ s/^\s*(})\s*//) { + $curly-- unless $comment; + $comment-- if $comment - 1 > 0; + $linebreak = 1; + $lines++; + } elsif ($p =~ s/^\s*(;)\s*//) { + if ($p && (!$comment || $p !~ m|^[\s\t]*(?:\*/)[\s\t]*$|)) { + $linebreak = 1; + $lines++ + } + } elsif ($p =~ s/^("[^"]*")//) { + } elsif ($p =~ s|^\s*/\*\s*||) { + $comment = 1; + next; + } elsif ($p !~ s/^(.)//) { + last; + } + $script .= "\t" x $curly if $needindent; + $script .= "//" . ("\t" x ($comment-1)) if ($comment && ($needindent || $script eq '')); + $script .= "$1"; + if ($linebreak) { + $script .= "\n"; + $needindent = 1; + } else { + $needindent = 0; + } + } + if ($curly != 2) { + printf STDERR "Parse error, curly braces count ". ($curly-2) .". returning unmodified script:\n$orig\n\n"; + return $orig; + } + if ($lines) { + $script = "\n\t\t$script\n\t"; + } else { + $script = " $script "; + } + return $script; +} + +sub parsedb (@) { + my @input = @_; + foreach (@input) { + chomp $_; +# ID,AegisName,Name,Type,Buy,Sell,Weight,ATK,DEF,Range,Slots,Job,Upper,Gender,Loc,wLV,eLV,Refineable,View,{ Script },{ OnEquip_Script },{ OnUnequip_Script } + if( $_ =~ qr/^ + (?(?:\/\/[^0-9]*)?) + (?[0-9]+), + (?[^,]+), + (?[^,]+), + (?[0-9]+), + (?[0-9]*), + (?[0-9]*), + (?[0-9]*), + (?[0-9-]*)(?:(?[0-9-]*))?, + (?[0-9-]*), + (?[0-9]*), + (?[0-9]*), + (?[x0-9A-F]*), + (?[0-9]*), + (?[0-9]*), + (?[0-9]*), + (?[0-9]*), + (?[0-9]*)(?:(?[0-9]*))?, + (?[0-9]*), + (?[0-9]*), + {(?