ONO::FW::Edu::Apps::Modules::Skiing

package ONO::FW::Edu::Apps::Modules::Skiing;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2022-2026 Jos Kirps and The Joopita Project [ASBL]
# Copyright (C) 2011-2022 Jos Kirps and Joopita Research ASBL
# Copyright (C) 2006-2011 Jos Kirps and The Joopita Project
# Copyright (C) 2001-2006 Jos Kirps and The WobbleWolf Project
#
# This file, as well as many other parts of the ONO Software Project or
# related elements, are FREE SOFTWARE available under the ARTISTIC LICENSE 2.0.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# For the full license, see /ono/osr/license/LICENSE.txt, or write to
# jos_AT_kirps_DOT_com or contact_AT_joopita_DOT_com.
#
################################################################################
# END OF COPYRIGHT / LICENSE, HERE COMES THE CODE ... #
################################################################################

#: This module is a front end application module wrapper that has been
#: created for the Morzino Project (morzino.com) and that has been released
#: as Open Source software.
#:
#: Note that this is NOT a self-contained application, it is only a wrapper
#: that makes heavy use of the ONO Perl Framework application engine.

use strict;

use ONO::FW::Edu::Apps::ToolBox;

use ONO::FW::Edu::Apps::JS::SkiingScript;

use ONO::IO;

use ONO::FW::Apps::ToolBox;
use ONO::FW::Apps::Dev;
use ONO::FW::Game::Nav;

use ONO::Lib::Image::Canvas;
use ONO::Lib::PDF::Draw;
use ONO::Lib::PDF::ToolBox;

use ONO::FW::Apps::Core;
use ONO::FW::Apps::Core::Graphics;

use ONO::Lib::Parser;
use ONO::FW::Apps::PDF;
use ONO::Lib::UI::Check;
use ONO::Lib::UI::Select;

sub learn {

my (
$self,
$option,
$vars_ref,
$HTTP,
$BASE,
) = @_;

################################################################
# INIT - BEGIN
################################################################

my (
$db,
$community,
$action_url,
$form,
$format,
$canvas,
$pdfkey,
$sec,$min,$hour,
$mday,$mon,$year,
$wday,$yday,$timestamp,
$lang,
$BLK_ref,
$vars_ref,
) = ONO::FW::Apps::Core->init($vars_ref);

my %vars = %$vars_ref;
my %BLK = %$BLK_ref;

my $app = "skiing";

ONO::FW::Apps::Core->now("",$app,$vars{'app_lang'});

my @txt = (
"Skiing",
"distance",
"slope",
"FINISH",
);

if ($vars{'app_lang'} eq "de") {
@txt = (
"Skifahren",
"Distanz",
"Piste",
"ZIEL",
);
}

if ($vars{'app_lang'} eq "lu") {
@txt = (
"Skifueren",
"Distanz",
"Pist",
"ZIEL",
);
}

if ($vars{'app_lang'} eq "fr") {
@txt = (
"Ski",
"distance",
"piste",
"ARRIVEE",
);
}

if (!$vars{'app_input_distance_status'}) {
$vars{'app_input_distance_status'} = 2;
}
if (!$vars{'app_input_slope_status'}) {
$vars{'app_input_slope_status'} = 2;
}

$vars{'app_input_speed'} = 4;
$vars{'app_input_gate_min_width'} = 150;
$vars{'app_input_gate_max_width'} = 200;
$vars{'app_input_gate_probability'} = 4;
$vars{'app_input_tree_probability'} = 1;
$vars{'app_input_rock_probability'} = 0;

if ($vars{'app_input_slope_status'} == 2) {
$vars{'app_input_speed'} = 4.5;
$vars{'app_input_gate_min_width'} = 125;
$vars{'app_input_gate_max_width'} = 175;
$vars{'app_input_gate_probability'} = 6;
$vars{'app_input_tree_probability'} = 2;
$vars{'app_input_rock_probability'} = 0;
}

if ($vars{'app_input_slope_status'} == 3) {
$vars{'app_input_speed'} = 5;
$vars{'app_input_gate_min_width'} = 100;
$vars{'app_input_gate_max_width'} = 175;
$vars{'app_input_gate_probability'} = 8;
$vars{'app_input_tree_probability'} = 4;
$vars{'app_input_rock_probability'} = 1;
}

if ($vars{'app_input_slope_status'} == 4) {
$vars{'app_input_speed'} = 5.5;
$vars{'app_input_gate_min_width'} = 75;
$vars{'app_input_gate_max_width'} = 175;
$vars{'app_input_gate_probability'} = 10;
$vars{'app_input_tree_probability'} = 8;
$vars{'app_input_rock_probability'} = 3;
}

if (ONO::IO->devstation) {
# $vars{'app_input_distance_status'} = 0.1;
}

my $WEB;

my $AppName = "Skiing";

$vars{'app_input_print_options_title_default'} = $AppName;

if (ONO::FW::Apps::Core->running(\%vars,$db) || $vars{'output_game'}) {

# $WEB .= ONO::FW::Apps::Core->blockbackbutton($BASE,$vars_ref);

#############################################################
# ONLINE TRAINING
#############################################################

if ($vars{'output_game'}) {

# if ($vars{'output_web_next_question'}) {
# $vars{'output_web_question_number'}++;
# }
#
# my $question_number = ONO::FW::Apps::Core->question_number($vars{'output_web_question_number'});

$WEB .= qq~<style>
/* Ensure canvas is positioned relatively for absolute div positioning */
#gameCanvas {
position: relative;
border: none;
outline: none;
}
/* Styles for mobile control divs */
.mobile-control {
}
#leftControl {
}
#rightControl {
}
</style>
~;

