Skip to content

Commit

Permalink
Added special case for Portal objects, to fix bug where 'look <door o…
Browse files Browse the repository at this point in the history
…bject>' returns an error about needing to use the Poral override
  • Loading branch information
PeterAJansen committed Jul 10, 2024
1 parent 3fa14c9 commit d921929
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion simulator/src/main/scala/scienceworld/actions/ActionLook.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import language.model.{ActionExpr, ActionExprIdentifier, ActionExprOR, ActionExp
import scienceworld.input.ActionDefinitions.mkActionRequest
import scienceworld.input.{ActionDefinitions, ActionHandler}
import scienceworld.objects.agent.Agent
import scienceworld.objects.portal.Portal
import scienceworld.struct.EnvObject
import scienceworld.struct.EnvObject._
import util.StringHelpers
Expand Down Expand Up @@ -84,7 +85,23 @@ class ActionLookAt(action:ActionRequestDef, assignments:Map[String, EnvObject])
val (invalidStr, isValid) = ActionLookAt.isValidAction(assignments)
if (!isValid) return (invalidStr, false)

val objDescription = obj.getDescriptionSafe(mode = MODE_DETAILED).getOrElse("<ERROR: attempting to view hidden object>") //## TODO: Arguable whether the error case here should be caught by checks above
// Modified version, with special handling for Portal objects
val mode = MODE_DETAILED
var objDescription = "<ERROR: Could not retrieve object description>" // This error should never happen
// Get the perspective container
if (agent.getContainer().isDefined) { // This should always be the case unless something terrible has happened
val perspectiveContainer = agent.getContainer().get
obj match {
case x: Portal => {
val desc = x.getDescriptionSafe(mode, perspectiveContainer)
if (desc.isDefined) objDescription = desc.get
}
case x: EnvObject => {
val desc = x.getDescriptionSafe(mode)
if (desc.isDefined) objDescription = desc.get
}
}
}
return (objDescription, true)

}
Expand Down

0 comments on commit d921929

Please sign in to comment.