Beispiel #1
0
 public static function create()
 {
     if (!Input::has('name')) {
         App::abort(400);
     }
     $user = Auth::user();
     $map = new Map();
     $map->width = 512;
     $map->height = 512;
     $map->name = Input::get('name');
     $map->description = Input::has('description') ? Input::get('description') : '';
     $map->version = 960;
     $map->save();
     $ownership = new Permission();
     $ownership->mapid = $map->id;
     $ownership->userid = $user->id;
     $ownership->owner = true;
     $ownership->edit = true;
     $ownership->view = true;
     $ownership = $map->permissions()->save($ownership);
     $minimap = new Minimap();
     $minimap->mapid = $map->id;
     $minimap->updated_at = new \DateTime();
     $minimap = $map->minimap()->save($minimap);
     \OTWorlds\MinimapPainter::$filename = $minimap->path;
     \OTWorlds\MinimapPainter::create(512, 512);
     \OTWorlds\MinimapPainter::save();
     return $map->id;
 }
Beispiel #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //
     $map = Map::findOrFail($this->argument('map'));
     $minimap = $map->minimap;
     if (!$minimap->locked || $this->option('force')) {
         // Call dibs on editing this minimap
         $supernow = new Carbon();
         $this->info('[' . Carbon::now() . '] Locking and processing map ' . $map->id);
         $minimap->updated_at = new \DateTime();
         $minimap->locked = true;
         $minimap->save();
         // Load the tiles. May take some time. =)
         $tiles = Tile::where('mapid', $map->id)->where('posz', 7)->get();
         // Prepare the canvas, maestro!
         \OTWorlds\MinimapPainter::$filename = $minimap->path;
         \OTWorlds\MinimapPainter::load($map->width, $map->height);
         foreach ($tiles as $tile) {
             \OTWorlds\MinimapPainter::paint(intval($tile->posx), intval($tile->posy), intval($tile->itemid));
         }
         // Finish up
         \OTWorlds\MinimapPainter::save();
         // Let other processes edit this map again
         $minimap->locked = false;
         $minimap->save();
         $donenow = new Carbon();
         $this->info('[' . $donenow->now() . '] Done. Processed ' . $tiles->count() . ' tiles in ' . $donenow->diffInSeconds($supernow) . ' seconds.');
     } else {
         $this->error('Minimap is locked. Either another process is using it, or the last one crashed. Use --force to ignore.');
     }
 }