$WEB .= qq~<script>
function correct_next() {
onojs_block('correct_next_message');
}
</script>
~;

$WEB .= qq~<div class="overhide" style="width:920px;height:480px">~;

$WEB .= ONO::FW::Edu::Apps::JS::SkiingScript->code(
$vars{'app_input_distance_status'}*5000,
$vars{'app_input_speed'},
$vars{'app_input_gate_min_width'},
$vars{'app_input_gate_max_width'},
$vars{'app_input_gate_probability'}/100,
$vars{'app_input_tree_probability'}/100,
$vars{'app_input_rock_probability'}/100,
$txt[3],
);

my %nav;

$nav{"button_l_color"} = "bg_fabric";
$nav{"button_r_color"} = "bg_fabric";

$nav{'button_l_id'} = "left";
$nav{'button_r_id'} = "right";

$nav{'button_l_onclick'} = "ono_button_left();";
$nav{'button_r_onclick'} = "ono_button_right();";

$nav{'button_l_pos'} = "top:400px;left:14px";
$nav{'button_r_pos'} = "top:400px;left:840px";

$WEB .= qq~<div class="abs" style="top:0px">~;
$WEB .= ONO::FW::Game::Nav->nav("main",\%nav,"mlr").ONO::FW::Game::Nav->script("main","lr");
$WEB .= qq~</div>~;

$WEB .= qq~</div>~;

my $RESULT = qq~<table class="default_table auto">
<tr>
<td><input type="submit" name="output_game" value="$BLK{'again'}..." class="button_green button_big mr10"></td>
</tr>
</table>
~;

my $INPUT;
foreach my $key (sort keys %vars) {
if ($key =~ /^(app_input|output)_/) {
$INPUT .= qq~<input type="hidden" name="$key" value="$vars{$key}">~;
}
}

$WEB .= qq~<$form>
$INPUT
<div id="correct_next_message" class="hide">
<div class="abs" style="width:920px;top:400px">
<div class="auto w50">
<div class="box_green">
$RESULT
</div>
</div>
</div>
</div>
</form>
~;

# if ($question_number > $vars{'app_input_number_of_questions'}) {
#
# $WEB = ONO::FW::Apps::Core->question_progress_done_msg($app,$db,$community,$form,$action_url,$vars{'app_input_number_of_questions'},0,$lang,$BLK_ref,$vars_ref,"M");
#
# }

ONO::FW::Apps::Core->varstore($vars{'username'},$vars{'virclass'},$vars{'anonymous'},\%vars);

}

} else {

#############################################################
# EXERCISE SETUP
#############################################################

my %setup;

my $CONF;

my @tabs = ("1:yellow:500 m","2:yellow:1 km","3:yellow:2 km","4:yellow:3 km");
my $CUSTOM1 = ONO::Lib::UI::Select->buttons('app_input_distance',$vars{'app_input_distance_status'},\@tabs,"","B");

my @tabs = ("1:green:$BLK{'green'}","2:blue:$BLK{'blue'}","3:red:$BLK{'red'}","4:dark:$BLK{'black'}");
my $CUSTOM2 = ONO::Lib::UI::Select->buttons('app_input_slope',$vars{'app_input_slope_status'},\@tabs,"","B");



$CONF .= ONO::FW::Apps::ToolBox->conf_input("custom", $BLK_ref,\%vars,"",$txt[1],$CUSTOM1);
$CONF .= ONO::FW::Apps::ToolBox->conf_input("spacer", $BLK_ref,\%vars);
$CONF .= ONO::FW::Apps::ToolBox->conf_input("custom", $BLK_ref,\%vars,"",$txt[2],$CUSTOM2);
$CONF .= ONO::FW::Apps::ToolBox->conf_input("spacer", $BLK_ref,\%vars);

$WEB .= ONO::FW::Apps::Core->conf_box(
$db,
$community,
$app,
$form,
"",
$action_url,
$CONF,
$lang,
$BLK_ref,
\%vars,
"gG",
);

$WEB .= qq~<div class="abs" style="top:20px;left:480px">
<img class="block" src="/images/morzino/apps/skiing.jpg" alt="">
</div>
~;

$WEB .= ONO::FW::Apps::Core->vardump(\%vars);

}

# my ($status,$WEB) = ONO::Lib::Parser->parse($WEB,$vars_ref);

# $WEB .= ONO::FW::Apps::Core->vardump(\%vars);

my @INPUT = (
"worldHeight",
"maxSpeed",
"minGateWidth",
"maxGateWidth",
"gateProbability",
"treeProbability",
"rockProbability",
"finishText",
);

my @ACTION = (
qq~alert_you_won\^correct_next\^~,
);

$WEB .= ONO::FW::Apps::Dev->js_compiler(
"/cgi-bin/local/perl/school/apps/skiing.pl",
"ono/sys/ONO/Ext/Morzino/Apps/JS",
"ONO:Ext:Morzino:Apps:Modules:Skiing",
"ONO:Ext:Morzino:Apps:JS:Skiing",
\@INPUT,
\@ACTION,
);

$WEB = ONO::FW::Edu::Apps::ToolBox->apps_gate($WEB,$vars_ref);

return $WEB;

}

###################################################################
#### THAT'S IT :-D
###################################################################

1;

__END__