Ejemplo n.º 1
0
func (m *Map) LoadTiles() bool {
	start := time.Now().UnixNano()
	var allTiles []TileRow

	//Init the tile id to 1
	g_newTileId = 1

	err := g_orm.SetTable("tile").Join("INNER", "tile_layer", "tile_layer.tileid = tile.idtile").Join(" LEFT", "tile_events", "tile_events.idtile_events = tile.idtile_event").OrderBy("tile.idtile DESC").FindAll(&allTiles)
	if err != nil {
		log.Error("map", "loadTiles", "Error while loading tiles: %v", err.Error())
		return false
	}

	log.Info("Map", "loadTiles", "%d tiles fetched in %dms", len(allTiles), (time.Now().UnixNano()-start)/1e6)

	if len(allTiles) > 0 {
		log.Verbose("Map", "loadTiles", "Processing tiles with %d goroutines", m.numOfProcessRoutines)

		// Start process goroutine
		for i := 1; i <= m.numOfProcessRoutines; i++ {
			go m.processTiles()
		}

		// Send rows to channel
		for key, row := range allTiles {
			//First tile has highest ID
			if key == 0 {
				g_newTileId = (row.Idtile + 1)
				log.Verbose("Map", "loadTiles", "Determined next tile ID: %d", g_newTileId)
			}

			m.processChan <- row
		}

		// Close channel so the process goroutine(s) will shutdown
		close(m.processChan)
	}
	return true
}
Ejemplo n.º 2
0
func (m *PokemonManager) loadPokemonSpecies() bool {
	var pokes []models.PokemonSpeciesJoinPokemonEvolution
	err := G_orm.SetTable("pokemon_species").Join("LEFT", "pokemon_evolution", "pokemon_evolution.evolved_species_id = (SELECT `ps2`.id FROM pokemon_species AS `ps2` WHERE `ps2`.evolves_from_species_id = pokemon_species.id LIMIT 1)").FindAll(&pokes)
	if err != nil {
		log.Error("PokeManager", "loadPokemonSpecies", "Failed to load pokemon species. Error: %v", err.Error())
		return false
	}

	log.Verbose("PokeManager", "loadPokemonSpecies", "Processing pokemon species")
	for _, row := range pokes {
		pokemon := NewPokemonSpecesFromEntity(row)
		m.pokemonSpecies[pokemon.SpeciesId] = pokemon
	}

	return true
}
Ejemplo n.º 3
0
func (m *PokemonManager) loadAbilities() bool {
	var abilities []models.Abilities
	err := G_orm.FindAll(&abilities)
	if err != nil {
		log.Error("PokeManager", "loadAbilities", "Failed to load abilities. Error: %v", err.Error())
		return false
	}

	log.Verbose("PokeManager", "loadAbilities", "Processing abiliites")
	for _, row := range abilities {
		ability := NewAbilityFromEntity(row)
		m.abilities[ability.AbilityId] = ability
	}

	return true
}
Ejemplo n.º 4
0
func (m *PokemonManager) loadMoves() bool {
	var moves []models.MovesJoinMoveFlavorText
	err := G_orm.SetTable("moves").Join("LEFT", "move_flavor_text", fmt.Sprintf("%v = %v", models.MoveFlavorText_IdMove, models.Moves_Id)).FindAll(&moves)
	if err != nil {
		log.Error("PokeManager", "loadMoves", "Failed to load moves. Error: %v", err.Error())
		return false
	}

	log.Verbose("PokeManager", "loadMoves", "Processing moves")
	for _, row := range moves {
		move := NewMoveFromEntity(row)
		m.moves[move.MoveId] = move
	}

	return true
}
Ejemplo n.º 5
0
func (m *PokemonManager) loadPokemon() bool {
	var pokes []models.Pokemon
	err := G_orm.FindAll(&pokes)
	if err != nil {
		log.Error("PokeManager", "loadPokemon", "Failed to load pokemon. Error: %v", err.Error())
		return false
	}

	log.Verbose("PokeManager", "loadPokemon", "Processing pokemon")
	for _, row := range pokes {
		pokemon := NewPokemonFromEntity(row)

		// Add to map
		m.pokemon[pokemon.PokemonId] = pokemon
	}

	return true
}
Ejemplo n.º 6
0
func (m *PokemonManager) loadAbilityMessages() bool {
	var ability_messages []models.AbilityMessages
	err := G_orm.FindAll(&ability_messages)
	if err != nil {
		log.Error("PokeManager", "loadAbilityMessages", "Failed to load ability messages. Error: %v", err.Error())
		return false
	}

	log.Verbose("PokeManager", "loadAbilityMessagess", "Processing ability messages")
	for _, row := range ability_messages {
		messages := strings.Split(row.Message, "|")
		messageMap := make(map[int]string)
		for index, msg := range messages {
			messageMap[index] = msg
		}

		m.abilityMessages[row.AbilityId] = messageMap
	}

	return true
}