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

com.bladecoder.engine.ink.ExternalFunctions Maven / Gradle / Ivy

There is a newer version: 4.3.1
Show newest version
package com.bladecoder.engine.ink;

import com.bladecoder.engine.model.World;
import com.bladecoder.engine.util.EngineLogger;
import com.bladecoder.ink.runtime.Story.ExternalFunction;

public class ExternalFunctions {

	private InkManager inkManager;

	public ExternalFunctions() {
	}

	public void bindExternalFunctions(InkManager ink) throws Exception {

		this.inkManager = ink;

		// WARNING: Not use this function, use the set Command instead.
		inkManager.getStory().bindExternalFunction("setModelProp", new ExternalFunction() {

			@Override
			public Object call(Object[] args) throws Exception {

				try {
					World.getInstance().setModelProp(args[0].toString(), args[1].toString());
				} catch (Exception e) {
					EngineLogger.error("Ink setModelProp: " + e.getMessage());
				}

				return null;
			}
		});

		inkManager.getStory().bindExternalFunction("getModelProp", new ExternalFunction() {

			@Override
			public Object call(Object[] args) throws Exception {
				try {
					return World.getInstance().getModelProp(args[0].toString());
				} catch (Exception e) {
					EngineLogger.error("Ink getModelProp: " + e.getMessage());
				}

				return null;
			}
		});

		inkManager.getStory().bindExternalFunction("inInventory", new ExternalFunction() {

			@Override
			public Object call(Object[] args) throws Exception {
				return World.getInstance().getInventory().get(args[0].toString()) != null;
			}
		});
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy