Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added special case for Portal objects, to fix bug where 'look <door o… #73

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading