Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
// Get Programming with JavaScript
// Listing 20.08
// Map Manager
// Uses gpwj.data and theCrypt.Place
(function () {
  "use strict";
  var placesStore = {};
  
  function addPlace (placeData) {
    var place = new theCrypt.Place(placeData.title, placeData.description);
    placesStore[placeData.id] = place;
      
    if (placeData.items !== undefined) {
      placeData.items.forEach(place.addItem);
    }
    
    if (placeData.exits !== undefined) {
      placeData.exits.forEach(function (exit) {
        place.addExit(exit.direction, exit.id);
        place.addChallenge(exit.direction, exit.challenge);
      });
    }
    return place;
  }
  
  function loadPlace (id, callback) {
    var place = placesStore[id];
  
    if (place === undefined) {
      gpwj.data.load(id, function (placeData) {
        var place = addPlace(placeData);
        callback(place);
      });    
    } else {
      callback(place);
    }
  }
  
  if (window.theCrypt === undefined) {
    window.theCrypt = {};
  }
  
  theCrypt.map = {
    loadPlace: loadPlace
  };
  
})();
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
jrlarsenpro
0viewers