Finished text parser
This commit is contained in:
parent
d439ac92fc
commit
832ed15060
11 changed files with 323 additions and 127 deletions
|
@ -1,14 +1,21 @@
|
|||
package WayofTime.alchemicalWizardry;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
|
@ -254,6 +261,8 @@ import cpw.mods.fml.common.registry.GameRegistry;
|
|||
|
||||
public class AlchemicalWizardry
|
||||
{
|
||||
public static boolean parseTextFiles = true;
|
||||
|
||||
public static boolean doMeteorsDestroyBlocks = true;
|
||||
public static String[] diamondMeteorArray;
|
||||
public static int diamondMeteorRadius;
|
||||
|
@ -399,7 +408,9 @@ public class AlchemicalWizardry
|
|||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
{
|
||||
|
||||
|
||||
File bmDirectory = new File("config/BloodMagic/schematics");
|
||||
|
||||
if (!bmDirectory.exists() && bmDirectory.mkdirs())
|
||||
|
@ -1089,6 +1100,9 @@ public class AlchemicalWizardry
|
|||
|
||||
BloodMagicConfiguration.loadBlacklist();
|
||||
BloodMagicConfiguration.blacklistRituals();
|
||||
|
||||
if(parseTextFiles)
|
||||
this.parseTextFile();
|
||||
}
|
||||
|
||||
public static void initAlchemyPotionRecipes()
|
||||
|
@ -1316,4 +1330,164 @@ public class AlchemicalWizardry
|
|||
|
||||
CompressionRegistry.registerItemThreshold(new ItemStack(Blocks.cobblestone), 64);
|
||||
}
|
||||
|
||||
public void parseTextFile()
|
||||
{
|
||||
File textFiles = new File("config/BloodMagic/bookDocs");
|
||||
//if(textFiles.exists())
|
||||
{
|
||||
try {
|
||||
System.out.println("I am in an island of files!");
|
||||
|
||||
InputStream input = AlchemicalWizardry.class.getResourceAsStream("/assets/alchemicalwizardryBooks/books/book.txt");
|
||||
|
||||
Minecraft.getMinecraft().fontRenderer.setUnicodeFlag(true);
|
||||
|
||||
if(input != null)
|
||||
{
|
||||
DataInputStream in = new DataInputStream(input);
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
||||
String strLine;
|
||||
//Read File Line By Line
|
||||
|
||||
int maxWidth = 25;
|
||||
int maxLines = 16;
|
||||
|
||||
int currentPage = 0;
|
||||
|
||||
int pageIndex = 1;
|
||||
|
||||
String currentTitle = "aw.entry.Magnus";
|
||||
|
||||
String[] strings = new String[1];
|
||||
strings[0] = "";
|
||||
|
||||
while ((strLine = br.readLine()) != null)
|
||||
{
|
||||
if(strLine.trim().isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(strLine.startsWith("//TITLE "))
|
||||
{
|
||||
String[] newStrings = new String[currentPage + 1 + 1]; //Just to show that it is increasing
|
||||
for(int i=0; i<strings.length; i++)
|
||||
{
|
||||
newStrings[i] = strings[i];
|
||||
}
|
||||
|
||||
currentPage++;
|
||||
newStrings[currentPage - 1] = currentTitle + "." + pageIndex + "=" + newStrings[currentPage - 1];
|
||||
newStrings[currentPage] = "";
|
||||
strings = newStrings;
|
||||
|
||||
pageIndex = 1;
|
||||
|
||||
String title = strLine.replaceFirst("//TITLE ", " ").trim();
|
||||
currentTitle = "aw.entry." + title;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
strLine = strLine.replace('”', '"').replace('“','"');
|
||||
|
||||
if(Minecraft.getMinecraft() != null && Minecraft.getMinecraft().fontRenderer != null)
|
||||
{
|
||||
List list = Minecraft.getMinecraft().fontRenderer.listFormattedStringToWidth(strLine, 110);
|
||||
if(list != null)
|
||||
{
|
||||
System.out.println("Number of lines: " + list.size());
|
||||
}
|
||||
}
|
||||
|
||||
String[] cutStrings = strLine.split(" ");
|
||||
|
||||
for(String word : cutStrings)
|
||||
{
|
||||
boolean changePage = false;
|
||||
int length = word.length();
|
||||
word = word.replace('\t', ' ');
|
||||
List list = Minecraft.getMinecraft().fontRenderer.listFormattedStringToWidth(strings[currentPage] + " " + word, 110);
|
||||
|
||||
// if(currentWidth != 0 && currentWidth + length + 1 > maxWidth)
|
||||
// {
|
||||
// currentLine++;
|
||||
// currentWidth = 0;
|
||||
// }
|
||||
//if(currentLine > maxLines)
|
||||
if(list.size() > maxLines)
|
||||
{
|
||||
changePage = true;
|
||||
}
|
||||
if(changePage)
|
||||
{
|
||||
String[] newStrings = new String[currentPage + 1 + 1]; //Just to show that it is increasing
|
||||
for(int i=0; i<strings.length; i++)
|
||||
{
|
||||
newStrings[i] = strings[i];
|
||||
}
|
||||
|
||||
currentPage++;
|
||||
|
||||
newStrings[currentPage - 1] = currentTitle + "." + pageIndex + "=" + newStrings[currentPage - 1];
|
||||
newStrings[currentPage] = word;
|
||||
strings = newStrings;
|
||||
|
||||
pageIndex++;
|
||||
|
||||
changePage = false;
|
||||
}else
|
||||
{
|
||||
strings[currentPage] = strings[currentPage] + " " + word;
|
||||
}
|
||||
}
|
||||
|
||||
int currentLines = Minecraft.getMinecraft().fontRenderer.listFormattedStringToWidth(strings[currentPage], 110).size();
|
||||
while(Minecraft.getMinecraft().fontRenderer.listFormattedStringToWidth(strings[currentPage] + " ", 110).size() <= currentLines)
|
||||
{
|
||||
{
|
||||
strings[currentPage] = strings[currentPage] + " ";
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("" + strLine);
|
||||
}
|
||||
|
||||
strings[currentPage] = currentTitle + "." + pageIndex + "=" + strings[currentPage];
|
||||
|
||||
File bmDirectory = new File("src/main/resources/assets/alchemicalwizardryBooks");
|
||||
if(!bmDirectory.exists())
|
||||
{
|
||||
bmDirectory.mkdirs();
|
||||
}
|
||||
|
||||
File file = new File(bmDirectory, "books.txt");
|
||||
// if (file.exists() && file.length() > 3L)
|
||||
// {
|
||||
//
|
||||
// }else
|
||||
{
|
||||
PrintWriter writer = new PrintWriter(file);
|
||||
for(String stri : strings)
|
||||
{
|
||||
writer.println(stri);
|
||||
}
|
||||
writer.close();
|
||||
}
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
Minecraft.getMinecraft().fontRenderer.setUnicodeFlag(false);
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,8 +79,9 @@ public class GuiIndex extends GuiScreen{
|
|||
|
||||
if(entries != null && !entries.isEmpty()){
|
||||
int j = 0;
|
||||
for(int i = 0; i < entries.size(); i++){
|
||||
Entry entry = (Entry)entries.values().toArray()[i];
|
||||
Entry[] entryList = EntryRegistry.getEntriesInOrderForCategory(category);
|
||||
for(int i = 0; i < entryList.length; i++){
|
||||
Entry entry = entryList[i];
|
||||
if(entry != null && entry.indexPage == this.currPage){
|
||||
x = this.left + gwidth / 2 - 75;
|
||||
y = (top + 15) + (10*j);
|
||||
|
@ -125,11 +126,13 @@ public class GuiIndex extends GuiScreen{
|
|||
}
|
||||
|
||||
public void registerButtons(){
|
||||
HashMap<String, Entry> entries = EntryRegistry.entries.get(this.category);
|
||||
HashMap<String, Entry> entries = EntryRegistry.entries.get(this.category);
|
||||
|
||||
if(entries != null && !entries.isEmpty()){
|
||||
Entry[] entryList = EntryRegistry.getEntriesInOrderForCategory(category);
|
||||
int j = 0;
|
||||
for(int i = 0; i < entries.size(); i++){
|
||||
Entry entry = (Entry)entries.values().toArray()[i];
|
||||
for(int i = 0; i < entryList.length; i++){
|
||||
Entry entry = entryList[i];
|
||||
|
||||
if(entry != null && entry.indexPage == this.currPage){
|
||||
String title = entry.name;
|
||||
|
|
|
@ -25,7 +25,7 @@ public class EntryText implements IEntry{
|
|||
if(this.entryName == null)
|
||||
this.entryName = key;
|
||||
|
||||
String s = StatCollector.translateToLocal("bu.entry." + this.entryName + "." + page);
|
||||
String s = StatCollector.translateToLocal("aw.entry." + this.entryName + "." + page);
|
||||
x = left + width / 2 - 58;
|
||||
y = (top + 15);
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package WayofTime.alchemicalWizardry.book.interfaces;
|
||||
|
||||
import WayofTime.alchemicalWizardry.book.compact.Entry;
|
||||
|
||||
public class StringEntry
|
||||
{
|
||||
public String str;
|
||||
public Entry entry;
|
||||
public StringEntry(String str, Entry ent)
|
||||
{
|
||||
this.str = str;
|
||||
this.entry = ent;
|
||||
}
|
||||
}
|
|
@ -2,24 +2,31 @@ package WayofTime.alchemicalWizardry.book.registries;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import WayofTime.alchemicalWizardry.book.compact.Category;
|
||||
import WayofTime.alchemicalWizardry.book.compact.Entry;
|
||||
|
||||
public class EntryRegistry {
|
||||
public static void registerCategories(Category category){
|
||||
public class EntryRegistry
|
||||
{
|
||||
public static void registerCategories(Category category)
|
||||
{
|
||||
categories.add(category);
|
||||
categoryMap.put(category.name, category);
|
||||
entryOrder.put(category, new ArrayList());
|
||||
categoryCount++;
|
||||
}
|
||||
public static ArrayList<Category> categories = new ArrayList<Category>();
|
||||
public static HashMap<Category, List<String>> entryOrder = new HashMap();
|
||||
public static HashMap<String, Category> categoryMap = new HashMap<String, Category>();
|
||||
|
||||
public static int categoryCount = 0;
|
||||
|
||||
public static void registerEntry(Category category, HashMap<String, Entry> entryMap, Entry entry){
|
||||
public static void registerEntry(Category category, HashMap<String, Entry> entryMap, Entry entry)
|
||||
{
|
||||
entryMap.put(entry.name, entry);
|
||||
entries.put(category, entryMap);
|
||||
entryOrder.get(category).add(entry.name);
|
||||
|
||||
if(maxEntries.containsKey(category) && entry.indexPage > maxEntries.get(category))
|
||||
maxEntries.put(category, entry.indexPage);
|
||||
|
@ -36,4 +43,26 @@ public class EntryRegistry {
|
|||
public static HashMap<String, Entry> rituals = new HashMap<String, Entry>();
|
||||
public static HashMap<String, Entry> bloodUtils = new HashMap<String, Entry>();
|
||||
|
||||
public static Entry[] getEntriesInOrderForCategory(Category category)
|
||||
{
|
||||
HashMap<String, Entry> entries = EntryRegistry.entries.get(category);
|
||||
List<String> nameList = entryOrder.get(category);
|
||||
|
||||
ArrayList<Entry> list = new ArrayList<Entry>();
|
||||
|
||||
for(String str : nameList)
|
||||
{
|
||||
list.add(entries.get(str));
|
||||
}
|
||||
|
||||
Object[] entriesList = list.toArray();
|
||||
Entry[] entryList = new Entry[entriesList.length];
|
||||
|
||||
for(int i=0; i<entriesList.length; i++)
|
||||
{
|
||||
entryList[i] = (Entry)(entriesList[i]);
|
||||
}
|
||||
|
||||
return entryList;
|
||||
}
|
||||
}
|
|
@ -38,6 +38,11 @@ public class BUEntries
|
|||
}
|
||||
|
||||
public void initEntries(){
|
||||
rIntro = new Entry(new IEntry[]{new EntryText(), new EntryText(), new EntryText()}, "Introduction", 1);
|
||||
rWeakRituals = new Entry(new IEntry[]{new EntryText(), new EntryText(), new EntryText(), new EntryText()}, "Weak Rituals", 1);
|
||||
rRituals = new Entry(new IEntry[]{new EntryText(), new EntryText(), new EntryText(), new EntryText()}, "Rituals", 1);
|
||||
|
||||
|
||||
theAltar = new Entry(new IEntry[]{new EntryItemText(new ItemStack(ModBlocks.blockAltar), "Blood Altar")}, EnumChatFormatting.BLUE + "Blood Altar", 1);
|
||||
runes = new Entry(new IEntry[]{new EntryItemText(new ItemStack(ModBlocks.runeOfSelfSacrifice)), new EntryItemText(new ItemStack(ModBlocks.runeOfSacrifice)), new EntryItemText(new ItemStack(ModBlocks.speedRune))}, "Runes", 1);
|
||||
|
||||
|
@ -55,7 +60,7 @@ public class BUEntries
|
|||
ritualRegeneration = new Entry(new IEntry[]{new EntryText(), new EntryText(), new EntryText()}, "Regeneration", 1);
|
||||
ritualFeatheredKnife = new Entry(new IEntry[]{new EntryText(), new EntryText(), new EntryText(), new EntryText()}, "Feathered Knife", 1);
|
||||
ritualMoon = new Entry(new IEntry[]{new EntryText()}, "Harvest Moon", 1);
|
||||
ritualSoul = new Entry(new IEntry[]{new EntryText(), new EntryText()}, "Eternal Soul", 1);
|
||||
ritualSoul = new Entry(new IEntry[]{new EntryText(), new EntryText()}, "Eternal Soul", 2);
|
||||
|
||||
ritualCure = new Entry(new IEntry[]{new EntryText(), new EntryRitualInfo(500)}, "Curing", 1);
|
||||
// blockDivination = new Entry(new IEntry[]{new EntryItemText(new ItemStack(BUBlocks.altarProgress)), new EntryCraftingRecipe(BURecipes.altarProgress)}, "Divination Block", 1);
|
||||
|
@ -68,6 +73,10 @@ public class BUEntries
|
|||
debug = new Entry(new IEntry[]{new EntryText("Debug"), new EntryImage("bloodutils:textures/misc/screenshots/t1.png", 854, 480, "Debug")}, EnumChatFormatting.AQUA + "De" + EnumChatFormatting.RED + "bug", 1);
|
||||
registerEntries();
|
||||
}
|
||||
public static Entry rIntro;
|
||||
public static Entry rWeakRituals;
|
||||
public static Entry rRituals;
|
||||
|
||||
public static Entry theAltar;
|
||||
public static Entry runes;
|
||||
|
||||
|
@ -96,9 +105,16 @@ public class BUEntries
|
|||
public static Entry debug;
|
||||
|
||||
public void registerEntries(){
|
||||
|
||||
EntryRegistry.registerEntry(BUEntries.categoryBasics, EntryRegistry.basics, BUEntries.theAltar);
|
||||
EntryRegistry.registerEntry(BUEntries.categoryBasics, EntryRegistry.basics, BUEntries.runes);
|
||||
|
||||
EntryRegistry.registerEntry(BUEntries.categoryRituals, EntryRegistry.rituals, BUEntries.rIntro);
|
||||
EntryRegistry.registerEntry(BUEntries.categoryRituals, EntryRegistry.rituals, BUEntries.rWeakRituals);
|
||||
EntryRegistry.registerEntry(BUEntries.categoryRituals, EntryRegistry.rituals, BUEntries.rRituals);
|
||||
|
||||
|
||||
|
||||
EntryRegistry.registerEntry(BUEntries.categoryRituals, EntryRegistry.rituals, BUEntries.ritualWater);
|
||||
EntryRegistry.registerEntry(BUEntries.categoryRituals, EntryRegistry.rituals, BUEntries.ritualLava);
|
||||
EntryRegistry.registerEntry(BUEntries.categoryRituals, EntryRegistry.rituals, BUEntries.ritualGreenGrove);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue