Skip to content

Commit

Permalink
added i18n support
Browse files Browse the repository at this point in the history
  • Loading branch information
khjxiaogu committed Aug 1, 2020
1 parent c475df9 commit a191cd6
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 31 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.khjxiaogu</groupId>
<artifactId>FactorioComposer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.2-SNAPSHOT</version>
<name>Factorio Composer</name>
<description>Music importer for Factorio</description>
<build>
Expand Down
60 changes: 30 additions & 30 deletions src/main/java/com/khjxiaogu/factorio/composer/FactorioComposer.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public class FactorioComposer {
SignalID.V_O,SignalID.V_P,SignalID.V_Q,SignalID.V_R,SignalID.V_S,SignalID.V_BLUE,
SignalID.V_U,SignalID.V_V,SignalID.V_W,SignalID.V_X,SignalID.V_Y,SignalID.V_Z};
public static void main(String[] args) throws Exception {
JFrame f = new JFrame("Factorio Composer by khjxiaogu");
JFrame f = new JFrame(Messages.getString("FactorioComposer.title")); //$NON-NLS-1$
f.setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.setResizable(false);
JButton button1 = new JButton("Compose folder to blueprint book");
JButton button2 = new JButton("Compose file to blueprint");
JButton button1 = new JButton(Messages.getString("FactorioComposer.fromfolder")); //$NON-NLS-1$
JButton button2 = new JButton(Messages.getString("FactorioComposer.fromfile")); //$NON-NLS-1$
button1.addActionListener(ev -> {
try {
exportBPB();
Expand All @@ -74,15 +74,15 @@ public static void main(String[] args) throws Exception {
JPanel p = new JPanel();
JPanel p2 = new JPanel();
JLabel p3=new JLabel();
p3.setText("made by khjxiaogu");
p3.setText(Messages.getString("FactorioComposer.author")); //$NON-NLS-1$
JLabel p4= new JLabel();
p4.setText("<html><a href=\"\">View code via github</html>");
p4.setText(Messages.getString("FactorioComposer.viewgithub")); //$NON-NLS-1$
p4.setCursor(new Cursor(Cursor.HAND_CURSOR));
p4.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
try {
Desktop.getDesktop().browse(new URI("https://github.com/khjxiaogu/FactorioComposer"));
Desktop.getDesktop().browse(new URI("https://github.com/khjxiaogu/FactorioComposer")); //$NON-NLS-1$
} catch (Exception ex) {
//It looks like there's a problem
}
Expand All @@ -101,22 +101,22 @@ public static void exportBPB() throws InvalidMidiDataException, IOException {
BluePrintBook bp=new BluePrintBook();
File inputFolder=chooseFolder();
if(inputFolder==null)return;
File[] fs=inputFolder.listFiles((dir, name) -> name.toLowerCase().endsWith(".mid")||name.toLowerCase().endsWith(".midi")||name.toLowerCase().endsWith(".smr"));
File[] fs=inputFolder.listFiles((dir, name) -> name.toLowerCase().endsWith(".mid")||name.toLowerCase().endsWith(".midi")||name.toLowerCase().endsWith(".smr")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
for(File f:fs) {
bp.addBluePrint(makeBluePrint(f));
}
JTextArea area = new JTextArea(10, 40);
JScrollPane pane = new JScrollPane();
area.setText(Utils.EncodeFson(bp));
JOptionPane.showOptionDialog(null,pane, "Copy Blueprint code", JOptionPane.DEFAULT_OPTION,JOptionPane.PLAIN_MESSAGE, null, null, null);
JOptionPane.showOptionDialog(null,pane, Messages.getString("FactorioComposer.copy_bp"), JOptionPane.DEFAULT_OPTION,JOptionPane.PLAIN_MESSAGE, null, null, null); //$NON-NLS-1$
}
public static void exportBP() throws InvalidMidiDataException, IOException {
File input=choose();
if(input==null)return;
JTextArea area = new JTextArea(10, 40);
JScrollPane pane = new JScrollPane();
area.setText(Utils.EncodeFson(makeBluePrint(input)));
JOptionPane.showOptionDialog(null,pane, "Copy Blueprint code", JOptionPane.DEFAULT_OPTION,JOptionPane.PLAIN_MESSAGE, null, null, null);
JOptionPane.showOptionDialog(null,pane, Messages.getString("FactorioComposer.copy_bp"), JOptionPane.DEFAULT_OPTION,JOptionPane.PLAIN_MESSAGE, null, null, null); //$NON-NLS-1$
}
public static BluePrint makeBluePrint(File input) throws InvalidMidiDataException, IOException {
MidiSheet ms=new MidiSheet(input,0,1);
Expand All @@ -127,7 +127,7 @@ public static BluePrint makeBluePrint(File input) throws InvalidMidiDataExceptio
bp.addIcon(SignalID.V_D);
toCircuit(ms,bp);
ms.Combine();
bp.setName(input.getName().substring(0,input.getName().lastIndexOf('.'))+" - "+(ms.tracks.get(0).getNote(ms.tracks.get(0).getSize()-1).ticks+20)+"tick");
bp.setName(input.getName().substring(0,input.getName().lastIndexOf('.'))+" - "+(ms.tracks.get(0).getNote(ms.tracks.get(0).getSize()-1).ticks+20)+Messages.getString("FactorioComposer.tick")); //$NON-NLS-1$ //$NON-NLS-2$
return bp;
}
public static void toCircuit(MidiSheet ms,BluePrint bp) {
Expand Down Expand Up @@ -183,20 +183,20 @@ public static void toCircuit(MidiSheet ms,BluePrint bp) {
sp.setVolume(0.4F);
sp.setGlobally(true);
sp.setPolyphony(true);
sp.setCond(new CircuitCondition(SignalID.V_ANY,0,">"));
sp.setCond(new CircuitCondition(SignalID.V_ANY,0,">")); //$NON-NLS-1$
if(addLights) {
DeciderCombinator lc=new DeciderCombinator(cx,-2.5F);
bp.addEntity(lc);
lc.setOutput(SignalID.V_L);
lc.setCopycount(false);
lc.setDirection(0);
lc.setCond(new CircuitCondition(SignalID.V_ANY,0,">"));
lc.setCond(new CircuitCondition(SignalID.V_ANY,0,">")); //$NON-NLS-1$
lc.connect(1,sp,1, true);
lc.connect(1,sp,1, false);
Light lit=new Light(cx,-5F);
bp.addEntity(lit);
lit.setUseColor(true);
lit.setCond(new CircuitCondition(SignalID.V_L,0,">"));
lit.setCond(new CircuitCondition(SignalID.V_L,0,">")); //$NON-NLS-1$
lit.connect(1,lc,2,true);
lit.connect(1,clr,1,false);
last=lit;
Expand Down Expand Up @@ -232,20 +232,20 @@ public static void toCircuit(MidiSheet ms,BluePrint bp) {
sp.setVolume(0.8F);
sp.setGlobally(true);
sp.setPolyphony(true);
sp.setCond(new CircuitCondition(SignalID.V_ANY,0,">"));
sp.setCond(new CircuitCondition(SignalID.V_ANY,0,">")); //$NON-NLS-1$
if(addLights) {
DeciderCombinator lc=new DeciderCombinator(cx,-2.5F);
bp.addEntity(lc);
lc.setOutput(SignalID.V_L);
lc.setCopycount(false);
lc.setDirection(0);
lc.setCond(new CircuitCondition(SignalID.V_ANY,0,">"));
lc.setCond(new CircuitCondition(SignalID.V_ANY,0,">")); //$NON-NLS-1$
lc.connect(1,sp,1, true);
lc.connect(1,sp,1, false);
Light lit=new Light(cx,-5F);
bp.addEntity(lit);
lit.setUseColor(true);
lit.setCond(new CircuitCondition(SignalID.V_L,0,">"));
lit.setCond(new CircuitCondition(SignalID.V_L,0,">")); //$NON-NLS-1$
lit.connect(1,lc,2,true);
if(last!=null)
last.connect(1,lit,1,false);
Expand All @@ -268,20 +268,20 @@ public static void toCircuit(MidiSheet ms,BluePrint bp) {
sp.setVolume(0.7F);
sp.setGlobally(true);
sp.setPolyphony(true);
sp.setCond(new CircuitCondition(SignalID.V_ANY,0,">"));
sp.setCond(new CircuitCondition(SignalID.V_ANY,0,">")); //$NON-NLS-1$
if(addLights) {
DeciderCombinator lc=new DeciderCombinator(cx,-2.5F);
bp.addEntity(lc);
lc.setOutput(SignalID.V_L);
lc.setCopycount(false);
lc.setDirection(0);
lc.setCond(new CircuitCondition(SignalID.V_ANY,0,">"));
lc.setCond(new CircuitCondition(SignalID.V_ANY,0,">")); //$NON-NLS-1$
lc.connect(1,sp,1, true);
lc.connect(1,sp,1, false);
Light lit=new Light(cx,-5F);
bp.addEntity(lit);
lit.setUseColor(true);
lit.setCond(new CircuitCondition(SignalID.V_L,0,">"));
lit.setCond(new CircuitCondition(SignalID.V_L,0,">")); //$NON-NLS-1$
lit.connect(1,lc,2,true);
if(last!=null)
last.connect(1,lit,1,false);
Expand All @@ -301,15 +301,15 @@ private static BaseEntity makeTrack(BluePrint bp,int cx,Set<Integer> track) {
DeciderCombinator last=fd;
last.setCopycount(true);
last.setOutput(SignalID.V_EACH);
last.setCond(new CircuitCondition(SignalID.V_EACH,SignalID.V_T,"="));
last.setCond(new CircuitCondition(SignalID.V_EACH,SignalID.V_T,"=")); //$NON-NLS-1$
for(Integer tick:track) {
if(num==sids.length) {
DeciderCombinator cd=new DeciderCombinator(cx,cy+0.5F);
cd.setDirection(0);
cy+=2;
cd.setCopycount(true);
cd.setOutput(SignalID.V_EACH);
cd.setCond(new CircuitCondition(SignalID.V_EACH,SignalID.V_T,"="));
cd.setCond(new CircuitCondition(SignalID.V_EACH,SignalID.V_T,"=")); //$NON-NLS-1$
bp.addEntity(cd);
cd.connect(1,last,1,false);
cd.connect(2,last,2,true);
Expand Down Expand Up @@ -345,7 +345,7 @@ public static void toSpeakers(MidiSheet ms,BluePrint bp) {
continue;
}
if((note.key<41&&Math.abs(lastmin-note.ticks)<5)||(note.key>112&&Math.abs(lastmax-note.ticks)<5)) {
System.out.println("repeat illegal notes found");
System.out.println("repeat illegal notes found"); //$NON-NLS-1$
mainTrack.remove(i);
i--;
continue;
Expand All @@ -360,7 +360,7 @@ public static void toSpeakers(MidiSheet ms,BluePrint bp) {
}else if(lsp!=null) {
sp.connect(1,lsp,1,true);
}
sp.setCond(new CircuitCondition(SignalID.V_T,(int)note.ticks+10,"="));
sp.setCond(new CircuitCondition(SignalID.V_T,(int)note.ticks+10,"=")); //$NON-NLS-1$
sp.setGlobally(true);
int nid=note.key-53;
if(nid<0) {
Expand All @@ -370,7 +370,7 @@ public static void toSpeakers(MidiSheet ms,BluePrint bp) {
sp.setInstrumentID(2);
sp.setNoteID(1);
lastmin=(int) note.ticks;
System.out.println("too low,use drum instead");
System.out.println("too low,use drum instead"); //$NON-NLS-1$
}else {
sp.setNoteID(nid);
sp.setInstrumentID(4);
Expand All @@ -382,7 +382,7 @@ public static void toSpeakers(MidiSheet ms,BluePrint bp) {
sp.setInstrumentID(2);
sp.setNoteID(16);
lastmax=(int) note.ticks;
System.out.println("too high,use bell instead");
System.out.println("too high,use bell instead"); //$NON-NLS-1$
}else {
sp.setInstrumentID(8);
sp.setNoteID(nid);
Expand All @@ -404,18 +404,18 @@ public static void toSpeakers(MidiSheet ms,BluePrint bp) {
}

public static File choose() {
JFileChooser jfc = new JFileChooser(new File("./"));
jfc.setDialogTitle("Select midi file");
FileNameExtensionFilter restrict = new FileNameExtensionFilter("midi file","mid", "midi","smr");
JFileChooser jfc = new JFileChooser(new File("./")); //$NON-NLS-1$
jfc.setDialogTitle(Messages.getString("FactorioComposer.selectfile")); //$NON-NLS-1$
FileNameExtensionFilter restrict = new FileNameExtensionFilter(Messages.getString("FactorioComposer.file"),"mid", "midi","smr"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
jfc.setAcceptAllFileFilterUsed(false);
jfc.addChoosableFileFilter(restrict);
if (jfc.showOpenDialog(null) != JFileChooser.APPROVE_OPTION)
return null;
return jfc.getSelectedFile();
}
public static File chooseFolder() {
JFileChooser jfc = new JFileChooser();
jfc.setDialogTitle("Select midi folder");
JFileChooser jfc = new JFileChooser(new File("./")); //$NON-NLS-1$
jfc.setDialogTitle(Messages.getString("FactorioComposer.selectfolder")); //$NON-NLS-1$
jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
jfc.setAcceptAllFileFilterUsed(false);
if (jfc.showOpenDialog(null) != JFileChooser.APPROVE_OPTION)
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/khjxiaogu/factorio/composer/Messages.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.khjxiaogu.factorio.composer;

import java.util.MissingResourceException;
import java.util.ResourceBundle;

public class Messages {
private static final String BUNDLE_NAME = "com.khjxiaogu.factorio.composer.messages"; //$NON-NLS-1$

private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);

private Messages() {
}

public static String getString(String key) {
try {
return RESOURCE_BUNDLE.getString(key);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/khjxiaogu/factorio/composer/messages.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FactorioComposer.author=made by khjxiaogu
FactorioComposer.copy_bp=Copy Blueprint code
FactorioComposer.file=midi file
FactorioComposer.fromfile=Compose file to blueprint
FactorioComposer.fromfolder=Compose folder to blueprint book
FactorioComposer.selectfile=Select midi file
FactorioComposer.selectfolder=Select midi folder
FactorioComposer.tick=tick
FactorioComposer.title=Factorio Composer by khjxiaogu
FactorioComposer.viewgithub=<html><a href="">View code via github</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FactorioComposer.author=khj\u5C0F\u9AA8\u5236\u4F5C
FactorioComposer.copy_bp=\u590D\u5236\u84DD\u56FE\u4EE3\u7801
FactorioComposer.file=midi\u6587\u4EF6
FactorioComposer.fromfile=\u5BFC\u5165\u6587\u4EF6\u5230\u84DD\u56FE
FactorioComposer.fromfolder=\u5BFC\u5165\u6587\u4EF6\u5939\u5230\u84DD\u56FE\u7C3F
FactorioComposer.selectfile=\u9009\u62E9midi\u6587\u4EF6
FactorioComposer.selectfolder=\u9009\u62E9midi\u6587\u4EF6\u5939
FactorioComposer.tick=ticks
FactorioComposer.title=\u5F02\u661F\u5DE5\u5382\u97F3\u4E50\u751F\u6210\u5668by khj\u5C0F\u9AA8
FactorioComposer.viewgithub=<html><a href="">\u5728github\u4E0A\u67E5\u770B\u4EE3\u7801</html>

0 comments on commit a191cd6

Please sign in to comment.