Contents of this document:
1. DirectorNode Documentation
2. ModMusicManager Documentation
------------------------


COPY THIS FILE IF YOU WANT TO USE ANY OF THE SOFTWARE EXPLAINED IN THIS FILE. IT WILL HELP
OTHERS UNDERSTAND WHAT THE SOFTWARE DOES AND THAT THEY CAN TOO COPY IT FOR MODDING PURPOSES.


DirectorNode Documentation
------------------------

The DirectorNode is a behaviour node for the game Don't Starve. It is unique in that it uses
an external function to determine which child node to visit.

The index function does not receive any parameters by the node. Only the variables available
in the namespace of its initialisation can be used. In simpler words: You will need to write
the index function within the Brain:OnStart function. This is relatively common practise for
similiar functions in other nodes, so you should be able to find an example if needed.

You can "disable" the node by setting an invalid index. This is not the best procedure, as
you should not even visit that node in the first place, but it is possible.

The following is DirectorNode v1.0


local DirectorNode = Class(BehaviourNode,function(self, name, children, idxfn)
    BehaviourNode._ctor(self, name or "Director", children)
	assert( idxfn ~= nil, "DirectorNode requires a directing function")
    self.idxfn = idxfn
    self.idx = 1
end)

function DirectorNode:DBString()
	local res = self.idxfn() or -1
    return string.format("index %d idxfn %d",self.idx, res)
end

function DirectorNode:Reset()
    self._base.Reset(self)
    self.idx = 1
end

function DirectorNode:Visit()
	
    if self.status ~= RUNNING then
        self.idx = self.idxfn() or 1
    end
    
    local child = self.children[self.idx]
	if child then
		
		self.status = RUNNING
		
		if child.status == FAILED or child.status == SUCCESS then
			--print("RESET",self.idx)
			child:Reset()
		end
		child:Visit()
		
		if child.status == SUCCESS then
			--print("SUCCESSFUL",self.idx)
            self.status = SUCCESS
        elseif child.status == FAILED then
			self.idx = self.idxfn() or 1
        end
	else
		--print("INVALID CHILD",self.idx)
		self.idx = self.idxfn() or 1
	end
end



ModMusicManager Documentation
------------------------

The Mod Music Manager is a component to organise custom music across various mods.

How to set up:
1. Copy "scripts/components/modmusicmanager.lua" and paste in your mod
2. Copy the code given at the beginning of the file and paste it in the respective files

How to use:
1. Add your music like so:
	GetModMusicManager():AddTrack(soundpath, priority, cooldown_init, cooldown_rep)
		whereas "soundpath" is a string and the event path for the FMOD sound event,
		"priority" is a number and the importance of the track (higher = more important),
		"cooldown_init" is a number and the time before fading out after starting (If
			no time is given, the track will play for ever),
		"cooldown_rep" is a number and the minimum time before fading out after refreshing (If
			no time is given, "cooldown_init" is used);
		return value: the track table
2. Play your music like so:
	GetModMusicManager():StartTrack(id)
		whereas "id" is either the numeric key of the track in the "tracks" table or the
			track table itself (as returned by "AddTrack")
3. (If fade-out time is given) Continue playing your music like so:
	GetModMusicManager():ContinueTrack(id)
		whereas "id" is either the numeric key of the track in the "tracks" table or the
			track table itself (as returned by "AddTrack")
4. Stop playing your music like so:
	GetModMusicManager():StopTrack(id)
		whereas "id" is either the numeric key of the track in the "tracks" table or the
			track table itself (as returned by "AddTrack")
Please note that calling the manager in modmain.lua usually requires the "GLOBAL." prefix.

Please do not edit the file without contacting the original author "Mobbstar". Report problems
to the original author to prevent outdated files from overriding the new one.
