Skip to content

Commit

Permalink
Merge pull request #359 from Revolutionary-Games/editor-issues-0.3.0
Browse files Browse the repository at this point in the history
Fixed multiple editor issues for 0.3.0
  • Loading branch information
TheCreator-- committed Dec 2, 2015
2 parents b8616af + 677ac5e commit 97a2bff
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 43 deletions.
80 changes: 50 additions & 30 deletions scripts/microbe_editor/microbe_editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,33 @@ function MicrobeEditor:update(renderTime, logicTime)
end

local q, r = self:getMouseHex()
if self.activeActionName then
if self.activeActionName then
local oldData = {["name"]=self.activeActionName, ["q"]=q, ["r"]=r, ["rotation"]=self.organelleRot}
local hexes = OrganelleFactory.checkSize(oldData)
local colour = ColourValue(0, 2, 0, 0.4)
local colour = ColourValue(2, 0, 0, 0.4)
local touching = false;
for _, hex in ipairs(hexes) do
if self.currentMicrobe:getOrganelleAt(hex.q + q + 0, hex.r + r - 1) or
self.currentMicrobe:getOrganelleAt(hex.q + q + 1, hex.r + r - 1) or
self.currentMicrobe:getOrganelleAt(hex.q + q + 1, hex.r + r + 0) or
self.currentMicrobe:getOrganelleAt(hex.q + q + 0, hex.r + r + 1) or
self.currentMicrobe:getOrganelleAt(hex.q + q - 1, hex.r + r + 1) or
self.currentMicrobe:getOrganelleAt(hex.q + q - 1, hex.r + r + 0) then
colour = ColourValue(0, 2, 0, 0.4)
end
end
for _, hex in ipairs(hexes) do
if self.currentMicrobe:getOrganelleAt(hex.q + q, hex.r + r) then
colour = ColourValue(2, 0, 0, 0.4)
end
end
--if CEGUIWindow.getWindowUnderMouse():getName() == 'root' then
local newData = {["name"]=self.activeActionName, ["q"]=q, ["r"]=r, ["sceneNode"]=sceneNode, ["rotation"]=self.organelleRot, ["colour"]=colour}
OrganelleFactory.renderOrganelles(newData)
for i=1, 8 do
sceneNode[i].transform:touch()
end
end
if CEGUIWindow.getWindowUnderMouse():getName() == 'root' then
local newData = {["name"]=self.activeActionName, ["q"]=q, ["r"]=r, ["sceneNode"]=sceneNode, ["rotation"]=self.organelleRot, ["colour"]=colour}
OrganelleFactory.renderOrganelles(newData)
for i=1, 8 do
sceneNode[i].transform:touch()
end
end
end

-- self.nextMicrobeEntity being a temporary used to pass the microbe from game to editor
Expand Down Expand Up @@ -203,39 +215,42 @@ function MicrobeEditor:addOrganelle(organelleType)
if self.currentMicrobe:getOrganelleAt(hex.q + q, hex.r + r) then
empty = false
end
for s, hex in pairs(organelle._hexes) do
if self.currentMicrobe:getOrganelleAt(hex.q + q + 0, hex.r + r - 1) or
self.currentMicrobe:getOrganelleAt(hex.q + q + 1, hex.r + r - 1) or
self.currentMicrobe:getOrganelleAt(hex.q + q + 1, hex.r + r + 0) or
self.currentMicrobe:getOrganelleAt(hex.q + q + 0, hex.r + r + 1) or
self.currentMicrobe:getOrganelleAt(hex.q + q - 1, hex.r + r + 1) or
self.currentMicrobe:getOrganelleAt(hex.q + q - 1, hex.r + r + 0) then
touching = true;
end
end
if self.currentMicrobe:getOrganelleAt(hex.q + q + 0, hex.r + r - 1) or
self.currentMicrobe:getOrganelleAt(hex.q + q + 1, hex.r + r - 1) or
self.currentMicrobe:getOrganelleAt(hex.q + q + 1, hex.r + r + 0) or
self.currentMicrobe:getOrganelleAt(hex.q + q + 0, hex.r + r + 1) or
self.currentMicrobe:getOrganelleAt(hex.q + q - 1, hex.r + r + 1) or
self.currentMicrobe:getOrganelleAt(hex.q + q - 1, hex.r + r + 0) then
touching = true;
end
end
if empty and touching then
for s, hex in pairs(organelle._hexes) do
local x, y = axialToCartesian(hex.q + q, hex.r + r)
local s = encodeAxial(hex.q + q, hex.r + r)
self.occupiedHexes[s] = Entity()
local sceneNode = OgreSceneNodeComponent()
sceneNode.transform.position = Vector3(-x, -y, 0)
sceneNode.transform:touch()
sceneNode.meshName = "hex.mesh"
self.occupiedHexes[s]:addComponent(sceneNode)
self.occupiedHexes[s]:setVolatile(true)
end
self:enqueueAction({
cost = Organelle.mpCosts[organelleType],
redo = function()
self.currentMicrobe:addOrganelle(q, r, self.organelleRot, organelle)
self.organelleCount = self.organelleCount + 1
for _, hex in pairs(organelle._hexes) do
local x, y = axialToCartesian(hex.q + q, hex.r + r)
local s = encodeAxial(hex.q + q, hex.r + r)
self.occupiedHexes[s] = Entity()
local sceneNode = OgreSceneNodeComponent()
sceneNode.transform.position = Vector3(-x, -y, 0)
sceneNode.transform:touch()
sceneNode.meshName = "hex.mesh"
self.occupiedHexes[s]:addComponent(sceneNode)
self.occupiedHexes[s]:setVolatile(true)
end
end,
undo = function()
self.currentMicrobe:removeOrganelle(q, r)
self.currentMicrobe.sceneNode.transform:touch()
self.organelleCount = self.organelleCount - 1
for _, hex in pairs(organelle._hexes) do
local x, y = axialToCartesian(hex.q + q, hex.r + r)
local s = encodeAxial(hex.q + q, hex.r + r)
self.occupiedHexes[s]:destroy()
end
end
})
end
Expand All @@ -257,6 +272,10 @@ function MicrobeEditor:removeOrganelle()
self.currentMicrobe:removeOrganelle(storage:get("q", 0), storage:get("r", 0))
self.currentMicrobe.sceneNode.transform:touch()
self.organelleCount = self.organelleCount - 1
for _, cytoplasm in pairs(organelle._hexes) do
local s = encodeAxial(cytoplasm.q + storage:get("q", 0), cytoplasm.r + storage:get("r", 0))
self.occupiedHexes[s]:destroy()
end
end,
undo = function()
local organelle = Organelle.loadOrganelle(storage)
Expand Down Expand Up @@ -350,3 +369,4 @@ function MicrobeEditor:createNewMicrobe()
action.redo()
end
end

