- Хроники
- Scions of Destiny
- Interlude
- Chaotic Throne: High Five
- Grand Cursade
- Salvation
- Fafurion
- Исходники
- Присутствуют
- Сборка
- Mobius
I realise that this is posted in the wrong section, but I could not post it in the guides section. I would kindly ask the administration to move it to the appropriate section and remove this sentence.
Greetings, folks!
Today I'll present to you a way to optimise the HTML length by up to 30%, depending on the nesting. The examples I give are taken from an old Interlude core, but the general idea is applicable to all java-based cores.
Proof of concept: The two important bits are the (1) Original HTML size row and the (4) No Tabs/Rows size row, which represent the before and after, respectively.
STEPS:
1. locate the `setHtml(String text)` method inside `NpcHtmlMessage.java`.
2. add the following bit of code as a standalone method:
3. find the last ocurence of the `text` String variable in the `setHtml()` method, and push it through this newly created method like so: `removeTabSpacesAndNewRows(text);`.
4. example of the final result.
5. You could further refine it by processing the `text` variable between the two IF clauses by creating a new local variable, assigning it a value of `text` and then replacing the subsequent `text` mentions in the `setHtml()` method with this new local var. Here's what it could look like:
UPDATE:
(thanks to @xdem for pointing it out)
You can instead apply the same logic/method to the HTMCache.java.
To do so, locate the loadFile() method and recycle the String/Text/Content through the removeTabSpacesAndNewRows() method, or just forget about the method and just copy its functionality and apply it in the loadFile() method.
KEEP IN MIND that if you will us the removeTabSpacesAndNewRows() method, it should be best if you moved it to another java class, preferrably in some UTILITY class.
Here is an example implementation:
Greetings, folks!
Today I'll present to you a way to optimise the HTML length by up to 30%, depending on the nesting. The examples I give are taken from an old Interlude core, but the general idea is applicable to all java-based cores.
Proof of concept: The two important bits are the (1) Original HTML size row and the (4) No Tabs/Rows size row, which represent the before and after, respectively.
STEPS:
1. locate the `setHtml(String text)` method inside `NpcHtmlMessage.java`.
2. add the following bit of code as a standalone method:
Java:
/**
* Replaces all occurrences of New Rows and Tab spaces in the string.
* @param text the string that may contain invalid characters
* @return the string with invalid characters removed
*/
public static String removeTabSpacesAndNewRows(String text)
{
return text.replaceAll("[\\t\\n]", "");
}
3. find the last ocurence of the `text` String variable in the `setHtml()` method, and push it through this newly created method like so: `removeTabSpacesAndNewRows(text);`.
4. example of the final result.
5. You could further refine it by processing the `text` variable between the two IF clauses by creating a new local variable, assigning it a value of `text` and then replacing the subsequent `text` mentions in the `setHtml()` method with this new local var. Here's what it could look like:
UPDATE:
(thanks to @xdem for pointing it out)
You can instead apply the same logic/method to the HTMCache.java.
To do so, locate the loadFile() method and recycle the String/Text/Content through the removeTabSpacesAndNewRows() method, or just forget about the method and just copy its functionality and apply it in the loadFile() method.
KEEP IN MIND that if you will us the removeTabSpacesAndNewRows() method, it should be best if you moved it to another java class, preferrably in some UTILITY class.
Here is an example implementation:
Последнее редактирование: