All Downloads are FREE. Search and download functionalities are using the official Maven repository.

godot.entrygenerator.generator.hintstring.RangeHintStringGenerator.kt Maven / Gradle / Ivy

There is a newer version: 0.10.0-4.3.0
Show newest version
package godot.entrygenerator.generator.hintstring

import godot.entrygenerator.exceptions.WrongAnnotationUsageException
import godot.entrygenerator.ext.fqName
import godot.entrygenerator.ext.fqNameIsJvmType
import godot.entrygenerator.model.JvmType
import godot.entrygenerator.model.Range
import godot.entrygenerator.model.RangeHintAnnotation
import godot.entrygenerator.model.RegisteredProperty
import java.util.*

class RangeHintStringGenerator(registeredProperty: RegisteredProperty):
    PropertyHintStringGenerator>(registeredProperty) {
    override fun getHintString(): String {
        if (!registeredProperty.type.fqName.fqNameIsJvmType(JvmType.DOUBLE, JvmType.FLOAT, JvmType.INT, JvmType.LONG)) {
            throw WrongAnnotationUsageException(
                registeredProperty,
                propertyHintAnnotation,
                setOf(
                    *JvmType.DOUBLE.fqName.toTypedArray(),
                    *JvmType.FLOAT.fqName.toTypedArray(),
                    *JvmType.INT.fqName.toTypedArray(),
                    *JvmType.LONG.fqName.toTypedArray()
                )
            )
        }
        if (propertyHintAnnotation == null) {
            return ""
        }

        val argumentsForStringTemplate = mutableListOf()

        argumentsForStringTemplate.add(propertyHintAnnotation.start)
        argumentsForStringTemplate.add(propertyHintAnnotation.end)

        if (propertyHintAnnotation.step.toDouble() >= 0) {
            argumentsForStringTemplate.add(propertyHintAnnotation.step)
        }

        if (propertyHintAnnotation.or != Range.NONE) {
            argumentsForStringTemplate.add(propertyHintAnnotation.or.name.lowercase(Locale.ENGLISH))
        }

        if (propertyHintAnnotation.hideSlider) {
            argumentsForStringTemplate.add("hide_slider")
        }

        if (propertyHintAnnotation.isRadians) {
            argumentsForStringTemplate.add("radians")
        }

        if (propertyHintAnnotation.isDegrees) {
            argumentsForStringTemplate.add("degrees")
        }

        if (propertyHintAnnotation.isExp) {
            argumentsForStringTemplate.add("exp")
        }

        if (propertyHintAnnotation.suffix != null) {
            argumentsForStringTemplate.add("suffix:${propertyHintAnnotation.suffix}")
        }

        return argumentsForStringTemplate.joinToString(",")
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy