Skip to content

Instantly share code, notes, and snippets.

@BallerIndustries
Created June 13, 2019 16:27
Show Gist options
  • Save BallerIndustries/e833b89b9972a516995313eb8ef334a9 to your computer and use it in GitHub Desktop.
Save BallerIndustries/e833b89b9972a516995313eb8ef334a9 to your computer and use it in GitHub Desktop.
package com.dkc.pp.util;
import android.content.Context;
import android.widget.ImageView;
import com.dkc.pp.character.PPCharacter;
import com.squareup.picasso.Picasso;
import java.util.Map;
import java.util.regex.Pattern;
/**
* Created by Angus on 21/10/13.
*/
public class Globals
{
public static final String EXTRA_PLUSPLUS_CHARACTER_ID = "com.dkc.pp.PLUSPLUS_CHARACTER_ID";
public static final Pattern PLAYER_NAME_PATTERN = Pattern.compile("\\[playername\\]", Pattern.CASE_INSENSITIVE);
public void setCharacterProfilePic(Context context, PPCharacter character, ImageView view) {
Picasso.with(context).load(character.createAssetUrl(character.getProfilePicFilename())).into(view);
}
public boolean processPredicate(String predicate, Map<String, Integer> variables) {
String[] tmp = predicate.split(" ");
if (tmp.length != 3) {
throw new RuntimeException("Woah woah woah! I don't want you to send all this nonsense that I am unable to handle!");
}
if (variables.containsKey(tmp[0])) {
tmp[0] = variables.get(tmp[0]).toString();
}
if (variables.containsKey(tmp[1])) {
tmp[1] = variables.get(tmp[1]).toString();
}
String operation = tmp[1];
int leftOperand = Integer.parseInt(tmp[0]);
int rightOperand = Integer.parseInt(tmp[2]);
switch (operation) {
case "<":
return leftOperand < rightOperand;
case ">":
return leftOperand > rightOperand;
case ">=":
return leftOperand >= rightOperand;
case "<=":
return leftOperand <= rightOperand;
case "==":
return leftOperand == rightOperand;
default:
throw new RuntimeException(String.format("Listen you mother fucker, I'm not interested in that operation. Take your %s and fuck off!", operation));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment