Skip to content

Commit

Permalink
metabox idle animation. Now has user-specific characters
Browse files Browse the repository at this point in the history
  • Loading branch information
ianfhunter committed Apr 29, 2014
1 parent 1d29c17 commit d4abc26
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 23 deletions.
Binary file added hero.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
101 changes: 78 additions & 23 deletions wordpress-rpg.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,43 @@
/*
Plugin Name: Wordpress RPG
Plugin URI:
Description: Incetivize your blogging with RPG Meta-elements
Description: Incentivize your blogging with RPG Meta-elements
Author: Ian Hunter
Version: 0.0
Author URI: www.ianhunter.ie
*/


#The info display in the top right hand corner
#Returns a user's active quest
function get_quest(){
$file = WP_PLUGIN_DIR."/Wordpress-RPG/experience" . get_current_user_id() . ".rpg";
$json = file_get_contents ( $file );
if ($json == ""){
$quest = "None";
}else{
$jsonD = json_decode($json);
$quest = $jsonD->{"quest"};
}
return $quest;
}


#The info display in the top right hand corner.
function admin_info_header() {
$file = WP_PLUGIN_DIR."/Wordpress-RPG/experience.rpg";
$experience = file_get_contents ( $file );
$file = WP_PLUGIN_DIR."/Wordpress-RPG/experience".get_current_user_id().".rpg";
$json = file_get_contents ( $file );
$jsonD = json_decode($json);
$experience = $jsonD->{"total_experience"};
$stats = calc_level($experience);
echo '<div style="float:right">Level ' . $stats[0] . ' Templar - ' . $stats[1] . '/' . $stats[2] .' Exp - 2 Quests</div>';
$quest = $jsonD->{"quest"};

echo '<div style="float:right">⚔ Level ' . $stats[0] . ' Templar - ' . $stats[1] . '/' . $stats[2] .' Exp - Quest: '. $quest.'</div>';
}

#Calculates what level you are given your experience
#Level 1 = 40
#Level N+1 = 1.6 * N

#Returns: Level, Remaining Exp, Next Level EXP
function calc_level($experience){
$level = 500;
$modifier = 1.6;
Expand All @@ -33,31 +51,68 @@ function calc_level($experience){
return array($count,$experience,$level);
}

#Gives menu item in settings
function rpg_menu() {
add_options_page( 'RPG Settings', 'Wordpress RPG', 'manage_options', 'wordpress-rpg', 'rpg_options' );
#Adds experience upon posting, based on character count
function add_experience() {
$file = WP_PLUGIN_DIR."/Wordpress-RPG/experience" . get_current_user_id() . ".rpg";
$json = file_get_contents ( $file );
if ($json == ""){
$experience = 0;
$quest = "None";
}else{
$jsonD = json_decode($json);
$experience = $jsonD->{"total_experience"};
$quest = $jsonD->{"quest"};
}

#Should check if quest is complete & Optionally assign a new task
#Quests should be a 'write a post with X tag/category' - Other types?
$exp = strlen($_POST['content']) + $experience;
$json = json_encode(array(
"total_experience" => $exp,
"quest" => $quest
));
file_put_contents ( $file ,$json );
}

#Forms in settings menu item
function rpg_options() {
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
#Activates a quest
function add_quest($quest_title){
$file = WP_PLUGIN_DIR."/Wordpress-RPG/experience" . get_current_user_id() . ".rpg";
$json = file_get_contents ( $file );
if ($json == ""){
$experience = 0;
}else{
$jsonD = json_decode($json);
$experience = $jsonD->{"total_experience"};
}
echo '<div class="wrap">';
echo '<p>Here is where the form would go if I actually had options.</p>';
echo '</div>';

$json = json_encode(array(
"total_experience" => $experience,
"quest" => $quest_title
));
file_put_contents ( $file ,$json );
}

#Adds experience upon posting
function add_experience() {
$file = WP_PLUGIN_DIR."/Wordpress-RPG/experience.rpg";
$experience = file_get_contents ( $file );
$exp = strlen($_POST['content']) + $experience;
file_put_contents ( $file ,$exp );
function quest_metabox(){
add_meta_box("rpg-metabox", "Wordpress RPG", draw_metabox, 'post', 'side', 'high');
}
function draw_metabox(){
#Would be really nice to rotate through some phrases here.
#And also have avatars based on your character
echo " <img src='".plugins_url()."/Wordpress-RPG/hero.gif' /> " . "Killing some slimes... " ;
#Credit: http://leon-murayami.deviantart.com/art/Illusion-of-Gaia-Will-XP-402827050

#maybe echo active quest.
#echo get_quest()

}


add_action('admin_bar_menu', 'admin_info_header');
add_action('admin_menu', 'rpg_menu' );
#add_action('admin_menu', 'rpg_menu' );
add_action('publish_post', 'add_experience' );

add_action('add_meta_boxes', 'quest_metabox' );
add_action('save_post', 'save_quest_draft' );

?>

0 comments on commit d4abc26

Please sign in to comment.