<commit_before>/*
 * To change this template, choose Tools | Templates and open the template in the editor.
 */
package model.builders.actors;

import geometry.math.MyRandom;
import geometry.tools.LogUtil;

import java.util.ArrayList;
import java.util.List;

import model.battlefield.actors.Actor;
import model.builders.Builder;
import model.builders.definitions.BuilderLibrary;
import model.builders.definitions.DefElement;
import model.builders.definitions.Definition;

/**
 * @author Benoît
 */
public class ActorBuilder extends Builder {
	public static final String TYPE = "Type";

	public static final String TYPE_MODEL = "Model";
	public static final String TYPE_PARTICLE = "Particle";
	public static final String TYPE_ANIMATION = "Animation";
	public static final String TYPE_PHYSIC = "Physic";
	public static final String TYPE_SOUND = "Sound";

	protected static final String ACTOR_LIST = "ActorList";
	protected static final String TRIGGER = "Trigger";
	protected static final String PROB = "Prob";
	protected static final String ACTOR_LINK = "ActorLink";

	protected String type;
	private List<String> childrenActorBuildersID = new ArrayList<>();
	protected List<ActorBuilder> childrenActorBuilders = new ArrayList<>();
	protected List<String> childrenTriggers = new ArrayList<>();
	protected List<Double> childrenProbs = new ArrayList<>();

	public ActorBuilder(Definition def, BuilderLibrary lib) {
		super(def, lib);
		for (DefElement de : def.elements) {
			switch (de.name) {
				case TYPE:
					type = de.getVal();
					break;
				case ACTOR_LIST:
					childrenActorBuildersID.add(de.getVal(ACTOR_LINK));
					childrenTriggers.add(de.getVal(TRIGGER));
					if (de.getVal(PROB) != null) {
						childrenProbs.add(de.getDoubleVal(PROB));
					} else {
						childrenProbs.add(1d);
					}
					break;
			}
		}
	}

	public Actor build(String trigger, Actor parent) {
		List<ActorBuilder> localChildrenActorBuilders = new ArrayList<>();
		List<String> localChildrenTriggers = new ArrayList<>();

		int i = 0;
		for (ActorBuilder b : childrenActorBuilders) {
			if (MyRandom.next() < childrenProbs.get(i)) {
				localChildrenActorBuilders.add(b);
				localChildrenTriggers.add(childrenTriggers.get(i));
			}
			i++;
		}

		Actor res = new Actor(parent, trigger, localChildrenTriggers, localChildrenActorBuilders, lib.battlefield.actorPool);
		res.debbug_id = getId();
		return res;
	}

	@Override
	public void readFinalizedLibrary() {
		for (String s : childrenActorBuildersID) {
			childrenActorBuilders.add(lib.getActorBuilder(s));
		}
		if (childrenActorBuilders.size() != childrenTriggers.size()) {
			LogUtil.logger.info("fuck " + def.id);
		}
	}

}<commit_msg>deletion of useless code<commit_after>/*
 * To change this template, choose Tools | Templates and open the template in the editor.
 */
package model.builders.actors;

import geometry.math.MyRandom;
import geometry.tools.LogUtil;

import java.util.ArrayList;
import java.util.List;

import model.battlefield.actors.Actor;
import model.builders.Builder;
import model.builders.definitions.BuilderLibrary;
import model.builders.definitions.DefElement;
import model.builders.definitions.Definition;

/**
 * @author Benoît
 */
public class ActorBuilder extends Builder {
	public static final String TYPE = "Type";

	public static final String TYPE_MODEL = "Model";
	public static final String TYPE_PARTICLE = "Particle";
	public static final String TYPE_ANIMATION = "Animation";
	public static final String TYPE_PHYSIC = "Physic";
	public static final String TYPE_SOUND = "Sound";

	protected static final String ACTOR_LIST = "ActorList";
	protected static final String TRIGGER = "Trigger";
	protected static final String PROB = "Prob";
	protected static final String ACTOR_LINK = "ActorLink";

	protected String type;
	private List<String> childrenActorBuildersID = new ArrayList<>();
	protected List<ActorBuilder> childrenActorBuilders = new ArrayList<>();
	protected List<String> childrenTriggers = new ArrayList<>();
	protected List<Double> childrenProbs = new ArrayList<>();

	public ActorBuilder(Definition def, BuilderLibrary lib) {
		super(def, lib);
		for (DefElement de : def.elements) {
			switch (de.name) {
				case TYPE:
					type = de.getVal();
					break;
				case ACTOR_LIST:
					childrenActorBuildersID.add(de.getVal(ACTOR_LINK));
					childrenTriggers.add(de.getVal(TRIGGER));
					if (de.getVal(PROB) != null) {
						childrenProbs.add(de.getDoubleVal(PROB));
					} else {
						childrenProbs.add(1d);
					}
					break;
			}
		}
	}

	public Actor build(String trigger, Actor parent) {
		List<ActorBuilder> localChildrenActorBuilders = new ArrayList<>();
		List<String> localChildrenTriggers = new ArrayList<>();

		int i = 0;
		for (ActorBuilder b : childrenActorBuilders) {
			if (MyRandom.next() < childrenProbs.get(i)) {
				localChildrenActorBuilders.add(b);
				localChildrenTriggers.add(childrenTriggers.get(i));
			}
			i++;
		}

		Actor res = new Actor(parent, trigger, localChildrenTriggers, localChildrenActorBuilders, lib.battlefield.actorPool);
		res.debbug_id = getId();
		return res;
	}

	@Override
	public void readFinalizedLibrary() {
		for (String s : childrenActorBuildersID) {
			childrenActorBuilders.add(lib.getActorBuilder(s));
		}
	}

}
{'fraction_non_alphanumeric': 0.10986290936785986, 'fraction_numerical': 0.0007616146230007616, 'mean_word_length': 4.612179487179487, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '818454', 'n_tokens_mistral': 1769, 'n_tokens_neox': 1583, 'n_words': 412}