Brute force code for Chat autologging

Progress reports and musings from the developers on the current gaming tools.

Moderators: dorpond, trevor, Azhrei

Post Reply
Dyriam
Kobold
Posts: 2
Joined: Fri Nov 06, 2009 8:45 am

Brute force code for Chat autologging

Post by Dyriam »

Hello.
This is my first contribution to this forum. After waiting for some time to see the chat autologging feature functional on MapTool and since I make extensive use of it, I decided to try and implement it myself. My understanding of Java is quite limited, I just copied what was already there. The code is quite straightforward and lacks any finesse, but it works and hopefully it can be improved by some kind java expert out there.
Since this is a feature that many users are requesting, I thought I would publish my contribution. It works fine for my gaming group on Windows Vista and XP on new PC's for a normal gaming session, with no noticeable slowdown. I have no idea how it will run on slower machines or very long gaming sessions.
The crude idea is just to flush the whole message history into a fixed log file everytime a new message is added. Currently, the log file is erased when MapTool is loaded anew and the first text is entered on the message panel, but otherwise it will be constantly updated to contain the whole current session. Just remember to make a copy of it when you close MapTools or it will be wiped in the next session!

To add this feature you have to edit the messagePanel.java file go to the end of the addMessage method (scroll directly to the end of the file) . After the last bit of code:

// if rolls not being visible to this user result in an empty message, display nothing
if (!output.matches(".*\002\\s*\003.*")) {
output = output.replaceAll("\002|\003", "");
try {
Element element = document.getElement("body");
document.insertBeforeEnd(element, "<div>" + output + "</div>");
if (!message.getSource().equals(MapTool.getPlayer().getName())) {
MapTool.playSound(SND_MESSAGE_RECEIVED);
}
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (BadLocationException ble) {
ble.printStackTrace();
}
}


Insert this other bit of code:

String messageHistory = MapTool.getFrame().getCommandPanel().getMessageHistory();
File saveFile = new File("c:\\Program Files\\MapTool\\logs\\log.html");
try {
FileUtil.writeBytes(saveFile, messageHistory.getBytes());
} catch (IOException ioe) {
}


This will create the logfile in the path c:\Program Files\MapTool\logs\log.html. If you wish to change the path, just give the file constructor a different argument.

Possible improvements are to create the log path relative to the MapTool path and give the file a different name depending on the current date, much like OpenRPG does. My first attempts failed to actually create a new logfile at 0:00 when the day changed, so I went back to the fixed filename.

I uploaded a functional modification of the program (version .61) in Megaupload, which drops the log file in c:\Archivos de Programa\MapTool\logs\log.html, in case anyone wants to test it and doesn't want to bother adding the code and compiling the whole thing over again.
Here's the link: http://www.megaupload.com/?d=52R8XS53

Hope this helps.

As a side note, using this log file for readback on rolls, I have been able to create character sheets on Excel Spreadsheets that automate most of the RP functions. For example, hitting the Full Attack button in the Excel character sheet will calculate the modified attack bonuses, make the attack rolls on MapTools, check if a target AC was hit, check the critical range and roll the criticals if appropriate, add the damage of the blows that hit and show it back on MapTools, indicating how much damage was slash, fire, etc.
If it's not too off-topic, I will be posting a sample of this in the ideas for new tools forum soon.

User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: Brute force code for Chat autologging

Post by Azhrei »

Welcome to RPTools, Dyriam!

If you would like to contribute to MapTool, please read the "Developer's Guide" thread in the main forum. It has information about how to format code that you wish to contribute as well as some general style guidelines. In addition, while the community might be interested in a particular patch and try it out on their own, the overall "guiding light" of development is handled by Trevor and any patches that get merged into the main trunk of the code must be approved by him.

That said, I appreciate you taking the time to make these changes. Unfortunately, this is a rather brute force approach and won't scale well when the chat log gets large. For small chat windows this is probably fine, but for those people using a framework that creates extensive HTML to represent attacks (including some very sophisticated tooltips) rewriting the log file on every message will be way too much overhead.

The preferred implementation would be to write the chat log out periodically, keeping track of the size of the log so that the next time the log is written, only the new information needs to be appended to the existing log file. (That's why the preferences page has a field to enter the duration between saves.)

This means tying the autosave into the existing timer structure in MapTool. I had sent Trevor some questions about how he wanted this implemented, but I haven't gotten a response yet -- I'll send him another PM.
If it's not too off-topic, I will be posting a sample of this in the ideas for new tools forum soon.
The New Tools forum is for new tool ideas for the RPTools team. This sounds like a user-contributed utility so it should probably be in the User Creations forum instead. Or in Links & External Resources if you decide to just post a link to it rather than get into a lot of discussion about it.

Thanks for helping out!

User avatar
Sir Flak
Dragon
Posts: 344
Joined: Thu Sep 28, 2006 4:20 pm
Location: Oklahoma, US

Re: Brute force code for Chat autologging

Post by Sir Flak »

Dyriam wrote: As a side note, using this log file for readback on rolls, I have been able to create character sheets on Excel Spreadsheets that automate most of the RP functions. For example, hitting the Full Attack button in the Excel character sheet will calculate the modified attack bonuses, make the attack rolls on MapTools, check if a target AC was hit, check the critical range and roll the criticals if appropriate, add the damage of the blows that hit and show it back on MapTools, indicating how much damage was slash, fire, etc.
If it's not too off-topic, I will be posting a sample of this in the ideas for new tools forum soon.
This sounds kewl, I'd like to hear more about it. I've been thinking for a while how to hook-in an external character sheet program that can send rolls/etc into maptool. It'd run so much smoother in a little program compiled to be the character sheet than parsing stuff on the fly all the time.

Post Reply

Return to “Developer Notes”