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

games.rednblack.talos.runtime.utils.MathExpressionMappings Maven / Gradle / Ivy

/*******************************************************************************
 * Copyright 2019 See AUTHORS file.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

package games.rednblack.talos.runtime.utils;

import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.reflect.ClassReflection;
import com.badlogic.gdx.utils.reflect.Field;
import com.badlogic.gdx.utils.reflect.ReflectionException;
import games.rednblack.talos.runtime.Expression;

public class MathExpressionMappings {
	private static final ObjectMap names = new ObjectMap<>();

	static {
		Array namesArr = new Array<>();
		// get list of possible interpolations

		Field[] fields = ClassReflection.getFields(Expression.class);
		for (int i = 0; i < fields.length; i++) {
			try {
				Expression interp = (Expression)fields[i].get(null);
				names.put(fields[i].getName(), interp);
				namesArr.add(fields[i].getName());
			} catch (ReflectionException e) {
				e.printStackTrace();
			}
		}
	}

	public static Expression getMathExpressionForName (String name) {
		return names.get(name);
	}

	public static String getNameForMathExpression (Expression expression) {
		for (ObjectMap.Entry name : names) {
			if (name.value == expression) {
				return name.key;
			}
		}
		return "fade";
	}

	public static void getAvailableMathExpressions (Array interps) {
		for (String key : names.keys()) {
			interps.add(key);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy