Questions about addon development

All development conversation and discussion takes place here

Moderator: Moderator

Post Reply
Message
Author
Hachem_Muche
Uruivellas
Posts: 744
Joined: Thu Nov 18, 2010 6:42 pm

Questions about addon development

#1 Post by Hachem_Muche »

I'm working on an addon with a lot of small changes to a large number of talents. Two questions:

1. Is there any way to see a revision history of individual functions/class definitions, etc. so that I can see if, say, the specific Fireflash talent definition (not just the fire.lua file) has been updated?

2. Is there a superload equivalent way to update only part of a talent definition, but leave the rest alone? In the case of Fireflash, I'd like to change only the "radius = function(...." part of the definition, but leave the rest alone, so that I don't need to rewrite that part of the addon if something else in the talent changes between game versions.
Author of the Infinite 500 and PlenumTooltip addons, and the joys of Scaling in ToME.

Canderel
Sher'Tul
Posts: 1252
Joined: Mon Nov 24, 2003 2:31 pm
Location: South Africa

Re: Questions about addon development

#2 Post by Canderel »

I die somethong like that in the constitution stamina addon, where i changed the stamina recover talent. So yes you can for the second part. Not sure about the first bot.

aardvark
Wyrmic
Posts: 200
Joined: Wed Aug 22, 2012 12:16 am

Re: Questions about addon development

#3 Post by aardvark »

It's a little cumbersome but (assuming you're trying to track svn HEAD):

Code: Select all

svn log -r BASE:HEAD --diff [path]
You have to check the line numbers that start the diff chunks against your local version to see what function they're in. A two step deal, but that's what I do. You'll probably want to pipe the output through more or another pager. If you use a graphical svn client, I have no help to offer.

Hachem_Muche
Uruivellas
Posts: 744
Joined: Thu Nov 18, 2010 6:42 pm

Re: Questions about addon development

#4 Post by Hachem_Muche »

Thanks for the replies. After some more digging, I've partially rewritten _M:newTalent in ActorTalents.lua to allow talents to be redefined multiple times. Superloading the old function, this merges (overwrites) new talent definitions on top of the old, greatly simplifying talent updates. Only changed fields (besides talent name and type) need to be included in the addon's overload or data definitions.

For example:

Code: Select all

Original talent def                 Update def                           Effective (running) def
newTalent{                          newTalent{                           newTalent{
  name = "Fireflash",                 name = "Fireflash",                  name = "Fireflash",
  type = {"spell/fire",3},            type = {"spell/fire",3},             type = {"spell/fire",3},

....                                                                         <original fields carried over>

  range =7.                             ...                                 range =7.

...                                                                           <original fields carried over>

  radius = <original radius>,         radius = <new radius>,               radius = <new radius>,

...                                     ...                                  <original fields carried over>

  info = <original info>,             info = <new info>,                   info = <new info>,

}                                    }                                    }
I think this functionality should be added to the engine, since it makes addon talent changes much easier, faster to develop (and run) and more robust with respect to changing game versions. I've only updated the definition for talents, but similar functionality for actors, objects, etc, could also be done. I will post the new function definition after I've tested it a bit more.
Author of the Infinite 500 and PlenumTooltip addons, and the joys of Scaling in ToME.

aardvark
Wyrmic
Posts: 200
Joined: Wed Aug 22, 2012 12:16 am

Re: Questions about addon development

#5 Post by aardvark »

Hachem_Muche wrote:Thanks for the replies. After some more digging, I've partially rewritten _M:newTalent in ActorTalents.lua to allow talents to be redefined multiple times. Superloading the old function, this merges (overwrites) new talent definitions on top of the old, greatly simplifying talent updates.
Talent updates are already fairly easy if you use hooks in your addon. Put a load.lua file in the hooks subdirectory of your mod and add a "ToME:load" hook:

Code: Select all

require "engine.class"
require "engine.interface.ActorTalents"

class:bindHook("ToME:load", function (self, data)
	ActorTalents:loadDefinition("/data-my-mod/path/to/talent-changer.lua")
end)
Then, because the loadDefinition() function sets the environment in which its argument file runs, you can assign the talent you want to change to a local variable and override just the fields you want to change:

Code: Select all

local talent_to_change = Talents:getTalentFromId(Talents.T_TALENT_ID)

talent_to_change.value_to_change = 7
talent_to_change.function_to_change = function (actor, talent)
	print "This message will show up in the log."
end
And it all works without any engine or module class changes, although I do agree it's not at all obvious. I figured out how to do it by tracing my way through the code.

Changing items is even easier using the (undocumented, even on the wiki) "Entity:loadList" hook. You don't even need extra files for this one. Just put the changes directly in load.lua. The name of the file that's being loaded is in data.file and all the items created in that file are stored in the data.res table. Say you wanted to add a couple gold to the price of Prox's foot:

Code: Select all

require "engine.class"

class:bindHook("Entity:loadList", function (self, data)
	if data.file == "/data/general/objects/boss-artifacts.lua" then
		for _, item in ipairs(data.res) do
			if item.name == "Prox's Lucky Halfling Foot" then item.cost = item.cost + 2 end
		end
	end
end)
And, of course, don't forget to enable hooks in your init.lua file!

Post Reply