Extract background color to continue image
This commit is contained in:
parent
35d07c1aa4
commit
26c282138e
23 changed files with 218 additions and 115 deletions
|
@ -21,12 +21,13 @@ var ExerciceCurrentCoefficient = 1.0
|
|||
|
||||
// Exercice represents a challenge inside a Theme.
|
||||
type Exercice struct {
|
||||
Id int64 `json:"id"`
|
||||
IdTheme *int64 `json:"id_theme"`
|
||||
Language string `json:"lang,omitempty"`
|
||||
Title string `json:"title"`
|
||||
Authors string `json:"authors"`
|
||||
Image string `json:"image"`
|
||||
Id int64 `json:"id"`
|
||||
IdTheme *int64 `json:"id_theme"`
|
||||
Language string `json:"lang,omitempty"`
|
||||
Title string `json:"title"`
|
||||
Authors string `json:"authors"`
|
||||
Image string `json:"image"`
|
||||
BackgroundColor uint32 `json:"background_color,omitempty"`
|
||||
// Disabled indicates if the exercice is available to players now or not
|
||||
Disabled bool `json:"disabled"`
|
||||
// WIP indicates if the exercice is in development or not
|
||||
|
@ -75,7 +76,7 @@ func (e *Exercice) AnalyzeTitle() {
|
|||
func getExercice(table, condition string, args ...interface{}) (*Exercice, error) {
|
||||
var e Exercice
|
||||
var tmpgain float64
|
||||
if err := DBQueryRow("SELECT id_exercice, id_theme, title, authors, image, disabled, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, resolution, seealso, finished FROM "+table+" "+condition, args...).Scan(&e.Id, &e.IdTheme, &e.Title, &e.Authors, &e.Image, &e.Disabled, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &tmpgain, &e.Coefficient, &e.VideoURI, &e.Resolution, &e.SeeAlso, &e.Finished); err != nil {
|
||||
if err := DBQueryRow("SELECT id_exercice, id_theme, title, authors, image, background_color, disabled, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, resolution, seealso, finished FROM "+table+" "+condition, args...).Scan(&e.Id, &e.IdTheme, &e.Title, &e.Authors, &e.Image, &e.BackgroundColor, &e.Disabled, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &tmpgain, &e.Coefficient, &e.VideoURI, &e.Resolution, &e.SeeAlso, &e.Finished); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
e.Gain = int64(math.Trunc(tmpgain))
|
||||
|
@ -142,7 +143,7 @@ func GetDiscountedExercice(id int64) (*Exercice, error) {
|
|||
|
||||
// getExercices returns the list of all challenges present in the database.
|
||||
func getExercices(table string) ([]*Exercice, error) {
|
||||
if rows, err := DBQuery("SELECT id_exercice, id_theme, title, authors, image, disabled, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, resolution, seealso, finished FROM " + table + " ORDER BY path ASC"); err != nil {
|
||||
if rows, err := DBQuery("SELECT id_exercice, id_theme, title, authors, image, background_color, disabled, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, resolution, seealso, finished FROM " + table + " ORDER BY path ASC"); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
@ -151,7 +152,7 @@ func getExercices(table string) ([]*Exercice, error) {
|
|||
for rows.Next() {
|
||||
e := &Exercice{}
|
||||
var tmpgain float64
|
||||
if err := rows.Scan(&e.Id, &e.IdTheme, &e.Title, &e.Authors, &e.Image, &e.Disabled, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &tmpgain, &e.Coefficient, &e.VideoURI, &e.Resolution, &e.SeeAlso, &e.Finished); err != nil {
|
||||
if err := rows.Scan(&e.Id, &e.IdTheme, &e.Title, &e.Authors, &e.Image, &e.BackgroundColor, &e.Disabled, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &tmpgain, &e.Coefficient, &e.VideoURI, &e.Resolution, &e.SeeAlso, &e.Finished); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
e.Gain = int64(math.Trunc(tmpgain))
|
||||
|
@ -180,11 +181,11 @@ func GetDiscountedExercices() ([]*Exercice, error) {
|
|||
|
||||
// GetExercices returns the list of all challenges in the Theme.
|
||||
func (t *Theme) GetExercices() ([]*Exercice, error) {
|
||||
query := "SELECT id_exercice, id_theme, title, authors, image, disabled, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, resolution, seealso, finished FROM exercices WHERE id_theme IS NULL ORDER BY path ASC"
|
||||
query := "SELECT id_exercice, id_theme, title, authors, image, background_color, disabled, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, resolution, seealso, finished FROM exercices WHERE id_theme IS NULL ORDER BY path ASC"
|
||||
args := []interface{}{}
|
||||
|
||||
if t.GetId() != nil {
|
||||
query = "SELECT id_exercice, id_theme, title, authors, image, disabled, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, resolution, seealso, finished FROM exercices WHERE id_theme = ? ORDER BY path ASC"
|
||||
query = "SELECT id_exercice, id_theme, title, authors, image, background_color, disabled, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, resolution, seealso, finished FROM exercices WHERE id_theme = ? ORDER BY path ASC"
|
||||
args = append(args, t.GetId())
|
||||
}
|
||||
|
||||
|
@ -196,7 +197,7 @@ func (t *Theme) GetExercices() ([]*Exercice, error) {
|
|||
exos := []*Exercice{}
|
||||
for rows.Next() {
|
||||
e := &Exercice{}
|
||||
if err := rows.Scan(&e.Id, &e.IdTheme, &e.Title, &e.Authors, &e.Image, &e.Disabled, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Resolution, &e.SeeAlso, &e.Finished); err != nil {
|
||||
if err := rows.Scan(&e.Id, &e.IdTheme, &e.Title, &e.Authors, &e.Image, &e.BackgroundColor, &e.Disabled, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Resolution, &e.SeeAlso, &e.Finished); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
e.AnalyzeTitle()
|
||||
|
@ -259,7 +260,7 @@ func (t *Theme) addExercice(e *Exercice) (err error) {
|
|||
if e.WIP {
|
||||
wip = "%"
|
||||
}
|
||||
if res, err := DBExec("INSERT INTO exercices (id_theme, title, authors, image, disabled, url_id, path, statement, overview, finished, headline, issue, depend, gain, video_uri, resolution, seealso, issue_kind, coefficient_cur) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "+ik+", "+cc+")", t.GetId(), wip+e.Title, e.Authors, e.Image, e.Disabled, e.URLId, e.Path, e.Statement, e.Overview, e.Finished, e.Headline, e.Issue, e.Depend, e.Gain, e.VideoURI, e.Resolution, e.SeeAlso); err != nil {
|
||||
if res, err := DBExec("INSERT INTO exercices (id_theme, title, authors, image, background_color, disabled, url_id, path, statement, overview, finished, headline, issue, depend, gain, video_uri, resolution, seealso, issue_kind, coefficient_cur) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "+ik+", "+cc+")", t.GetId(), wip+e.Title, e.Authors, e.Image, e.BackgroundColor, e.Disabled, e.URLId, e.Path, e.Statement, e.Overview, e.Finished, e.Headline, e.Issue, e.Depend, e.Gain, e.VideoURI, e.Resolution, e.SeeAlso); err != nil {
|
||||
return err
|
||||
} else if eid, err := res.LastInsertId(); err != nil {
|
||||
return err
|
||||
|
@ -271,29 +272,30 @@ func (t *Theme) addExercice(e *Exercice) (err error) {
|
|||
}
|
||||
|
||||
// AddExercice creates and fills a new struct Exercice and registers it into the database.
|
||||
func (t *Theme) AddExercice(title string, authors string, image string, wip bool, urlId string, path string, statement string, overview string, headline string, depend *Exercice, gain int64, videoURI string, resolution string, seealso string, finished string) (e *Exercice, err error) {
|
||||
func (t *Theme) AddExercice(title string, authors string, image string, backgroundcolor uint32, wip bool, urlId string, path string, statement string, overview string, headline string, depend *Exercice, gain int64, videoURI string, resolution string, seealso string, finished string) (e *Exercice, err error) {
|
||||
var dpd *int64 = nil
|
||||
if depend != nil {
|
||||
dpd = &depend.Id
|
||||
}
|
||||
|
||||
e = &Exercice{
|
||||
Title: title,
|
||||
Authors: authors,
|
||||
Image: image,
|
||||
Disabled: false,
|
||||
WIP: wip,
|
||||
URLId: urlId,
|
||||
Path: path,
|
||||
Statement: statement,
|
||||
Overview: overview,
|
||||
Headline: headline,
|
||||
Depend: dpd,
|
||||
Finished: finished,
|
||||
Gain: gain,
|
||||
VideoURI: videoURI,
|
||||
Resolution: resolution,
|
||||
SeeAlso: seealso,
|
||||
Title: title,
|
||||
Authors: authors,
|
||||
Image: image,
|
||||
BackgroundColor: backgroundcolor,
|
||||
Disabled: false,
|
||||
WIP: wip,
|
||||
URLId: urlId,
|
||||
Path: path,
|
||||
Statement: statement,
|
||||
Overview: overview,
|
||||
Headline: headline,
|
||||
Depend: dpd,
|
||||
Finished: finished,
|
||||
Gain: gain,
|
||||
VideoURI: videoURI,
|
||||
Resolution: resolution,
|
||||
SeeAlso: seealso,
|
||||
}
|
||||
|
||||
err = t.addExercice(e)
|
||||
|
@ -308,7 +310,7 @@ func (e *Exercice) Update() (int64, error) {
|
|||
wip = "%"
|
||||
}
|
||||
|
||||
if res, err := DBExec("UPDATE exercices SET title = ?, authors = ?, image = ?, disabled = ?, url_id = ?, path = ?, statement = ?, overview = ?, headline = ?, issue = ?, issue_kind = ?, depend = ?, gain = ?, coefficient_cur = ?, video_uri = ?, resolution = ?, seealso = ?, finished = ? WHERE id_exercice = ?", wip+e.Title, e.Authors, e.Image, e.Disabled, e.URLId, e.Path, e.Statement, e.Overview, e.Headline, e.Issue, e.IssueKind, e.Depend, e.Gain, e.Coefficient, e.VideoURI, e.Resolution, e.SeeAlso, e.Finished, e.Id); err != nil {
|
||||
if res, err := DBExec("UPDATE exercices SET title = ?, authors = ?, image = ?, background_color = ?, disabled = ?, url_id = ?, path = ?, statement = ?, overview = ?, headline = ?, issue = ?, issue_kind = ?, depend = ?, gain = ?, coefficient_cur = ?, video_uri = ?, resolution = ?, seealso = ?, finished = ? WHERE id_exercice = ?", wip+e.Title, e.Authors, e.Image, e.BackgroundColor, e.Disabled, e.URLId, e.Path, e.Statement, e.Overview, e.Headline, e.Issue, e.IssueKind, e.Depend, e.Gain, e.Coefficient, e.VideoURI, e.Resolution, e.SeeAlso, e.Finished, e.Id); err != nil {
|
||||
return 0, err
|
||||
} else if nb, err := res.RowsAffected(); err != nil {
|
||||
return 0, err
|
||||
|
|
Reference in a new issue