I want to create mod

Development information and discussion about EDK.
Post Reply
Bas
Apprentice
Posts: 62
Joined: Sun Apr 20, 2014 12:11
Location: Russia, Moscow
Contact:

I want to create mod

Post by Bas » Mon Nov 07, 2016 12:23

Hi guys!

I have 3 changes for killboard. The main problem is KB update that revert my changes.
First, i created patches. Little bit easy to update, but i have 3-5 active killboards, so i waste more time than i want.
Unfortunately, i don't understand how to create changes properly, but may be you can help me with some things :)

1) First modification is "Colored ISK loss":
in common/includes/class.killlisttable.php i find

Code: Select all

	 	 	 $kll['victim'] = $kill->getVictimName();
	 	 	 $kll['victimiskloss'] = $kill->getISKLoss();
... and add

Code: Select all

	 	 	 // change color for victim isk loss
	 	 	 $kll['victimiskloss2'] = $kll['victimiskloss'];
then i find

Code: Select all

				 $kll['victimiskloss'] = sprintf("%.02fk", $kll['victimiskloss']/1000);
			}
... and add

Code: Select all

	 	 	 // change color for victim isk loss
	 	 	 if ($kll['victimiskloss2'] > 5000000000)
	 	 	 {
	 	 	 	 $kll['victimiskloss'] = '<span style="color: #ff0000;">' . $kll['victimiskloss'] . '</span>';
	 	 	 }
	 	 	 else if ($kll['victimiskloss2'] > 500000000)
	 	 	 {
	 	 	 	 $kll['victimiskloss'] = '<span style="color: #ffff00;">' . $kll['victimiskloss'] . '</span>';
	 	 	 }
yeah, so dirty and i can modify if-then-else above for proper functionallity, but i think about mod.

2) Second is "img link"
In themes/default/templates/killlisttable.tpl i change

Code: Select all

<tr class="kb-table-row-loss" onclick="window.location.href='{$k.urldetail}';">
to

Code: Select all

><tr class="kb-table-row-loss">
... and same for kills
then a change

Code: Select all

<img src='{$k.victimshipimage}' style="width: 32px; height: 32px;" alt="" />
to

Code: Select all

<a href='{$k.urldetail}'><img src='{$k.victimshipimage}' style="width: 32px; height: 32px; vertical-align: middle;" alt="" /></a>
This changes fix img location in td and allow users to open kills in new tab/window easier (i.e. with ctrl or copy km link)

3) viewtopic.php?f=1012&t=21908 ;]


Can i change someting without src modification?
Can i replace template for default theme with mod?
Probably easier to use patches :) But i read some mods and don't understand what i can do :(

User avatar
Salvoxia
Developer
Posts: 1436
Joined: Wed Feb 22, 2012 12:11

Re: I want to create mod

Post by Salvoxia » Wed Nov 09, 2016 13:32

Hi,

just a quick answer what's possible, I'll go into detail later:
  • 1) First modification is "Colored ISK loss"
    Can be done using a mod, event without having compatibility issues with other mods that modify the killisttable class or template
  • 2) Second is "img link"
    A mod can make EDK use its own version of a template, but that will cause problems with other mods doing the same. The last mod, that gets loaded and overrides the same template as other mods, will have its template used.
  • 3) viewtopic.php?f=1012&t=21908 ;]
    Unfortunately, this is only possible in a mod while overriding the complete logic for displaying the main information (recent activity / kills / losses / Ships&Weaons etc.). You'd have to keep that up-to-date in your mod each time that logic in the the core file is changed.
Best Regards,
Salvoxia

User avatar
Salvoxia
Developer
Posts: 1436
Joined: Wed Feb 22, 2012 12:11

Re: I want to create mod

Post by Salvoxia » Thu Nov 10, 2016 19:04

Hi,

this is my follow-up post, intended to explain the basic principles making mods possible and to give examples that hopefully will help you with your first mod.
The bare minimum you need for a mod is a folder in EDK's mods directory and an "init.php" named file in that folder. If the mod is enabled, the logic in that file gets executed on every page call. The typical thing to do is to register a method as callback for one of EDK's internal events.

At certain key positions in the code, EDK will fire an internal event and execute all callback methods, that are registered for this event. Usually, the method is called with an argument, containing an object of interest (e.g. an entry in the kill list table, when constructing the table).

A nice example for a mod consisting solely of the "init.php" file (and a settings.php file for some settings) is the info_links mod.


The second important concept is the way the pages are constructed. All publicly accessible killboard pages have a corresponding file in the common directory. Each file consists of a "page" class. This class in turn consists of several methods, that are called in order to gather all required information, transform and display it.

The names of the methods to call in each page class are arranged in a queue when the class is instantiated. After each page class is instantiated, an internal event is fired, with the page class as argument. That way, a mod can register to the "assembling" event of a specific page class and hook its own methods into that queue (or replace methods in the queue with its own). Again, the info_links mod mod is a nice example for using that technique.

The third important principle is overriding core files. All a mod needs to do for replacing one of the core page files is to have a file with the same name and class name in its own folder.
For replacing one of the core classes, the mod's class must be registered with the class loader. Examples can be found in EDK's globals.php file.
And finally replacing templates: Each time, a template is loaded (the way it should be loaded), the internal "get_tpl" event is fired. A mod can register for this event and only act if the template is requested, that it wants to replace (for an example see the cynoCloakMod).


And to your specific modifications.
  • Colored ISK Loss
    The killlisttable class fires the event
    'killlist_table_kill' for each $kll it contains. Your callback method will receive the fully populated $kll array. Using this, you can add/modify any data you like. The highlight_capitals mod is a good example for doing just that.
  • "img link"
    As I wrote before, you'll have to replace the default template with your modified versions. An example for a mod doing the same thing is again the highlight_capitals mod.
  • Increasing the top killers list's limit
    To achieve this, you'll have to implement your own modified version of the killList() method in the pCorpDetail page class (it's basically the some you've been doing with the core file, but moving that modified version to your mod). Then register for the 'corpDetail_assembling' event and replace the killList method in the page classes queue with a callback to your own method.
I'll leave you with this to play around a bit.
If you have any further questions, don't hesitate to ask :)

Best Regards,
Salvoxia

Bas
Apprentice
Posts: 62
Joined: Sun Apr 20, 2014 12:11
Location: Russia, Moscow
Contact:

Re: I want to create mod

Post by Bas » Sat Nov 12, 2016 23:53

o_O

Biggest thanks for this posts.
I'll try to look on sources with other view. Some of things i understood when read the code, but some of them is new.
I think this post will help not only for me.

Post Reply

Return to “EDK Development Suggestions”

Who is online

Users browsing this forum: No registered users and 6 guests