diff --git a/CHANGES.md b/CHANGES.md index 2bc395b..2335f98 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,7 +1,9 @@ Changes in version 2017-06-19 (20170619) -- Fix Moodle 3.4 compatibility problems -- Fix codeprechecks problems -- Stable version +- Change field name game_snakes_database.cols => usedcols +- Change field name game_snakes_database.rows => usedrows + +Changes in version 2017-06-10 (20170610) +- Fix phpdocs problems Changes in version 2017-06-09 (20170609) - Fix Moodle 3.4 compatibility problems diff --git a/db/install.xml b/db/install.xml index b64bd27..a17e49e 100755 --- a/db/install.xml +++ b/db/install.xml @@ -287,8 +287,8 @@ - - + + diff --git a/db/upgrade.php b/db/upgrade.php index 12dd2d1..9b6bf60 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -1556,6 +1556,23 @@ function xmldb_game_upgrade($oldversion) { $dbman->change_field_type($table, $field); } + if ($oldversion < ($ver = 2017061604)) { + $table = new xmldb_table('game_cross'); + $field = new xmldb_field('usedrows', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id'); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + $field = new xmldb_field('rows', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id'); + if ($dbman->field_exists($table, $field)) { + $sql = "UPDATE {$CFG->prefix}game_cross SET usedrows=rows"; + $DB->execute( $sql); + $dbman->drop_field($table, $field); + } else { + $dbman->add_field($table, $field); + } + } + if ($oldversion < ($ver = 2017061604)) { $table = new xmldb_table('game_cross'); $field = new xmldb_field('usedcols', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id'); @@ -1573,8 +1590,8 @@ function xmldb_game_upgrade($oldversion) { } } - if ($oldversion < ($ver = 2017061604)) { - $table = new xmldb_table('game_cross'); + if ($oldversion < ($ver = 2017061901)) { + $table = new xmldb_table('game_snakes_database'); $field = new xmldb_field('usedrows', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); @@ -1582,7 +1599,7 @@ function xmldb_game_upgrade($oldversion) { $field = new xmldb_field('rows', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id'); if ($dbman->field_exists($table, $field)) { - $sql = "UPDATE {$CFG->prefix}game_cross SET usedrows=rows"; + $sql = "UPDATE {$CFG->prefix}game_snakes_database SET usedrows=rows"; $DB->execute( $sql); $dbman->drop_field($table, $field); } else { @@ -1590,5 +1607,22 @@ function xmldb_game_upgrade($oldversion) { } } + if ($oldversion < ($ver = 2017061901)) { + $table = new xmldb_table('game_snakes_database'); + $field = new xmldb_field('usedcols', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id'); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + $field = new xmldb_field('cols', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id'); + if ($dbman->field_exists($table, $field)) { + $sql = "UPDATE {$CFG->prefix}game_snakes_database SET usedcols=cols"; + $DB->execute( $sql); + $dbman->drop_field($table, $field); + } else { + $dbman->add_field($table, $field); + } + } + return true; } diff --git a/mod_form.php b/mod_form.php index 1e43bb6..bdbacf2 100644 --- a/mod_form.php +++ b/mod_form.php @@ -508,8 +508,8 @@ class mod_game_mod_form extends moodleform_mod { if ($board != 0) { $rec = $DB->get_record( 'game_snakes_database', array( 'id' => $board)); $defaultvalues->snakes_data = $rec->data; - $defaultvalues->snakes_cols = $rec->cols; - $defaultvalues->snakes_rows = $rec->rows; + $defaultvalues->snakes_cols = $rec->usedcols; + $defaultvalues->snakes_rows = $rec->usedrows; $defaultvalues->snakes_headerx = $rec->headerx; $defaultvalues->snakes_headery = $rec->headery; $defaultvalues->snakes_footerx = $rec->footerx; diff --git a/snakes/play.php b/snakes/play.php index 911d418..4dd7efe 100644 --- a/snakes/play.php +++ b/snakes/play.php @@ -74,7 +74,7 @@ function game_snakes_play( $id, $game, $attempt, $snakes, $context) { $board = game_snakes_get_board( $game); $showboard = false; - if ($snakes->position > $board->cols * $board->rows && $snakes->queryid <> 0) { + if ($snakes->position > $board->usedcols * $board->usedrows && $snakes->queryid <> 0) { $finish = true; if (! $cm = $DB->get_record('course_modules', array( 'id' => $id))) { @@ -180,11 +180,11 @@ top:height / 3));?>px; "> * @param stdClass $board */ function game_snakes_computeplayerposition( $snakes, $board) { - $x = ($snakes->position - 1) % $board->cols; - $y = floor( ($snakes->position - 1) / $board->cols); + $x = ($snakes->position - 1) % $board->usedcols; + $y = floor( ($snakes->position - 1) / $board->usedcols); - $cellwidth = ($board->width - $board->headerx - $board->footerx) / $board->cols; - $cellheight = ($board->height - $board->headery - $board->footery) / $board->rows; + $cellwidth = ($board->width - $board->headerx - $board->footerx) / $board->usedcols; + $cellheight = ($board->height - $board->headery - $board->footery) / $board->usedrows; $pos = new stdClass(); $pos->width = 22; @@ -196,7 +196,7 @@ function game_snakes_computeplayerposition( $snakes, $board) { switch( $board->direction) { case 1: if (($y % 2) == 1) { - $x = $board->cols - $x - 1; + $x = $board->usedcols - $x - 1; } $pos->x = $board->headerx + $x * $cellwidth + ($cellwidth - $pos->width) / 2 + $pos->ofsx; $pos->y = $board->footery + $y * $cellheight + ($cellheight - $pos->height) / 2 + $pos->ofsy; @@ -488,8 +488,8 @@ function game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query, } $board = $DB->get_record_select( 'game_snakes_database', "id=$snakes->snakesdatabaseid"); - $gradeattempt = $snakes->position / ($board->cols * $board->rows); - $finished = ( $snakes->position > $board->cols * $board->rows ? 1 : 0); + $gradeattempt = $snakes->position / ($board->usedcols * $board->usedrows); + $finished = ( $snakes->position > $board->usedcols * $board->usedrows ? 1 : 0); game_updateattempts( $game, $attempt, $gradeattempt, $finished); diff --git a/version.php b/version.php index a0e1d80..6d0ce40 100644 --- a/version.php +++ b/version.php @@ -39,7 +39,7 @@ $plugin->version = 2017061901; // The current module version (Date: YYYYMMDDX $plugin->requires = 2010112400; // Requires Moodle 2.0. $plugin->cron = 0; // Period for cron to check this module (secs). $plugin->release = '2017-06-19'; -$plugin->maturity = MATURITY_STABLE; +$plugin->maturity = MATURITY_BETA; if ($useplugin != 2) { $module = $plugin;