Skip to content

Commit

Permalink
refactored organelle creation code, organelles now initialized by Org…
Browse files Browse the repository at this point in the history
…anelleFactory
  • Loading branch information
Moopli committed Jun 15, 2014
1 parent 20d6268 commit 5af8a3f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
8 changes: 8 additions & 0 deletions scripts/microbe_stage/agent_vacuole.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,11 @@ function AgentVacuole:load(storage)
process:load(storage:get("process", 0))
self.process = process
end

-- factory functions
function OrganelleFactory.makeOxytoxyVacuole()
local agentVacuole = AgentVacuole(CompoundRegistry.getCompoundId("oxytoxy"), global_processMap["OxyToxySynthesis"])
agentVacuole:addHex(0, 0)
agentVacuole:setColour(ColourValue(0, 1, 1, 0))
return agentVacuole
end
18 changes: 18 additions & 0 deletions scripts/microbe_stage/movement_organelle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,21 @@ function MovementOrganelle:update(microbe, milliseconds)
self:_moveMicrobe(microbe, milliseconds)
end

-- factory functions
function OrganelleFactory.makeFlagellum(q,r)
-- Calculate the momentum of the movement organelle based on angle towards nucleus
local organelleX, organelleY = axialToCartesian(q, r)
local nucleusX, nucleusY = axialToCartesian(0, 0)
local deltaX = nucleusX - organelleX
local deltaY = nucleusY - organelleY
local dist = math.sqrt(deltaX^2 + deltaY^2) -- For normalizing vector
local momentumX = deltaX / dist * FLAGELIUM_MOMENTUM
local momentumY = deltaY / dist * FLAGELIUM_MOMENTUM
local flagellum = MovementOrganelle(
Vector3(momentumX, momentumY, 0.0),
300
)
flagellum:setColour(ColourValue(0.8, 0.3, 0.3, 1))
flagellum:addHex(0, 0)
return flagellum
end
17 changes: 17 additions & 0 deletions scripts/microbe_stage/organelle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,20 @@ end
function Organelle:updateHexColours()
self._needsColourUpdate = true
end

-- The basic organelle maker
class 'OrganelleFactory'

-- OrganelleFactory:makeFoo() should be defined in the appropriate file
-- for example, OrganelleFactory:makeMitochondrion() should be defined in process_organelle.lua
-- each factory function should return an organelle that's ready to be inserted into a microbe
-- example:

function OrganelleFactory.makeNucleus()
local nucleus = NucleusOrganelle()
nucleus:addHex(0, 0)
nucleus:setColour(ColourValue(0.8, 0.2, 0.8, 1))
nucleus:addProcess(global_processMap["ReproductaseSynthesis"])
nucleus:addProcess(global_processMap["AminoAcidSynthesis"])
return nucleus
end
11 changes: 11 additions & 0 deletions scripts/microbe_stage/process_organelle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,14 @@ function ProcessOrganelle:load(storage)
self:addProcess(process)
end
end

-------------------------------------------
-- factory functions for process organelles

function OrganelleFactory.makeMitochondrion()
local mito = ProcessOrganelle()
mito:addProcess(global_processMap["Respiration"])
mito:addHex(0, 0)
mito:setColour(ColourValue(0.8, 0.4, 0.5, 0))
return mito
end
7 changes: 7 additions & 0 deletions scripts/microbe_stage/storage_organelle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ function StorageOrganelle:onRemovedFromMicrobe(microbe, q, r)
microbe:removeStorageOrganelle(self)
end


function OrganelleFactory.makeVacuole()
local vacuole = StorageOrganelle(100.0)
vacuole:addHex(0, 0)
vacuole:setColour(ColourValue(0, 1, 0, 1))
return vacuole
end

0 comments on commit 5af8a3f

Please sign in to comment.