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

Issues/270 show consume #278

Open
wants to merge 2 commits into
base: one-hour-one-life
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions dlgr/griduniverse/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ def __init__(self, **kwargs):
self.recruiter_id = kwargs.get("recruiter_id", "")
self.add_wall = None
self.current_item = None
self.just_consumed = False

# Determine the player's color. We don't have access to the specific
# gridworld we are running in, so we can't use the `limited_` variables
Expand Down Expand Up @@ -960,6 +961,8 @@ def tremble(self, direction):
def move(self, direction, tremble_rate=None, timestamp=None):
"""Move the player."""

self.just_consumed = False

if not self.grid.movement_enabled:
return

Expand Down Expand Up @@ -1057,6 +1060,7 @@ def serialize(self):
"identity_visible": self.identity_visible,
"recruiter_id": self.recruiter_id,
"current_item": self.current_item and self.current_item.serialize(),
"just_consumed": self.just_consumed,
}


Expand Down Expand Up @@ -1487,6 +1491,7 @@ def handle_build_wall(self, msg):

def handle_item_consume(self, msg):
player = self.grid.players[msg["player_id"]]
player.just_consumed = True
player_item = player.current_item
if player_item is None or not player_item.calories:
error_msg = {
Expand Down
12 changes: 12 additions & 0 deletions dlgr/griduniverse/static/scripts/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ var Player = function (settings, dimness) {
this.identity_visible = settings.identity_visible;
this.dimness = dimness;
this.replaceItem(settings.current_item || null);
this.just_consumed = settings.just_consumed;
return this;
};

Expand Down Expand Up @@ -603,6 +604,7 @@ var players = playerSet({'ego_id': undefined});

pixels.canvas.style.marginLeft = window.innerWidth * 0.03 / 2 + "px";
pixels.canvas.style.marginTop = window.innerHeight * 0.04 / 2 + "px";
pixels.canvas.style.border = "5px solid #000000"
document.body.style.transition = "0.3s all";
document.body.style.background = "#ffffff";

Expand All @@ -624,6 +626,16 @@ pixels.frame(function() {
return newColor;
});

// Did someone just consume something?
players.each(function (i, player) {
if (player.just_consumed) {
pixels.canvas.style.border = "5px solid " + player.color;
setTimeout(() => {
pixels.canvas.style.border = "5px solid #000000"
}, 1000);
}
});

for (const [position, item] of gridItems.entries()) {
if (players.isPlayerAt(position)) {
if (!item.interactive && item.calories) {
Expand Down
12 changes: 12 additions & 0 deletions dlgr/griduniverse/static/scripts/dist/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dlgr/griduniverse/static/scripts/dist/bundle.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dlgr/griduniverse/static/scripts/dist/difi.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dlgr/griduniverse/static/scripts/dist/questionnaire.js.map

Large diffs are not rendered by default.

Loading