Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
737 changes: 374 additions & 363 deletions src/me/goddragon/teaseai/api/chat/ChatParticipant.java

Large diffs are not rendered by default.

699 changes: 380 additions & 319 deletions src/me/goddragon/teaseai/api/media/MediaHandler.java

Large diffs are not rendered by default.

562 changes: 289 additions & 273 deletions src/me/goddragon/teaseai/api/picture/PictureHandler.java

Large diffs are not rendered by default.

134 changes: 97 additions & 37 deletions src/me/goddragon/teaseai/api/picture/PictureSelector.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,97 @@
package me.goddragon.teaseai.api.picture;

import me.goddragon.teaseai.TeaseAI;
import me.goddragon.teaseai.api.chat.ChatParticipant;
import me.goddragon.teaseai.api.session.Session;

import java.util.concurrent.TimeUnit;

/**
* Created by GodDragon on 26.03.2018.
*/
public class PictureSelector {

public TaggedPicture getPicture(Session session, ChatParticipant participant) {
if(participant.getPictureSet().getTaggedPictures().isEmpty()) {
return null;
}

long minutesPassed = TimeUnit.MILLISECONDS.toMinutes(session.getRuntime());
int preferredSessionDuration = TeaseAI.application.PREFERRED_SESSION_DURATION.getInt();
double percentage = minutesPassed/preferredSessionDuration*100D;

if(percentage > 80) {
return participant.getPictureSet().getRandomPictureForStates(DressState.NAKED, DressState.SEE_THROUGH);
} else if(percentage > 60) {
return participant.getPictureSet().getRandomPictureForStates(DressState.HANDS_COVERING);
} else if(percentage > 40) {
return participant.getPictureSet().getRandomPictureForStates(DressState.GARMENT_COVERING);
} else if(percentage > 20) {
return participant.getPictureSet().getRandomPictureForStates(DressState.HALF_DRESSED);
} else if(percentage > 10) {
return participant.getPictureSet().getRandomPictureForStates(DressState.FULLY_DRESSED, DressState.HALF_DRESSED);
} else {
return participant.getPictureSet().getRandomPicture(DressState.FULLY_DRESSED, PictureTag.FACE);
}
}
}
package me.goddragon.teaseai.api.picture;

import me.goddragon.teaseai.TeaseAI;
import me.goddragon.teaseai.api.chat.ChatParticipant;
import me.goddragon.teaseai.api.session.Session;
import me.goddragon.teaseai.utils.TeaseLogger;

import java.io.File;
import java.io.FilenameFilter;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;

/**
* Created by GodDragon on 26.03.2018.
*/
public class PictureSelector {

public TaggedPicture getPicture(Session session, ChatParticipant participant) {
if(participant.getPictureSet().getTaggedPictures().isEmpty() && participant.getPictureSet().getFolder().listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return (name.toLowerCase().endsWith(".jpg") || name.toLowerCase().endsWith(".png") || name.toLowerCase().endsWith(".gif"));
}
}).length == 0) {
return null;
}

long minutesPassed = TimeUnit.MILLISECONDS.toMinutes(session.getRuntime());
int preferredSessionDuration = TeaseAI.application.PREFERRED_SESSION_DURATION.getInt();
double percentage = minutesPassed/preferredSessionDuration*100D;

if (percentage <= 10)
{
TaggedPicture toReturn = participant.getPictureSet().getRandomPicture(DressState.FULLY_DRESSED, PictureTag.FACE);
if (toReturn != null)
{
return toReturn;
}
}
if (percentage <= 20)
{
TaggedPicture toReturn = participant.getPictureSet().getRandomPictureForStates(DressState.FULLY_DRESSED, DressState.HALF_DRESSED);
if (toReturn != null)
{
return toReturn;
}
}
if (percentage <= 40)
{
TaggedPicture toReturn = participant.getPictureSet().getRandomPictureForStates(DressState.HALF_DRESSED);
if (toReturn != null)
{
return toReturn;
}
}
if (percentage <= 60)
{
TaggedPicture toReturn = participant.getPictureSet().getRandomPictureForStates(DressState.GARMENT_COVERING);
if (toReturn != null)
{
return toReturn;
}
}
if (percentage <= 80)
{
TaggedPicture toReturn = participant.getPictureSet().getRandomPictureForStates(DressState.HANDS_COVERING);
if (toReturn != null)
{
return toReturn;
}
}
TaggedPicture toReturn = participant.getPictureSet().getRandomPictureForStates(DressState.NAKED, DressState.SEE_THROUGH);
if (toReturn != null)
{
return toReturn;
}
else
{
File setFolder = participant.getPictureSet().getFolder();
File[] locFiles = setFolder.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return (name.toLowerCase().endsWith(".jpg") || name.toLowerCase().endsWith(".png") || name.toLowerCase().endsWith(".gif"));
}
});
if (locFiles.length == 0)
{
TeaseLogger.getLogger().log(Level.SEVERE, "Image set selected has no images!!");
return null;
}

Random random = new Random();
return new TaggedPicture(locFiles[random.nextInt(locFiles.length)]);
}
}
}
230 changes: 115 additions & 115 deletions src/me/goddragon/teaseai/api/picture/PictureSet.java
Original file line number Diff line number Diff line change
@@ -1,115 +1,115 @@
package me.goddragon.teaseai.api.picture;

import me.goddragon.teaseai.utils.RandomUtils;
import me.goddragon.teaseai.utils.TeaseLogger;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;

/**
* Created by GodDragon on 26.03.2018.
*/
public class PictureSet {

private final List<TaggedPicture> taggedPictures = new ArrayList<>();

public PictureSet(File folder) {
TagsFile tagFile = TagsFile.getTagsFile(folder);

/*for (File file : folder.listFiles()) {
if (file.isFile() && file.getName().endsWith(".txt")) {
tagFile = file;
break;
}
}*/

if(tagFile == null) {
TeaseLogger.getLogger().log(Level.SEVERE, "Folder '" + folder.getAbsolutePath() + "' is missing a tags file.");
return;
}

for(File taggedFile : tagFile.getTaggedFiles()) {
taggedPictures.add(new TaggedPicture(taggedFile));
}
}

public TaggedPicture getRandomPictureForStates(DressState... dressStates) {
return getRandomPictureForTagStates(taggedPictures, Arrays.asList(dressStates), new ArrayList<>());
}

public TaggedPicture getRandomPicture(DressState dressState, PictureTag... pictureTags) {
return getRandomPictureForTagStates(Arrays.asList(new DressState[] {dressState}), Arrays.asList(pictureTags));
}

public TaggedPicture getRandomPicture(List<TaggedPicture> taggedPictures, PictureTag... pictureTags) {
return getRandomPicture(taggedPictures, Arrays.asList(pictureTags));
}

public TaggedPicture getRandomPicture(List<TaggedPicture> taggedPictures, List<PictureTag> pictureTags) {
return getRandomPictureForTagStates(taggedPictures, new ArrayList<>(), pictureTags);
}

public TaggedPicture getRandomPictureForTagStates(List<DressState> dressStates, List<PictureTag> pictureTags) {
return getRandomPictureForTagStates(taggedPictures, dressStates, pictureTags);
}


public TaggedPicture getRandomPictureForTagStates(List<TaggedPicture> taggedPictures, List<DressState> dressStates, List<PictureTag> pictureTags) {
List<TaggedPicture> validPictures = new ArrayList<>();

pictureLoop:
for (TaggedPicture taggedPicture : taggedPictures) {
//Remove all pictures that don't have a specific tag
for (PictureTag pictureTag : pictureTags) {
if (pictureTag != null && !taggedPicture.hasTag(pictureTag)) {
continue pictureLoop;
}
}

//If we are supposed to search for a specific dress state we check whether our picture fits those guidelines
if(!dressStates.isEmpty() && !dressStates.contains(taggedPicture.getDressState())) {
continue pictureLoop;
}

//If we reach this point the image is good to display
validPictures.add(taggedPicture);
}

if (validPictures.isEmpty()) {
//Find the dress state in the list which shows least
DressState lowestDressState = null;
for (DressState dressState : dressStates) {
if (lowestDressState == null || lowestDressState.getRank() > dressState.getRank()) {
lowestDressState = dressState;
}
}

DressState lowerDressState = lowestDressState.getNextLowerRank();

//Try finding an alternative image that shows less
if (lowerDressState != null) {
return getRandomPictureForTagStates(Arrays.asList(new DressState[] {lowerDressState}), pictureTags);
}

//We don't have any pictures to show anyway
if (taggedPictures.isEmpty()) {
return null;
}
//Okay we have been beaten. Show a random image
else {
return taggedPictures.get(RandomUtils.randInt(0, taggedPictures.size() - 1));
}
}

return validPictures.get(RandomUtils.randInt(0, validPictures.size() - 1));
}


public Collection<TaggedPicture> getTaggedPictures() {
return taggedPictures;
}
}
package me.goddragon.teaseai.api.picture;
import me.goddragon.teaseai.utils.RandomUtils;
import me.goddragon.teaseai.utils.TeaseLogger;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;
/**
* Created by GodDragon on 26.03.2018.
*/
public class PictureSet {
private final List<TaggedPicture> taggedPictures = new ArrayList<>();
private final File folder;
public PictureSet(File folder) {
this.folder = folder;
TagsFile tagFile = TagsFile.getTagsFile(folder);
if(tagFile == null) {
TeaseLogger.getLogger().log(Level.SEVERE, "Folder '" + folder.getAbsolutePath() + "' is missing a tags file.");
return;
}
for(File taggedFile : tagFile.getTaggedFiles()) {
taggedPictures.add(new TaggedPicture(taggedFile, true));
}
}
public TaggedPicture getRandomPictureForStates(DressState... dressStates) {
return getRandomPictureForTagStates(taggedPictures, Arrays.asList(dressStates), new ArrayList<>());
}
public TaggedPicture getRandomPicture(DressState dressState, PictureTag... pictureTags) {
return getRandomPictureForTagStates(Arrays.asList(new DressState[] {dressState}), Arrays.asList(pictureTags));
}
public TaggedPicture getRandomPicture(List<TaggedPicture> taggedPictures, PictureTag... pictureTags) {
return getRandomPicture(taggedPictures, Arrays.asList(pictureTags));
}
public TaggedPicture getRandomPicture(List<TaggedPicture> taggedPictures, List<PictureTag> pictureTags) {
return getRandomPictureForTagStates(taggedPictures, new ArrayList<>(), pictureTags);
}
public TaggedPicture getRandomPictureForTagStates(List<DressState> dressStates, List<PictureTag> pictureTags) {
return getRandomPictureForTagStates(taggedPictures, dressStates, pictureTags);
}
public TaggedPicture getRandomPictureForTagStates(List<TaggedPicture> taggedPictures, List<DressState> dressStates, List<PictureTag> pictureTags) {
List<TaggedPicture> validPictures = new ArrayList<>();
pictureLoop:
for (TaggedPicture taggedPicture : taggedPictures) {
//Remove all pictures that don't have a specific tag
for (PictureTag pictureTag : pictureTags) {
if (pictureTag != null && !taggedPicture.hasTag(pictureTag)) {
continue pictureLoop;
}
}
//If we are supposed to search for a specific dress state we check whether our picture fits those guidelines
if(!dressStates.isEmpty() && !dressStates.contains(taggedPicture.getDressState())) {
continue pictureLoop;
}
//If we reach this point the image is good to display
validPictures.add(taggedPicture);
}
if (validPictures.isEmpty()) {
//Find the dress state in the list which shows least
DressState lowestDressState = null;
for (DressState dressState : dressStates) {
if (lowestDressState == null || lowestDressState.getRank() > dressState.getRank()) {
lowestDressState = dressState;
}
}
DressState lowerDressState = lowestDressState.getNextLowerRank();
//Try finding an alternative image that shows less
if (lowerDressState != null) {
return getRandomPictureForTagStates(Arrays.asList(new DressState[] {lowerDressState}), pictureTags);
}
//We don't have any pictures to show anyway
if (taggedPictures.isEmpty()) {
return null;
}
//Okay we have been beaten. Show a random image
else {
return taggedPictures.get(RandomUtils.randInt(0, taggedPictures.size() - 1));
}
}
return validPictures.get(RandomUtils.randInt(0, validPictures.size() - 1));
}
public Collection<TaggedPicture> getTaggedPictures() {
return taggedPictures;
}
public File getFolder()
{
return folder;
}
}
Loading