Skip to content

Instantly share code, notes, and snippets.

@superckl
Created September 16, 2014 20:34
Show Gist options
  • Save superckl/7f7e57e682b8c3a8cfcd to your computer and use it in GitHub Desktop.
Save superckl/7f7e57e682b8c3a8cfcd to your computer and use it in GitHub Desktop.
Baked Map
public class PartSelectionManager {
private Material[] materials;
private int matIndex;
private List<BoatPart>[] parts;
private int partIndex;
public PartSelectionManager add(Material material, List<BoatPart> parts){
if(material == null || parts == null)
return this;
if(parts.size() < 1)
return this;
int index;
if((index = CollectionHelper.find(material, materials)) != -1){
List<BoatPart> partList = this.parts[index];
partList.addAll(parts);
}else{
index = materials.length;
this.materials = Arrays.copyOf(materials, index+1);
this.parts = Arrays.copyOf(this.parts, index+1);
this.materials[index] = material;
this.parts[index] = parts;
}
return this;
}
public BoatPart get(){
return this.parts[this.matIndex].get(partIndex);
}
public Material nextMaterial(){
if(matIndex == this.materials.length - 1)
this.matIndex = -1;
return this.materials[++this.matIndex];
}
public BoatPart nextPart(){
if(partIndex > this.parts[this.matIndex].size()-1)
this.partIndex = -1;
return this.parts[this.matIndex].get(++partIndex);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment