Author Topic: In the wishlist: TBL to spreadsheet converter  (Read 3375 times)

0 Members and 1 Guest are viewing this topic.

Offline Fury

  • The Curmudgeon
  • 213
In the wishlist: TBL to spreadsheet converter
So I was wondering how much work it would be to implement some sort of ships.tbl, weapons.tbl and tbm to spreadsheet converter? Spreadsheet layout would be something like this
Code: [Select]
$Name: +Title $Model File: $Damage: $Armor factor:
@Subach HL-7 XSTR("GTW Subach HL-7", 3243) none 15 0.9
@Akheton SDG XSTR("GTW Akheton SDG", 3258) none 30 0.0
It'd be so easy to add extra functions to the spreadsheet and have your calculations done for you for all weapons or ships in few seconds. As opposed to having to go through each one of them by hand which may take several days.

Please?
« Last Edit: October 30, 2010, 01:49:48 am by Fury »

 

Offline Snail

  • SC 5
  • 214
  • Posts: ☂
Re: In the wishlist: TBL to spreadsheet converter
TBLView32 did exactly that, but it doesn't parse SCP specific features and didn't do calculations. I think it just tabulated it. Anyhow if the guy who made TBLView (Heiko Hermann?) released the source code, it could be a starting point.

 

Offline Spicious

  • Master Chief John-158
  • 210
Re: In the wishlist: TBL to spreadsheet converter
Exporting to csv should be easy enough. It's just a matter of parsing. Figuring out a linear ordering of fields could be interesting too.

 

Offline Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
Re: In the wishlist: TBL to spreadsheet converter
Here's something I whipped up in about 30 minutes.  Feel free to throw tomatoes at it.

Code: [Select]
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;


public class TBLToCSV
{
    private final File input;
    private final File output;
    private final Map<String, Map<String, String>> chart;
    private final Set<String> labels;
   
    public TBLToCSV(File input, File output)
    {
        this.input = input;
        this.output = output;
        this.chart = new HashMap<String, Map<String, String>>();
        this.labels = new LinkedHashSet<String>();
    }
   
    public void process() throws IOException
    {
        List<String> lines = readTextFileLines(input);
        String currentName = null;
        boolean foundShipClasses = false;
       
        // generate chart
        for (String line: lines)
        {
            line = line.trim();
            if (line.equals("#Ship Classes"))
                foundShipClasses = true;
            if (!foundShipClasses)
                continue;
           
            if (line.startsWith("$Name:"))
            {
                currentName = line.substring(6).trim();
                chart.put(currentName, new HashMap<String, String>());
            }
           
            String firstPart = null;
            String secondPart = null;
            if (line.startsWith("$") || line.startsWith("+"))
            {
                int colonPos = line.indexOf(":");
                if (colonPos >= 0)
                {
                    firstPart = line.substring(0, colonPos + 1).trim();
                    secondPart = line.substring(colonPos + 1).trim();
                   
                    // truncate comments
                    int commentpos = secondPart.indexOf(";");
                    if (commentpos >= 0)
                        secondPart = secondPart.substring(0, commentpos).trim();
                   
                    // avoid errors in CSV!
                    if (secondPart.contains(","))
                        secondPart = secondPart.replace(',', '\'');
                }
            }
           
            if (firstPart == null || secondPart == null)
                continue;
           
            labels.add(firstPart);
            chart.get(currentName).put(firstPart, secondPart);
        }
       
        // save chart to CSV
       
        BufferedWriter writer = new BufferedWriter(new FileWriter(output));
        String header = "";
        for (String label: labels)
            header += (label + ",");
        writer.write(header + "\n");
       
        for (Map.Entry<String, Map<String, String>> entry: chart.entrySet())
        {
            String line = "";
           
            for (String label: labels)
                line += (entry.getValue().get(label) + ",");
            writer.write(line + "\n");
        }
        writer.close();
    }
   
    public static void main(String[] args) throws IOException
    {
        TBLToCSV app = new TBLToCSV(new File("C:\\temp\\ships.tbl"), new File("C:\\temp\\output.csv"));
        app.process();
    }
   
    public static boolean nullSafeEquals(Object obj1, Object obj2)
    {
        if (obj1 == null && obj2 == null)
            return true;
        if (obj1 == null || obj2 == null)
            return false;
        return obj1.equals(obj2);
    }
   
    public static List<String> readTextFileLines(File file)
    {
        String str;
        List<String> lines = new ArrayList<String>();
        try
        {
            BufferedReader reader = new BufferedReader(new FileReader(file));
            while ((str = reader.readLine()) != null)
                lines.add(str);
            reader.close();
        }
        catch (IOException ioe)
        {
            lines.clear();
        }
       
        return lines;
    }
}

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: In the wishlist: TBL to spreadsheet converter
Good thing I just picked some tomatoes :)
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 

Offline Fury

  • The Curmudgeon
  • 213
Re: In the wishlist: TBL to spreadsheet converter
So how does one use that java thingy?

 

Offline sigtau

  • 29
  • unfortunate technical art assclown
Re: In the wishlist: TBL to spreadsheet converter
I don't have FSO on here, but if someone could post a sample .tbl from their VP files, then I'd be happy to further test and add onto that code (I'm a five-year experienced Java programmer, so I might be able to help provided I can decipher Goober's code  :nervous:)
Who uses forum signatures anymore?

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: In the wishlist: TBL to spreadsheet converter
There's a few tables in the wiki already.  And I posted the weapons.tbl the other day on pastebin.
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 

Offline sigtau

  • 29
  • unfortunate technical art assclown
Re: In the wishlist: TBL to spreadsheet converter


hay guys look wat im making
Who uses forum signatures anymore?

 

Offline Fury

  • The Curmudgeon
  • 213
Re: In the wishlist: TBL to spreadsheet converter
That's nice and all, but you can't add your own functions in there to make the calculations you want to. Which is why I asked for a spreadsheet converter in similar layout to the example in code tags. :(

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: In the wishlist: TBL to spreadsheet converter
spreadsheets let you do cool things, like autobalence your weapons. so if you could import, crunch the values then export, that would be awesome. ive used spreadsheets for data analysis before, to figure out where things needed improvement. normally i copy over the values manually, but a method to rapidly convert to and from tables would be awesome.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline sigtau

  • 29
  • unfortunate technical art assclown
Re: In the wishlist: TBL to spreadsheet converter
spreadsheets let you do cool things, like autobalence your weapons. so if you could import, crunch the values then export, that would be awesome. ive used spreadsheets for data analysis before, to figure out where things needed improvement. normally i copy over the values manually, but a method to rapidly convert to and from tables would be awesome.

See the little icon that looks like this? 

That's the spreadsheet exporter.  There will be a spreadsheet importer as well (but it will only work as long as 1. it's a CSV file, and 2. it stays in the same general form as the original export).

Also, simply opening and saving the table reformats it to a more readable state, so those mass line-indentations in the retail weapons.tbl can be corrected by simply opening it in this program.
Who uses forum signatures anymore?

 

Offline Fury

  • The Curmudgeon
  • 213
Re: In the wishlist: TBL to spreadsheet converter
Sounds awesome. You're going to make many a tabler much happier, me included. :D

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: In the wishlist: TBL to spreadsheet converter
should work. might let me improve my armor table somewhat.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN