From 3b2c38cf0b288c7ffe5ef0d3edc43eceb85e9686 Mon Sep 17 00:00:00 2001 From: Minjae Song Date: Wed, 2 Jan 2019 22:23:48 +0900 Subject: [PATCH] csv reader can read file, stringify (not real save) and read the save itself wrote --- assets/mods/basegame/blocks/blocks.csv | 41 ++++++++++--------- assets/mods/basegame/blocks/blocks_old.csv | 41 ++++++++++--------- .../terrarum/debuggerapp/CSVEditor.java | 41 +++++++++++++------ src/net/torvald/terrarum/utils/CSVFetcher.kt | 7 ++-- 4 files changed, 75 insertions(+), 55 deletions(-) diff --git a/assets/mods/basegame/blocks/blocks.csv b/assets/mods/basegame/blocks/blocks.csv index 47e1924b6..7a855b38b 100644 --- a/assets/mods/basegame/blocks/blocks.csv +++ b/assets/mods/basegame/blocks/blocks.csv @@ -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" ## Notes ## - +# # Lava/Water props are left for future references, do not delete them until FluidCodex is built # - +# # id: Block ID # drop: Drop ID - +# # shdr/g/b, lumr/g/b: Shade RGB/ Lum RGB. # 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) # 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) - +# # 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 - +# # dsty: density. As we are putting water an 1000, it is identical to specific gravity. [g/l] - +# # dlfn: dynamic luminosity function. # 0-static, 1-torch flicker, 2-current global light (sun, star, moon), 3-daylight at noon, # 4-slow breath, 5-pulsate - +# # mate: material, four-letter code - +# # fv: vertical friction (boolean) # fr: horizontal friction. 0: frictionless, <16: slippery, 16: regular, >16: sticky - - +# +# ## 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 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!) # 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. - +# # BLOCK_ILLUMINATOR_CYAN is actually a SUPER_LUMINATOR, cyan colour is used as: # 1. It has quite a brightness on RGB colour space # 2. Helmholz-Kohlraush effect - - +# +# ## Tiles ## - +# # 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. - - +# +# ## References ## - +# # * 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 +# \ No newline at end of file diff --git a/assets/mods/basegame/blocks/blocks_old.csv b/assets/mods/basegame/blocks/blocks_old.csv index 47e1924b6..7a855b38b 100644 --- a/assets/mods/basegame/blocks/blocks_old.csv +++ b/assets/mods/basegame/blocks/blocks_old.csv @@ -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" ## Notes ## - +# # Lava/Water props are left for future references, do not delete them until FluidCodex is built # - +# # id: Block ID # drop: Drop ID - +# # shdr/g/b, lumr/g/b: Shade RGB/ Lum RGB. # 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) # 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) - +# # 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 - +# # dsty: density. As we are putting water an 1000, it is identical to specific gravity. [g/l] - +# # dlfn: dynamic luminosity function. # 0-static, 1-torch flicker, 2-current global light (sun, star, moon), 3-daylight at noon, # 4-slow breath, 5-pulsate - +# # mate: material, four-letter code - +# # fv: vertical friction (boolean) # fr: horizontal friction. 0: frictionless, <16: slippery, 16: regular, >16: sticky - - +# +# ## 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 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!) # 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. - +# # BLOCK_ILLUMINATOR_CYAN is actually a SUPER_LUMINATOR, cyan colour is used as: # 1. It has quite a brightness on RGB colour space # 2. Helmholz-Kohlraush effect - - +# +# ## Tiles ## - +# # 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. - - +# +# ## References ## - +# # * 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 +# \ No newline at end of file diff --git a/src/net/torvald/terrarum/debuggerapp/CSVEditor.java b/src/net/torvald/terrarum/debuggerapp/CSVEditor.java index bf3914ff8..997245d6f 100644 --- a/src/net/torvald/terrarum/debuggerapp/CSVEditor.java +++ b/src/net/torvald/terrarum/debuggerapp/CSVEditor.java @@ -13,6 +13,7 @@ import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.StringReader; +import java.nio.file.Files; import java.util.List; import java.util.Properties; import java.util.Vector; @@ -76,7 +77,7 @@ public class CSVEditor extends JFrame { comment.setVisible(true); 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(new JScrollPane(spreadsheet, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, @@ -133,31 +134,49 @@ public class CSVEditor extends JFrame { // construct newRow for (String column : columns) { String value = record.get(column); + if (value == null) { + value = csvFormat.getNullString(); + } newRow.add(spreadsheet.getColumnModel().getColumnIndex(column), value); } ((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 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 - displayMessage("OPERATION_CANCELLED"); - } + + // if opening cancelled, do nothing } // if discard cancelled, do nothing } }); - add("Save").addMouseListener(new MouseAdapter() { + add("Save…").addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { System.out.println(toCSV()); } }); - - add("Save as…"); } }); menuBar.add(new JMenu("Edit") { @@ -169,7 +188,7 @@ public class CSVEditor extends JFrame { } }); - menuBar.setSize(new Dimension(100, 18)); + menuBar.revalidate(); // 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) { @@ -248,6 +264,7 @@ public class CSVEditor extends JFrame { sb.append('"'); if (col + 1 < cols) sb.append(';'); } + sb.append("\n"); } sb.append("\n\n"); // add comments diff --git a/src/net/torvald/terrarum/utils/CSVFetcher.kt b/src/net/torvald/terrarum/utils/CSVFetcher.kt index b4d344715..4601fa9d3 100644 --- a/src/net/torvald/terrarum/utils/CSVFetcher.kt +++ b/src/net/torvald/terrarum/utils/CSVFetcher.kt @@ -53,9 +53,10 @@ object CSVFetcher { @Throws(java.io.IOException::class) fun readCSVasString(path: String): String { net.torvald.terrarum.utils.CSVFetcher.csvString = StringBuffer() - java.nio.file.Files.lines(java.nio.file.FileSystems.getDefault().getPath(path)).forEach( - { s -> net.torvald.terrarum.utils.CSVFetcher.csvString!!.append("$s\n") } - ) + java.nio.file.Files.lines(java.nio.file.FileSystems.getDefault().getPath(path)).forEach { + s -> net.torvald.terrarum.utils.CSVFetcher.csvString!!.append("$s\n") + } + return net.torvald.terrarum.utils.CSVFetcher.csvString!!.toString() } }