29 changes: 19 additions & 10 deletions scripts/microbe_editor/microbe_editor_hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ function MicrobeEditorHudSystem:init(gameState)
System.init(self, gameState)
self.editor:init(gameState)
for i=1, 7 do
self.hoverHex[i] = Entity("hover-hex" .. i)
local sceneNode = OgreSceneNodeComponent()
sceneNode.transform.position = Vector3(0,0,0)
sceneNode.transform:touch()
sceneNode.meshName = "hex.mesh"
self.hoverHex[i]:addComponent(sceneNode)
end
self.hoverOrganelle = Entity("hover-organelle")
self.hoverHex[i] = Entity("hover-hex" .. i)
local sceneNode = OgreSceneNodeComponent()
sceneNode.transform.position = Vector3(0,0,0)
sceneNode.transform:touch()
self.hoverOrganelle:addComponent(sceneNode)
sceneNode.meshName = "hex.mesh"
self.hoverHex[i]:addComponent(sceneNode)
end
self.hoverOrganelle = Entity("hover-organelle")
local sceneNode = OgreSceneNodeComponent()
sceneNode.transform.position = Vector3(0,0,0)
sceneNode.transform:touch()
self.hoverOrganelle:addComponent(sceneNode)
local root = gameState:rootGUIWindow()
self.mpLabel = root:getChild("MpPanel"):getChild("MpLabel")
self.nameLabel = root:getChild("SpeciesNamePanel"):getChild("SpeciesNameLabel")
Expand Down Expand Up @@ -103,8 +103,17 @@ end


function MicrobeEditorHudSystem:update(renderTime, logicTime)
for i=1, 7 do
local sceneNode = self.hoverHex[i]:getComponent(OgreSceneNodeComponent.TYPE_ID)
sceneNode.transform.position = Vector3(0,0,0)
sceneNode.transform:touch()
end
local sceneNode = self.hoverOrganelle:getComponent(OgreSceneNodeComponent.TYPE_ID)
sceneNode.transform.position = Vector3(0,0,0)
sceneNode.transform:touch()

self.editor:update(renderTime, logicTime)

-- Handle input
if Engine.mouse:wasButtonPressed(Mouse.MB_Left) then
self.editor:performLocationAction()
Expand Down
7 changes: 4 additions & 3 deletions scripts/microbe_stage/microbe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,10 @@ function Microbe:toggleEngulfMode()
colourToSet = ColourValue.Red
self.microbe.movementFactor = self.microbe.movementFactor / ENGULFING_MOVEMENT_DIVISION
end
for _, organelle in pairs(self.microbe.organelles) do
organelle:setExternalEdgeColour(colourToSet)
end
-- You should be able to get the membrane to flash blue (or become some color)
-- if you are able to get your hands on the membrane entity, which is currently defined in c++
-- below line is just an example—it doesn't actually work.
-- microbe.membraneComponent.entity:flashColour(3000, ColourValue(1,0.2,0.2,1))
self.microbe.engulfMode = not self.microbe.engulfMode
end

Expand Down

0 comments on commit 97a2bff

Please sign in to comment.