/** * 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.'); } }
/** * Non-static method for the Laravel Queue handler */ public function queuePaint($job, $data) { $map = Map::findOrFail($data['mapid']); self::$filename = $map->minimap->path; self::load(); foreach ($data['tiles'] as $tile) { if (intval($tile['z']) == 7) { self::paint(intval($tile['x']), intval($tile['y']), intval($tile['itemid'])); } } self::save(); $job->delete(); }
public function getMinimap($mapid) { $mapid = intval($mapid); $map = Map::findOrFail($mapid); //Enforce ACL if (!$this->userCanView($map)) { App::abort(403); } $minimap_path = $map->minimap->path; $png = file_get_contents($minimap_path); return Response::make($png, 200, array('content-type' => 'image/png')); }