csv reader can read file, stringify (not real save) and read the save itself wrote

This commit is contained in:
Minjae Song
2019-01-02 22:23:48 +09:00
parent 6ecbb672fb
commit 3b2c38cf0b
4 changed files with 75 additions and 55 deletions

View File

@@ -102,55 +102,56 @@
"-1"; "0";"BLOCK_NULL" ;"4.0000";"4.0000";"4.0000";"4.0000"; "-1";"2600";"NULL"; "0"; "0"; "1"; "1"; "0"; "0"; "N/A"; "0";"16";"0.0000";"0.0000";"0.0000";"0.0000" "-1"; "0";"BLOCK_NULL" ;"4.0000";"4.0000";"4.0000";"4.0000"; "-1";"2600";"NULL"; "0"; "0"; "1"; "1"; "0"; "0"; "N/A"; "0";"16";"0.0000";"0.0000";"0.0000";"0.0000"
## Notes ## ## Notes ##
#
# Lava/Water props are left for future references, do not delete them until FluidCodex is built # # Lava/Water props are left for future references, do not delete them until FluidCodex is built #
#
# id: Block ID # id: Block ID
# drop: Drop ID # drop: Drop ID
#
# shdr/g/b, lumr/g/b: Shade RGB/ Lum RGB. # shdr/g/b, lumr/g/b: Shade RGB/ Lum RGB.
# valid range: float of 0..4; 1.0 for 255 # valid range: float of 0..4; 1.0 for 255
#
# solid: whether the tile has full collision (affects physics; flowers are not solid, glass is solid) # solid: whether the tile has full collision (affects physics; flowers are not solid, glass is solid)
# clear: [PENDING FOR REMOVAL] whether the tile has trnasparency (affects render; flowers AND glass is clear) # clear: [PENDING FOR REMOVAL] whether the tile has trnasparency (affects render; flowers AND glass is clear)
# plat: if the block is a Platform (applicable target: actual platforms, furniture filler block that collision == PLATFORM) # plat: if the block is a Platform (applicable target: actual platforms, furniture filler block that collision == PLATFORM)
#
# vscs: viscosity, (velocity) / (1 + (n/16)), 16 halves movement speed, can be used to non-fluid tiles (sticky hazard, tarmac road in Terraria) # vscs: viscosity, (velocity) / (1 + (n/16)), 16 halves movement speed, can be used to non-fluid tiles (sticky hazard, tarmac road in Terraria)
#
# str: strength # str: strength
#
# dsty: density. As we are putting water an 1000, it is identical to specific gravity. [g/l] # dsty: density. As we are putting water an 1000, it is identical to specific gravity. [g/l]
#
# dlfn: dynamic luminosity function. # dlfn: dynamic luminosity function.
# 0-static, 1-torch flicker, 2-current global light (sun, star, moon), 3-daylight at noon, # 0-static, 1-torch flicker, 2-current global light (sun, star, moon), 3-daylight at noon,
# 4-slow breath, 5-pulsate # 4-slow breath, 5-pulsate
#
# mate: material, four-letter code # mate: material, four-letter code
#
# fv: vertical friction (boolean) # fv: vertical friction (boolean)
# fr: horizontal friction. 0: frictionless, <16: slippery, 16: regular, >16: sticky # fr: horizontal friction. 0: frictionless, <16: slippery, 16: regular, >16: sticky
#
#
## Illuminators ## ## Illuminators ##
#
# Illuminator white: Mercury Lamp; CIELAB of (94, -5.131, 10.613), which is made out of CIEXYZ of (0.947638, 1.146481, 0.482263), measured with ColorMunki Spectrometer (If you don't want green tinge, collect a daylight!) # Illuminator white: Mercury Lamp; CIELAB of (94, -5.131, 10.613), which is made out of CIEXYZ of (0.947638, 1.146481, 0.482263), measured with ColorMunki Spectrometer (If you don't want green tinge, collect a daylight!)
# Illuminator orange: Sodium Lamp; CIE xy of (0.5375, 0.4153), CIEXYZ of (352.531139, 272.379377, 30.980339), measured with ColorMunki Spectrometer # Illuminator orange: Sodium Lamp; CIE xy of (0.5375, 0.4153), CIEXYZ of (352.531139, 272.379377, 30.980339), measured with ColorMunki Spectrometer
# Defalut torch : Y 64 x 0.55183 y 0.40966 (Planckian ~1 770 K); real candlelight colour taken from Spyder5 colorimeter (for I couldn't afford i1DisplayPro/Colormunki -- at least back then!) # Defalut torch : Y 64 x 0.55183 y 0.40966 (Planckian ~1 770 K); real candlelight colour taken from Spyder5 colorimeter (for I couldn't afford i1DisplayPro/Colormunki -- at least back then!)
# Sunstone: Artificial sunlight, change colour over time in sync with sunlight. The light is set by game's code. # Sunstone: Artificial sunlight, change colour over time in sync with sunlight. The light is set by game's code.
# Sunlight capacitor: daylight at noon. Set by game's code. # Sunlight capacitor: daylight at noon. Set by game's code.
#
# BLOCK_ILLUMINATOR_CYAN is actually a SUPER_LUMINATOR, cyan colour is used as: # BLOCK_ILLUMINATOR_CYAN is actually a SUPER_LUMINATOR, cyan colour is used as:
# 1. It has quite a brightness on RGB colour space # 1. It has quite a brightness on RGB colour space
# 2. Helmholz-Kohlraush effect # 2. Helmholz-Kohlraush effect
#
#
## Tiles ## ## Tiles ##
#
# 16 colour palette : games's 16-colour palette # 16 colour palette : games's 16-colour palette
# Magical ice: theoretical __metallic__ ice that might form under super-high pressure (> 5 TPa). Its density is a wild guess. # Magical ice: theoretical __metallic__ ice that might form under super-high pressure (> 5 TPa). Its density is a wild guess.
#
#
## References ## ## References ##
#
# * Density of various woods : http://www.engineeringtoolbox.com/wood-density-d_40.html # * Density of various woods : http://www.engineeringtoolbox.com/wood-density-d_40.html
# * Density of various phases of ice : http://www1.lsbu.ac.uk/water/ice_phases.html # * Density of various phases of ice : http://www1.lsbu.ac.uk/water/ice_phases.html
#
Can't render this file because it contains an unexpected character in line 1 and column 20.

