Ejemplo n.º 1
0
func parseCslPackage(aircraftFile *os.File, baseDir string) (*CslPackage, error) {
	scanner := bufio.NewScanner(aircraftFile)
	result := &CslPackage{}
	result.Valid = true
	result.BaseDirectory = baseDir
	result.Dependencies = make([]string, 0)
	var currentAircraft *CslAircraft
	for scanner.Scan() {
		text := strings.TrimSpace(scanner.Text())
		if len(text) == 0 || strings.HasPrefix(text, "#") {
			//Zeile enthält keinen Text bzw. nur Kommentare --> ignorieren
			continue
		}
		tokens := strings.Split(text, " ")
		tokens = trimTokens(tokens)
		var err error
		switch tokens[0] {
		case "EXPORT_NAME":
			err = handleExportName(tokens, result)
		case "DEPENDENCY":
			err = handleDependency(tokens, result)
		case "AIRCRAFT":
			currentAircraft, err = handleAircraft(tokens, currentAircraft, result, aircraftFile)
		case "OBJECT":
			currentAircraft, err = handleObject7(tokens, currentAircraft, result)
		case "OBJ8_AIRCRAFT":
			currentAircraft, err = handleObject8Aircraft(tokens, currentAircraft, result)
		case "OBJ8":
			err = handleObj8(tokens, currentAircraft, aircraftFile)
		case "TEXTURE":
			err = handleTexture(tokens, currentAircraft)
		case "HASGEAR":
			err = handleHasGear(tokens, currentAircraft, aircraftFile)
		case "ICAO":
			err = handleIcao(tokens, currentAircraft)
		case "AIRLINE":
			err = handleAirline(tokens, currentAircraft)
		case "LIVERY":
			err = handleLivery(tokens, currentAircraft)
		default:
			logging.Warningf("unexpected command \"%v\" in file %v", tokens[0], aircraftFile.Name())
		}
		if err != nil {
			return nil, err
		}
	}
	if currentAircraft != nil {
		result.Aircrafts = append(result.Aircrafts, currentAircraft)
	}
	return result, nil
}
Ejemplo n.º 2
0
func handleHasGear(tokens []string, currentAircraft *CslAircraft, aircraftFile *os.File) error {
	if len(tokens) != 2 {
		return errors.New("Command <HASGEAR> missing value")
	}
	if currentAircraft != nil {
		switch tokens[1] {
		case "YES":
			currentAircraft.HasGear = true
		case "NO":
			currentAircraft.HasGear = false
		default:
			logging.Warningf("invalid HASGEAR-Value: %v (file: %v)", tokens[1], aircraftFile.Name())
		}
	}
	return nil
}
Ejemplo n.º 3
0
func handleAircraft(tokens []string, currentAircraft *CslAircraft, cslPackage *CslPackage, aircraftFile *os.File) (*CslAircraft, error) {
	if len(tokens) != 4 {
		return nil, errors.New(fmt.Sprintf("Command <AIRCRAFT> invalid token count, expected 4, current %v", len(tokens)))
	}
	logging.Warningf("ignore austin aircraft (not supported): %v (file: %v)", tokens[3], aircraftFile.Name())
	return nil, nil

	/*
		minVersion := tokens[1]
		maxVersion := tokens[2]
		if !checkVersion(minVersion, maxVersion) {
		}
		newAircraft := appendAircraft(currentAircraft, cslPackage)
		newAircraft.AcfFile = tokens[3]
		newAircraft.CslType=CSL_TYPE_AUSTIN
		return newAircraft, nil
	*/
}
Ejemplo n.º 4
0
func parseRelatedFile(relatedFilePath string) map[string][]string {
	relatedMap := make(map[string][]string)
	relatedFile, err := os.Open(relatedFilePath)
	if err != nil {
		logging.Warningf("could not open related file \"%v\": %v", relatedFilePath, err)
		return relatedMap
	}
	scanner := bufio.NewScanner(relatedFile)
	for scanner.Scan() {
		text := strings.TrimSpace(scanner.Text())
		if len(text) == 0 || strings.HasPrefix(text, ";") {
			//Zeile enthält keinen Text bzw. nur Kommentare --> ignorieren
			continue
		}
		tokens := strings.Split(text, " ")
		tokens = trimTokens(tokens)
		//für jeden ICAO-Code die Liste der verwandten ICAOs merken
		for _, token := range tokens {
			relatedMap[token] = tokens
		}
	}
	return relatedMap
}
Ejemplo n.º 5
0
//Erzeugt einen neuen MultiplayerManager
func New(cslFolder, relatedFile, lightsFile, defaultICAO string, config *Configuration) (*MultiplayerManager, error) {
	runtime.GOMAXPROCS(runtime.NumCPU())
	//OpenGL initialisieren
	err := gl.InitOpenGL()
	if err != nil {
		return nil, errors.New(fmt.Sprintf("could not initialize OpenGL: %v", err))
	}
	manager := &MultiplayerManager{}
	manager.planes = make([]*Plane, 0, 40)
	manager.isBlend = false
	manager.wrtDataRef = nil
	manager.prtDataRef = nil
	manager.renderAircraftLabels = config.RenderAircraftLabels
	manager.configuration = config
	manager.planesMutex = sync.RWMutex{}
	csl.CslManagerInstance.Init(cslFolder, relatedFile, defaultICAO)
	err = texture.TextureManagerInstance.Init(config.Resolution, lightsFile, config.MergeLitTextures, config.UseAnyLitTexture)
	if err != nil {
		logging.Warningf(fmt.Sprintf("Could not load lights texture: %v", err))
		return nil, err
	}
	return manager, nil
}
Ejemplo n.º 6
0
func (self *CslPackage) invalidate(msg string, params ...interface{}) {
	logging.Warningf("invalid package \"%v\", reason: %v [base directory: %v]", self.Name, fmt.Sprintf(msg, params...), self.BaseDirectory)
	self.Valid = false
}