use of com.teamwizardry.wizardry.api.spell.module.ModuleModifier in project Wizardry by TeamWizardry.
the class ComponentWhitelistedModifiers method refresh.
public void refresh() {
if (worktable.selectedComponent == null) {
setVisible(false);
addTag("disabled");
return;
} else {
setVisible(true);
removeTag("disabled");
}
HashSet<GuiComponent> temp = new HashSet<>(list.getChildren());
for (GuiComponent component : temp) {
list.relationships.remove(component);
}
Module module = worktable.getModule(worktable.selectedComponent);
if (module == null)
return;
if (module.applicableModifiers() == null)
return;
if (Objects.requireNonNull(module.applicableModifiers()).length <= 0)
return;
ModuleModifier[] modifiers = module.applicableModifiers();
if (modifiers == null)
return;
for (ModuleModifier modifier : modifiers) {
ComponentRect bar = new ComponentRect(0, 0, getSize().getXi(), 16);
bar.getColor().setValue(new Color(0x80000000, true));
ComponentSprite plate = new ComponentSprite(TableModule.plate, 0, 0, 16, 16);
bar.add(plate);
Sprite icon = new Sprite(new ResourceLocation(Wizardry.MODID, "textures/gui/worktable/icons/" + modifier.getID() + ".png"));
ComponentSprite iconComp = new ComponentSprite(icon, 2, 2, 12, 12);
plate.add(iconComp);
ComponentText text = new ComponentText(20, 4, ComponentText.TextAlignH.LEFT, ComponentText.TextAlignV.TOP);
text.getText().setValue(TextFormatting.GREEN + modifier.getShortHandName());
bar.add(text);
bar.render.getTooltip().func((Function<GuiComponent, java.util.List<String>>) t -> {
List<String> txt = new ArrayList<>();
for (GuiComponent comp : worktable.paperComponents.keySet()) if (comp.hasTag("dragging"))
return txt;
txt.add(TextFormatting.GOLD + module.getReadableName());
if (GuiScreen.isShiftKeyDown())
txt.add(TextFormatting.GRAY + module.getDescription());
else
txt.add(TextFormatting.GRAY + LibrarianLib.PROXY.translate("wizardry.misc.sneak"));
return txt;
});
bar.BUS.hook(GuiComponentEvents.MouseInEvent.class, event -> {
bar.getColor().setValue(new Color(0x66000000, true));
});
bar.BUS.hook(GuiComponentEvents.MouseOutEvent.class, event -> {
bar.getColor().setValue(new Color(0x80000000, true));
});
bar.BUS.hook(GuiComponentEvents.MouseDownEvent.class, event -> {
if (event.component.getMouseOver()) {
bar.getColor().setValue(new Color(0x4D000000, true));
}
});
bar.BUS.hook(GuiComponentEvents.MouseUpEvent.class, event -> {
if (event.component.getMouseOver()) {
bar.getColor().setValue(new Color(0x80000000, true));
}
});
bar.BUS.hook(GuiComponentEvents.MouseClickEvent.class, (event) -> {
if (!event.component.getMouseOver())
return;
int i = worktable.selectedComponent.hasData(Integer.class, modifier.getID()) ? worktable.selectedComponent.getData(Integer.class, modifier.getID()) : 0;
int status = -1;
if (event.getButton() == EnumMouseButton.LEFT) {
worktable.selectedComponent.setData(Integer.class, modifier.getID(), ++i);
status = 0;
} else if (event.getButton() == EnumMouseButton.RIGHT) {
if (worktable.selectedComponent.hasData(Integer.class, modifier.getID())) {
if (worktable.selectedComponent.getData(Integer.class, modifier.getID()) > 0) {
worktable.selectedComponent.setData(Integer.class, modifier.getID(), --i);
status = 1;
} else {
worktable.selectedComponent.removeData(Integer.class, modifier.getID());
}
}
}
ComponentSprite fakePlate = new ComponentSprite(TableModule.plate, 0, 0, 16, 16);
bar.add(fakePlate);
ComponentSprite fakeIconComp = new ComponentSprite(icon, 2, 2, 12, 12);
fakePlate.add(fakeIconComp);
ScheduledEventAnimation scheduled = new ScheduledEventAnimation(20, fakePlate::invalidate);
Vec2d r = worktable.selectedComponent.thisPosToOtherContext(bar);
KeyframeAnimation<ComponentSprite> animX = new KeyframeAnimation<>(fakePlate, "pos.x");
animX.setDuration(20);
if (status == 0) {
animX.setKeyframes(new Keyframe[] { new Keyframe(0, 0, Easing.linear), new Keyframe(1f, r.getX(), Easing.easeInBack) });
} else if (status == 1) {
animX.setKeyframes(new Keyframe[] { new Keyframe(0, r.getX(), Easing.linear), new Keyframe(1f, 0, Easing.easeInBack) });
}
KeyframeAnimation<ComponentSprite> animY = new KeyframeAnimation<>(fakePlate, "pos.y");
animY.setDuration(20);
if (status == 0) {
animY.setKeyframes(new Keyframe[] { new Keyframe(0, 0, Easing.linear), new Keyframe(1f, r.getY(), Easing.easeInBack) });
} else if (status == 1) {
animX.setKeyframes(new Keyframe[] { new Keyframe(0, r.getY(), Easing.linear), new Keyframe(1f, 0, Easing.easeInBack) });
}
worktable.getMainComponents().add(scheduled, animX, animY);
});
list.add(bar);
}
}
use of com.teamwizardry.wizardry.api.spell.module.ModuleModifier in project Wizardry by TeamWizardry.
the class SpellRing method processModifiers.
/**
* Will process all modifiers and attributes set.
* WILL RESET THE INFORMATION TAG.
*/
public void processModifiers() {
informationTag = new NBTTagCompound();
if (module != null) {
module.getAttributeRanges().forEach((attribute, range) -> {
informationTag.setDouble(attribute.getNbtName(), range.base);
});
}
List<AttributeModifier> attributeModifiers = new ArrayList<>();
if (module != null)
attributeModifiers.addAll(module.getAttributes());
for (ModuleModifier modifier : getModifiers().keySet()) {
for (int i = 0; i < getModifiers().get(modifier); i++) attributeModifiers.addAll(modifier.getAttributes());
}
ArrayListMultimap<Operation, AttributeModifier> sortedMap = ArrayListMultimap.create();
for (AttributeModifier modifier : attributeModifiers) sortedMap.put(modifier.getOperation(), modifier);
for (Operation op : Operation.values()) {
for (AttributeModifier modifier : sortedMap.get(op)) {
double current = informationTag.getDouble(modifier.getAttribute().getNbtName());
double newValue = modifier.apply(current);
informationTag.setDouble(modifier.getAttribute().getNbtName(), newValue);
// Wizardry.logger.info(module == null ? "<null module>" : module.getID() + ": Attribute: " + attribute + ": " + current + "-> " + newValue);
}
}
}
use of com.teamwizardry.wizardry.api.spell.module.ModuleModifier in project Wizardry by TeamWizardry.
the class SpellRing method deserializeNBT.
@Override
public void deserializeNBT(NBTTagCompound nbt) {
if (nbt.hasKey("module"))
this.module = Module.deserialize(nbt.getString("module"));
if (nbt.hasKey("extra"))
informationTag = nbt.getCompoundTag("extra");
if (nbt.hasKey("primary_color"))
primaryColor = Color.decode(nbt.getString("primary_color"));
if (nbt.hasKey("secondary_color"))
secondaryColor = Color.decode(nbt.getString("secondary_color"));
if (nbt.hasKey("modifiers")) {
modifiers.clear();
for (NBTBase base : nbt.getTagList("modifiers", Constants.NBT.TAG_COMPOUND)) if (base instanceof NBTTagCompound) {
NBTTagCompound modifierComound = (NBTTagCompound) base;
if (modifierComound.hasKey("modifier") && modifierComound.hasKey("count")) {
ModuleModifier moduleModifier = (ModuleModifier) Module.deserialize(modifierComound.getString("modifier"));
if (moduleModifier == null)
continue;
modifiers.put(moduleModifier, modifierComound.getInteger("count"));
}
}
}
if (nbt.hasKey("child_ring")) {
SpellRing childRing = deserializeRing(nbt.getCompoundTag("child_ring"));
childRing.setParentRing(this);
setChildRing(childRing);
}
}
use of com.teamwizardry.wizardry.api.spell.module.ModuleModifier in project Wizardry by TeamWizardry.
the class WorktableGui method compileModule.
private void compileModule(ArrayList<Module> stream, @Nullable GuiComponent component) {
if (component == null)
return;
Module module = getModule(component);
if (module == null)
return;
stream.add(module);
for (Module modifier : ModuleRegistry.INSTANCE.getModules(ModuleType.MODIFIER)) {
if (!(modifier instanceof ModuleModifier))
continue;
if (component.hasData(Integer.class, modifier.getID())) {
int x = component.getData(Integer.class, modifier.getID());
for (int i = 0; i < x; i++) {
stream.add(modifier);
}
}
}
if (!componentLinks.containsKey(getUUID(component)))
return;
UUID uuidChild = componentLinks.get(getUUID(component));
GuiComponent childComp = getComponent(uuidChild);
if (childComp == null)
return;
Module child = getModule(childComp);
if (child == null)
return;
compileModule(stream, childComp);
}
use of com.teamwizardry.wizardry.api.spell.module.ModuleModifier in project Wizardry by TeamWizardry.
the class SpellBuilder method toSpell.
private List<SpellRing> toSpell(List<ItemStack> inventory) {
List<SpellRing> spellList = new ArrayList<>();
Set<List<SpellRing>> spellChains = new HashSet<>();
List<List<ItemStack>> lines = brancher(inventory, codeLineBreak);
// Spell chain from multiple chains
for (List<ItemStack> line : lines) {
// List is made of all modules that aren't modifiers for this spellData chain.
Deque<SpellRing> uncompressedChain = new ArrayDeque<>();
// Step through each item in line. If modifier, add to lastModule, if not, add to compiled.
for (ItemStack stack : line) {
Module module = ModuleRegistry.INSTANCE.getModule(stack);
if (module == null)
continue;
if (module instanceof ModuleModifier) {
if (!uncompressedChain.isEmpty()) {
for (int i = 0; i < stack.getCount(); i++) {
SpellRing lastRing = uncompressedChain.peekLast();
lastRing.addModifier((ModuleModifier) module);
}
}
} else {
for (int i = 0; i < stack.getCount(); i++) {
SpellRing ring = new SpellRing(module);
uncompressedChain.add(ring);
}
}
}
spellChains.add(new ArrayList<>(uncompressedChain));
}
// We now have a code line of modules. link them as children in order.
for (List<SpellRing> rings : spellChains) {
if (rings.isEmpty())
continue;
Deque<SpellRing> deque = new ArrayDeque<>(rings);
SpellRing ringHead = deque.pop();
SpellRing lastRing = ringHead;
while (!deque.isEmpty()) {
SpellRing child = deque.pop();
lastRing.setChildRing(child);
child.setParentRing(lastRing);
lastRing = child;
}
spellList.add(ringHead);
}
for (SpellRing ring : spellList) {
SpellRing chainEnd = ring;
while (chainEnd != null) {
if (chainEnd.getChildRing() == null) {
chainEnd.processModifiers();
if (chainEnd.getModule() != null) {
chainEnd.setPrimaryColor(chainEnd.getModule().getPrimaryColor());
chainEnd.setSecondaryColor(chainEnd.getModule().getSecondaryColor());
}
chainEnd.updateColorChain();
break;
}
chainEnd.processModifiers();
chainEnd = chainEnd.getChildRing();
}
}
return spellList;
}
Aggregations