View File

@@ -102,55 +102,56 @@
"-1"; "0";"BLOCK_NULL" ;"4.0000";"4.0000";"4.0000";"4.0000"; "-1";"2600";"NULL"; "0"; "0"; "1"; "1"; "0"; "0"; "N/A"; "0";"16";"0.0000";"0.0000";"0.0000";"0.0000" "-1"; "0";"BLOCK_NULL" ;"4.0000";"4.0000";"4.0000";"4.0000"; "-1";"2600";"NULL"; "0"; "0"; "1"; "1"; "0"; "0"; "N/A"; "0";"16";"0.0000";"0.0000";"0.0000";"0.0000"
## Notes ## ## Notes ##
#
# Lava/Water props are left for future references, do not delete them until FluidCodex is built # # Lava/Water props are left for future references, do not delete them until FluidCodex is built #
#
# id: Block ID # id: Block ID
# drop: Drop ID # drop: Drop ID
#
# shdr/g/b, lumr/g/b: Shade RGB/ Lum RGB. # shdr/g/b, lumr/g/b: Shade RGB/ Lum RGB.
# valid range: float of 0..4; 1.0 for 255 # valid range: float of 0..4; 1.0 for 255
#
# solid: whether the tile has full collision (affects physics; flowers are not solid, glass is solid) # solid: whether the tile has full collision (affects physics; flowers are not solid, glass is solid)
# clear: [PENDING FOR REMOVAL] whether the tile has trnasparency (affects render; flowers AND glass is clear) # clear: [PENDING FOR REMOVAL] whether the tile has trnasparency (affects render; flowers AND glass is clear)
# plat: if the block is a Platform (applicable target: actual platforms, furniture filler block that collision == PLATFORM) # plat: if the block is a Platform (applicable target: actual platforms, furniture filler block that collision == PLATFORM)
#
# vscs: viscosity, (velocity) / (1 + (n/16)), 16 halves movement speed, can be used to non-fluid tiles (sticky hazard, tarmac road in Terraria) # vscs: viscosity, (velocity) / (1 + (n/16)), 16 halves movement speed, can be used to non-fluid tiles (sticky hazard, tarmac road in Terraria)
#
# str: strength # str: strength
#
# dsty: density. As we are putting water an 1000, it is identical to specific gravity. [g/l] # dsty: density. As we are putting water an 1000, it is identical to specific gravity. [g/l]
#
# dlfn: dynamic luminosity function. # dlfn: dynamic luminosity function.
# 0-static, 1-torch flicker, 2-current global light (sun, star, moon), 3-daylight at noon, # 0-static, 1-torch flicker, 2-current global light (sun, star, moon), 3-daylight at noon,
# 4-slow breath, 5-pulsate # 4-slow breath, 5-pulsate
#
# mate: material, four-letter code # mate: material, four-letter code
#
# fv: vertical friction (boolean) # fv: vertical friction (boolean)
# fr: horizontal friction. 0: frictionless, <16: slippery, 16: regular, >16: sticky # fr: horizontal friction. 0: frictionless, <16: slippery, 16: regular, >16: sticky
#
#
## Illuminators ## ## Illuminators ##
#
# Illuminator white: Mercury Lamp; CIELAB of (94, -5.131, 10.613), which is made out of CIEXYZ of (0.947638, 1.146481, 0.482263), measured with ColorMunki Spectrometer (If you don't want green tinge, collect a daylight!) # Illuminator white: Mercury Lamp; CIELAB of (94, -5.131, 10.613), which is made out of CIEXYZ of (0.947638, 1.146481, 0.482263), measured with ColorMunki Spectrometer (If you don't want green tinge, collect a daylight!)
# Illuminator orange: Sodium Lamp; CIE xy of (0.5375, 0.4153), CIEXYZ of (352.531139, 272.379377, 30.980339), measured with ColorMunki Spectrometer # Illuminator orange: Sodium Lamp; CIE xy of (0.5375, 0.4153), CIEXYZ of (352.531139, 272.379377, 30.980339), measured with ColorMunki Spectrometer
# Defalut torch : Y 64 x 0.55183 y 0.40966 (Planckian ~1 770 K); real candlelight colour taken from Spyder5 colorimeter (for I couldn't afford i1DisplayPro/Colormunki -- at least back then!) # Defalut torch : Y 64 x 0.55183 y 0.40966 (Planckian ~1 770 K); real candlelight colour taken from Spyder5 colorimeter (for I couldn't afford i1DisplayPro/Colormunki -- at least back then!)
# Sunstone: Artificial sunlight, change colour over time in sync with sunlight. The light is set by game's code. # Sunstone: Artificial sunlight, change colour over time in sync with sunlight. The light is set by game's code.
# Sunlight capacitor: daylight at noon. Set by game's code. # Sunlight capacitor: daylight at noon. Set by game's code.
#
# BLOCK_ILLUMINATOR_CYAN is actually a SUPER_LUMINATOR, cyan colour is used as: # BLOCK_ILLUMINATOR_CYAN is actually a SUPER_LUMINATOR, cyan colour is used as:
# 1. It has quite a brightness on RGB colour space # 1. It has quite a brightness on RGB colour space
# 2. Helmholz-Kohlraush effect # 2. Helmholz-Kohlraush effect
#
#
## Tiles ## ## Tiles ##
#
# 16 colour palette : games's 16-colour palette # 16 colour palette : games's 16-colour palette
# Magical ice: theoretical __metallic__ ice that might form under super-high pressure (> 5 TPa). Its density is a wild guess. # Magical ice: theoretical __metallic__ ice that might form under super-high pressure (> 5 TPa). Its density is a wild guess.
#
#
## References ## ## References ##
#
# * Density of various woods : http://www.engineeringtoolbox.com/wood-density-d_40.html # * Density of various woods : http://www.engineeringtoolbox.com/wood-density-d_40.html
# * Density of various phases of ice : http://www1.lsbu.ac.uk/water/ice_phases.html # * Density of various phases of ice : http://www1.lsbu.ac.uk/water/ice_phases.html
#
Can't render this file because it contains an unexpected character in line 1 and column 20.

View File

@@ -13,6 +13,7 @@ import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.io.StringReader; import java.io.StringReader;
import java.nio.file.Files;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.Vector; import java.util.Vector;
@@ -76,7 +77,7 @@ public class CSVEditor extends JFrame {
comment.setVisible(true); comment.setVisible(true);
comment.setPreferredSize(new Dimension(100, 220)); comment.setPreferredSize(new Dimension(100, 220));
comment.setText("# This is a comment section.\n# All the comment must begin with this '#' mark."); comment.setText("# This is a comment section.\n# All the comment must begin with this '#' mark.\n# null value on the CSV is represented as 'N/A'.");
panelSpreadSheet.add(menuBar, BorderLayout.NORTH); panelSpreadSheet.add(menuBar, BorderLayout.NORTH);
panelSpreadSheet.add(new JScrollPane(spreadsheet, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, panelSpreadSheet.add(new JScrollPane(spreadsheet, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
@@ -133,31 +134,49 @@ public class CSVEditor extends JFrame {
// construct newRow // construct newRow
for (String column : columns) { for (String column : columns) {
String value = record.get(column); String value = record.get(column);
if (value == null) {
value = csvFormat.getNullString();
}
newRow.add(spreadsheet.getColumnModel().getColumnIndex(column), value); newRow.add(spreadsheet.getColumnModel().getColumnIndex(column), value);
} }
((DefaultTableModel) spreadsheet.getModel()).addRow(newRow); ((DefaultTableModel) spreadsheet.getModel()).addRow(newRow);
} }
// then add the comments
// since the Commons CSV simply ignores the comments, we have to read them on our own.
try {
StringBuilder sb = new StringBuilder();
List<String> allTheLines = Files.readAllLines(fileChooser.getSelectedFile().toPath());
allTheLines.forEach(line -> {
if (line.startsWith("" + csvFormat.getCommentMarker().toString())) {
sb.append(line);
sb.append('\n');
}
});
comment.setText(sb.toString());
}
catch (Throwable fuck) {
throw new InternalError(fuck);
}
} }
else {
// cancelled opening // if opening cancelled, do nothing
displayMessage("OPERATION_CANCELLED");
}
} }
// if discard cancelled, do nothing // if discard cancelled, do nothing
} }
}); });
add("Save").addMouseListener(new MouseAdapter() { add("Save").addMouseListener(new MouseAdapter() {
@Override @Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
System.out.println(toCSV()); System.out.println(toCSV());
} }
}); });
add("Save as…");
} }
}); });
menuBar.add(new JMenu("Edit") { menuBar.add(new JMenu("Edit") {
@@ -169,7 +188,7 @@ public class CSVEditor extends JFrame {
} }
}); });
menuBar.setSize(new Dimension(100, 18)); menuBar.revalidate();
// setup spreadsheet // // setup spreadsheet //
@@ -203,9 +222,6 @@ public class CSVEditor extends JFrame {
} }
}); });
// will fix some components not "updating" at init, with some minor consequences...?
this.repaint();
} }
public static void main(String[] args) { public static void main(String[] args) {
@@ -248,6 +264,7 @@ public class CSVEditor extends JFrame {
sb.append('"'); sb.append('"');
if (col + 1 < cols) sb.append(';'); if (col + 1 < cols) sb.append(';');
} }
sb.append("\n");
} sb.append("\n\n"); } sb.append("\n\n");
// add comments // add comments

View File

@@ -53,9 +53,10 @@ object CSVFetcher {
@Throws(java.io.IOException::class) @Throws(java.io.IOException::class)
fun readCSVasString(path: String): String { fun readCSVasString(path: String): String {
net.torvald.terrarum.utils.CSVFetcher.csvString = StringBuffer() net.torvald.terrarum.utils.CSVFetcher.csvString = StringBuffer()
java.nio.file.Files.lines(java.nio.file.FileSystems.getDefault().getPath(path)).forEach( java.nio.file.Files.lines(java.nio.file.FileSystems.getDefault().getPath(path)).forEach {
{ s -> net.torvald.terrarum.utils.CSVFetcher.csvString!!.append("$s\n") } s -> net.torvald.terrarum.utils.CSVFetcher.csvString!!.append("$s\n")
) }
return net.torvald.terrarum.utils.CSVFetcher.csvString!!.toString() return net.torvald.terrarum.utils.CSVFetcher.csvString!!.toString()
} }
} }