Skip to content

Commit

Permalink
Fixed TimeManager to correctly populate TimeComponent.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinSc committed Jul 4, 2016
1 parent d9ae839 commit f7b2787
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,26 @@ public class DefaultTimeManager implements TimeManager, InternalTimeManager {

@Override
public void updateTime(long timeDiff) {
EntityRef worldEntity = timeEntityProvider.getTimeEntity();
TimeComponent world = worldEntity.getComponent(TimeComponent.class);
long lastTime = world.getTime();
timeSinceLastUpdate = timeDiff;
world.setTime(lastTime + timeDiff);
worldEntity.saveChanges();
EntityRef timeEntity = timeEntityProvider.getTimeEntity();
TimeComponent time = timeEntity.getComponent(TimeComponent.class);

if (time == null) {
time = timeEntity.createComponent(TimeComponent.class);
time.setTime(0);
timeEntity.saveChanges();
} else {
long lastTime = time.getTime();
timeSinceLastUpdate = timeDiff;
time.setTime(lastTime + timeDiff);
timeEntity.saveChanges();
}
}

@Override
public long getTime() {
EntityRef worldEntity = timeEntityProvider.getTimeEntity();
TimeComponent world = worldEntity.getComponent(TimeComponent.class);
return world.getTime();
EntityRef timeEntity = timeEntityProvider.getTimeEntity();
TimeComponent time = timeEntity.getComponent(TimeComponent.class);
return time.getTime();
}

@Override
Expand Down

0 comments on commit f7b2787

Please sign in to comment.