/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.bindedobjects.core;
import transientlibs.processors.misc.Detonator;
import transientlibs.objects.primitives.Int;
import transientlibs.objects.primitives.TBoolean;
import gnu.trove.map.hash.TObjectIntHashMap;
import java.util.ArrayList;
import transientlibs.slick2d.util.Log;
import transientlibs.objects.primitives.BooleanSlot;
import transientlibs.objects.primitives.IntSlot;
import transientlibs.objects.primitives.StringSlot;
import transientlibs.objects.primitives.TString;
/**
*
* @author kibertoad
*/
public class Binding {
public final static int terrainBinding = 1;
public final static int skillBinding = 2;
public final static int storyBinding = 3;
public final static int branchBinding = 4;
public final static int globalValueBinding = 5;
public final static int valueBinding = 6;
public final static int stringBinding = 7;
public final static int globalTriggerBinding = 8;
public final static int localTriggerBinding = 9;
public final static int mapBinding = 10;
public final static int creatureBinding = 11;
public final static int weaponBinding = 12;
public final static int timerBinding = 13;
public final static int bodyPartBinding = 14;
public final static int perkBinding = 15;
public final static int statBinding = 16;
public final static int lookTypeBinding = 17;
public final static int nationBinding = 18;
public final static int stateBinding = 19;
public final static int jobBinding = 20;
public final static int actionBinding = 21;
public final static int actionGroupBinding = 22;
public final static int techBinding = 23;
public final static int researchBranchBinding = 24;
public final static int moduleBinding = 25;
public final static int missionBinding = 26;
//public final static int imageBinding = 27;
public final static int fontBinding = 28;
public final static int interfaceElementBinding = 29;
public final static int interfaceTypeBinding = 30;
public final static int landmarkBinding = 31;
public final static int musicBinding = 32;
public final static int soundBinding = 33;
public final static int effectBinding = 34;
public final static int itemBinding = 35;
public final static int animationBinding = 36;
public final static int missileBinding = 37;
public final static int shipModuleBinding = 38;
public final static int personalityTraitBinding = 39;
public final static int domainBinding = 40; //sports
public final static int activityTypeBinding = 41; //physical activity
public final static int activityBinding = 42; //playing football
public final static int motivationBinding = 43; //playing football
public final static int needBinding = 44;
public final static int npcBinding = 45;
public final static int groupBinding = 46;
public final static int longValueBinding = 47;
public final static int eventBinding = 48;
public final static int combatEffectBinding = 48;
public final static int equipmentSlotBinding = 49;
public final static int itemTypeBinding = 50;
public final static int globalInterfaceElementBinding = 51;
public final static int cardBinding = 52;
public final static int cardTypeBinding = 53;
public final static int transientImageBinding = 54;
public final static int characterBinding = 55;
public final static int rollOutcomeBinding = 56;
public final static int bindedObjectTypes = 70;
public static TObjectIntHashMap nowList;
public final static int lookList = 0;
public static TObjectIntHashMap[] bindingCodes = new TObjectIntHashMap[bindedObjectTypes];
public static ArrayList<TObjectIntHashMap[]> bindingListCodes = new ArrayList<TObjectIntHashMap[]>(); //for branching lists like looks
public static TObjectIntHashMap aliasBindingCodes = new TObjectIntHashMap();
public static ArrayList<String> aliases = new ArrayList<String>();
public static void newAlias(String bindCode, String alias) {
Log.debug("BindCode: " + bindCode);
Log.debug("Alias: " + alias);
if (!aliasBindingCodes.containsKey(bindCode)) {
aliasBindingCodes.put(bindCode, aliasBindingCodes.size());
aliases.add(alias);
} else {
Log.error("Alias already defined!");
}
}
public static String getAlias(String bindCode) {
if (aliasBindingCodes.containsKey(bindCode)) {
return aliases.get(aliasBindingCodes.get(bindCode));
} else {
Log.error("Alias '" + bindCode + "' is not defined!");
return null;
}
}
public static void newBinding(int bindType, String bindCode) {
if (!bindingCodes[bindType].containsKey(bindCode)) {
bindingCodes[bindType].put(bindCode, bindingCodes[bindType].size());
if (bindType == valueBinding) {
//Detonator.INSTANCE.values.add(new Int(0));
Detonator.INSTANCE.localVars.add(new IntSlot());
}
if (bindType == localTriggerBinding) {
Detonator.INSTANCE.localTriggers.add(new BooleanSlot());
}
if (bindType == globalValueBinding) {
//Detonator.INSTANCE.globalValues.add(new Int(0));
Detonator.INSTANCE.vars.add(new IntSlot());
}
if (bindType == globalTriggerBinding) {
Detonator.INSTANCE.triggers.add(new BooleanSlot());
}
if (bindType == stringBinding) {
Detonator.INSTANCE.strings.add(new StringSlot());
}
if (bindType == missionBinding) {
Detonator.INSTANCE.missionAvailable.add(new TBoolean(false));
}
if (bindType == techBinding) {
Detonator.INSTANCE.techResearched.add(new TBoolean(false));
Detonator.INSTANCE.techAvailable.add(new TBoolean(false));
}
} else {
Log.info("Key already stored!");
}
}
public static void newListBinding(int bindList, int bindType, String bindCode) {
nowList = bindingListCodes.get(bindList)[bindType];
if (!nowList.containsKey(bindCode)) {
nowList.put(bindCode, nowList.size());
} else {
Log.info("Key already stored!");
}
}
public static String getBindCodeAlt(int bindType, int bindID) {
if (bindingCodes[bindType].containsValue(bindID)) {
return (String) bindingCodes[bindType].keys()[bindID];
} else {
return null;
}
}
public static String getBindCode(int bindType, int bindID) {
Log.info((String) bindingCodes[bindType].keys()[0]);
// Log.info((String) bindingCodes[bindType].keys()[1]);
if (bindingCodes[bindType].containsValue(bindID)) {
return (String) bindingCodes[bindType].keys()[bindingCodes[bindType].keys().length - bindID - 1];
} else {
return null;
}
}
public static int getBinding(int bindType, String bindCode) {
if (bindType == landmarkBinding) {
//Log.info("Bind landmark now!");
}
//this one is the most useful
//Log.info("getBinding; type " + bindType + " with code '" + bindCode+"'");
//Log.info("now have "+bindingCodes[bindType].size()+" bindings.");
if (bindingCodes[bindType].containsKey(bindCode)) {
return bindingCodes[bindType].get(bindCode);
} else {
newBinding(bindType, bindCode);
//bindingCodes[bindType].put(bindCode, bindingCodes[bindType].size());
return bindingCodes[bindType].get(bindCode);
}
}
public static int getListBinding(int bindList, int bindType, String bindCode) {
//this one is useful too
//Log.debug("Bind type " + bindType + " with code '" + bindCode + "' in list " + bindList);
nowList = bindingListCodes.get(bindList)[bindType];
if (nowList.containsKey(bindCode)) {
return nowList.get(bindCode);
} else {
nowList.put(bindCode, nowList.size());
return nowList.get(bindCode);
}
}
public static int readBinding(int bindType, String bindCode) {
//useful
//Log.debug("Read binding for code '" + bindCode+"'");
if (bindingCodes[bindType].containsKey(bindCode)) {
return bindingCodes[bindType].get(bindCode);
} else {
Log.warn("Complete key list: ");
for (Object s: bindingCodes[bindType].keys()) {
Log.warn((String)s);
}
Log.error("Unknown bind key " + bindCode + ", type " + bindType);
return -1;
}
}
//can not find
public static int safeReadBinding(int bindType, String bindCode) {
if (bindingCodes[bindType].containsKey(bindCode)) {
return bindingCodes[bindType].get(bindCode);
} else {
return -1;
}
}
}