Dogeku 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +39 -0
- data/app/Historique/Action.rb +29 -0
- data/app/Historique/ChangerCase.rb +44 -0
- data/app/Historique/HistoriqueAction.rb +114 -0
- data/app/components/CaseDessin.rb +325 -0
- data/app/components/GrilleDessin.rb +235 -0
- data/app/components/Header.rb +194 -0
- data/app/config/app.yml +0 -0
- data/app/config/database.yml +2 -0
- data/app/controller/ApprentissageControleur.rb +75 -0
- data/app/controller/ChargerControleur.rb +41 -0
- data/app/controller/JeuLibreControleur.rb +244 -0
- data/app/controller/MenuControleur.rb +57 -0
- data/app/controller/NiveauControleur.rb +54 -0
- data/app/controller/NouvellePartieControleur.rb +34 -0
- data/app/controller/PrincipaleControleur.rb +30 -0
- data/app/controller/PseudoControleur.rb +95 -0
- data/app/controller/ReglagesControleur.rb +86 -0
- data/app/controller/ReglesControleur.rb +34 -0
- data/app/controller/ScoresControleur.rb +42 -0
- data/app/controller/StatistiquesControleur.rb +64 -0
- data/app/core/Conf.rb +26 -0
- data/app/core/Controller.rb +180 -0
- data/app/core/Core.rb +186 -0
- data/app/core/Model.rb +159 -0
- data/app/core/View.rb +56 -0
- data/app/db/main.sqlite3 +0 -0
- data/app/model/Configuration.rb +180 -0
- data/app/model/Grille.rb +180 -0
- data/app/model/Jeu.rb +74 -0
- data/app/model/Score.rb +100 -0
- data/app/model/Utilisateur.rb +113 -0
- data/app/utils/DSubset.rb +98 -0
- data/app/utils/Generateur.rb +171 -0
- data/app/utils/HPTriple.rb +75 -0
- data/app/utils/Peche.rb +46 -0
- data/app/utils/SCandidate.rb +86 -0
- data/app/utils/SCell.rb +73 -0
- data/app/utils/Technique.rb +202 -0
- data/app/utils/TechniqueUsine.rb +25 -0
- data/app/utils/XWing.rb +203 -0
- data/app/view/Fenetre.rb +424 -0
- data/app/view/FenetreApprentissage.rb +272 -0
- data/app/view/FenetreCharger.rb +31 -0
- data/app/view/FenetreJeuLibre.rb +468 -0
- data/app/view/FenetreMenu.rb +198 -0
- data/app/view/FenetreNiveau.rb +105 -0
- data/app/view/FenetreNouvellePartie.rb +92 -0
- data/app/view/FenetrePrincipale.rb +45 -0
- data/app/view/FenetrePseudo.rb +115 -0
- data/app/view/FenetreReglages.rb +209 -0
- data/app/view/FenetreRegles.rb +111 -0
- data/app/view/FenetreScores.rb +120 -0
- data/app/view/FenetreStatistiques.rb +134 -0
- data/assets/css/style.css +69 -0
- data/assets/img/eraser.png +0 -0
- data/assets/img/fond.jpg +0 -0
- data/assets/img/iconApp.png +0 -0
- data/assets/img/logoS.jpeg +0 -0
- data/assets/img/sudokuIntro.jpg +0 -0
- data/assets/img/user.png +0 -0
- data/bin/dogeku +19 -0
- data/doc/Action.html +309 -0
- data/doc/ApprentissageControleur.html +568 -0
- data/doc/CaseDessin.html +2405 -0
- data/doc/ChangerCase.html +405 -0
- data/doc/ChargerControleur.html +342 -0
- data/doc/Conf.html +378 -0
- data/doc/Configuration.html +1115 -0
- data/doc/Controller.html +1008 -0
- data/doc/Core.html +1191 -0
- data/doc/DSubset.html +647 -0
- data/doc/Fenetre.html +2631 -0
- data/doc/FenetreApprentissage.html +1175 -0
- data/doc/FenetreCharger.html +343 -0
- data/doc/FenetreJeuLibre.html +1859 -0
- data/doc/FenetreMenu.html +900 -0
- data/doc/FenetreNiveau.html +626 -0
- data/doc/FenetreNouvellePartie.html +602 -0
- data/doc/FenetrePrincipale.html +371 -0
- data/doc/FenetrePseudo.html +695 -0
- data/doc/FenetreReglages.html +946 -0
- data/doc/FenetreRegles.html +636 -0
- data/doc/FenetreScores.html +650 -0
- data/doc/FenetreStatistiques.html +672 -0
- data/doc/Generateur.html +1015 -0
- data/doc/Grille.html +1348 -0
- data/doc/GrilleDessin.html +1281 -0
- data/doc/HPTriple.html +593 -0
- data/doc/Header.html +1253 -0
- data/doc/HistoriqueAction.html +792 -0
- data/doc/Jeu.html +923 -0
- data/doc/JeuLibreControleur.html +1445 -0
- data/doc/MenuControleur.html +522 -0
- data/doc/Model.html +996 -0
- data/doc/NiveauControleur.html +451 -0
- data/doc/NouvellePartieControleur.html +330 -0
- data/doc/Peche.html +396 -0
- data/doc/PrincipaleControleur.html +320 -0
- data/doc/PseudoControleur.html +695 -0
- data/doc/ReglagesControleur.html +747 -0
- data/doc/ReglesControleur.html +330 -0
- data/doc/SCandidate.html +617 -0
- data/doc/SCell.html +587 -0
- data/doc/Score.html +926 -0
- data/doc/ScoresControleur.html +346 -0
- data/doc/StatistiquesControleur.html +390 -0
- data/doc/Technique.html +543 -0
- data/doc/TechniqueUsine.html +252 -0
- data/doc/Utilisateur.html +806 -0
- data/doc/View.html +844 -0
- data/doc/XWing.html +1031 -0
- data/doc/_index.html +478 -0
- data/doc/class_list.html +51 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +58 -0
- data/doc/css/style.css +492 -0
- data/doc/file.README.html +141 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +17 -0
- data/doc/index.html +141 -0
- data/doc/js/app.js +243 -0
- data/doc/js/full_list.js +216 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +2523 -0
- data/doc/top-level-namespace.html +112 -0
- data/test/Generateur/grilleCorrecte.rb +198 -0
- data/test/Model/scoreCorrecte.rb +55 -0
- data/test/Model/utilisateurCorrecte.rb +68 -0
- data/test/test_helper.rb +2 -0
- data/test/unitTest.rb +72 -0
- metadata +187 -0
data/app/core/Core.rb
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# => Author:: Valentin, DanAurea
|
|
2
|
+
# => Version:: 0.1
|
|
3
|
+
# => Copyright:: © 2016
|
|
4
|
+
# => License:: Distributes under the same terms as Ruby
|
|
5
|
+
|
|
6
|
+
##
|
|
7
|
+
## Module permettant de gérer les liens entre les vues et les contrôleurs suivant des modèles particuliers
|
|
8
|
+
##
|
|
9
|
+
|
|
10
|
+
module Core
|
|
11
|
+
|
|
12
|
+
## Définit le répertoire de la racine
|
|
13
|
+
ROOT = File.expand_path(File.dirname(File.dirname(__FILE__))) + "/"
|
|
14
|
+
## Définit la racine du projet
|
|
15
|
+
ROOTPROJECT = File.dirname(ROOT) + "/"
|
|
16
|
+
## Définit le contrôleur
|
|
17
|
+
CONTROLLER = "Controleur"
|
|
18
|
+
## Définit la vue
|
|
19
|
+
VIEW = "Fenetre"
|
|
20
|
+
## Définit le mode debug
|
|
21
|
+
DEBUG = false
|
|
22
|
+
## Définit le log de la base de données
|
|
23
|
+
DEFAULT_DATABASE_LOG = "log/main.log"
|
|
24
|
+
## Définit la base de données
|
|
25
|
+
DEFAULT_ADAPTER = "sqlite3"
|
|
26
|
+
## Définit le répertoire de la base de données
|
|
27
|
+
DEFAULT_DATABASE_DIR = "db/"
|
|
28
|
+
## Définit le fichier où contiennent les éléments de la base de données
|
|
29
|
+
DEFAULT_DATABASE_NAME = "main.sqlite3"
|
|
30
|
+
|
|
31
|
+
@previousWindow = Array.new()
|
|
32
|
+
@args = nil
|
|
33
|
+
|
|
34
|
+
##
|
|
35
|
+
## Load a controller and render its view
|
|
36
|
+
##
|
|
37
|
+
## @param name The name
|
|
38
|
+
##
|
|
39
|
+
## @return Module itself
|
|
40
|
+
##
|
|
41
|
+
def Core.load(name, **args)
|
|
42
|
+
|
|
43
|
+
controller = loadController(name)
|
|
44
|
+
|
|
45
|
+
controller.render(name, args)
|
|
46
|
+
|
|
47
|
+
return self
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
##
|
|
51
|
+
## Change window
|
|
52
|
+
##
|
|
53
|
+
## @param name The name
|
|
54
|
+
##
|
|
55
|
+
## @return Module itself
|
|
56
|
+
##
|
|
57
|
+
def Core.changeTo(name, **args)
|
|
58
|
+
|
|
59
|
+
## Prevent some issue with back option
|
|
60
|
+
## no more loop possible when caller is
|
|
61
|
+
## identical as destination.
|
|
62
|
+
## Act like an Ariane's thread we
|
|
63
|
+
## can now back on all previous windows.
|
|
64
|
+
if @previousWindow.slice(-1) != name
|
|
65
|
+
## Save caller window
|
|
66
|
+
@previousWindow << name
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
@args = args
|
|
70
|
+
|
|
71
|
+
## Create a new empty window
|
|
72
|
+
Fenetre::fenetrePrecedente = Fenetre::fenetre.children.clone()
|
|
73
|
+
Fenetre::viderFenetre
|
|
74
|
+
|
|
75
|
+
load(name, args)
|
|
76
|
+
|
|
77
|
+
return self
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
##
|
|
82
|
+
## Back to previous window
|
|
83
|
+
##
|
|
84
|
+
## @return Module itself
|
|
85
|
+
##
|
|
86
|
+
def Core.back()
|
|
87
|
+
if @previousWindow.length > 1
|
|
88
|
+
## Slice current page
|
|
89
|
+
@previousWindow.slice!(-1)
|
|
90
|
+
## Go back to previous window
|
|
91
|
+
self.changeTo(@previousWindow.slice!(-1), @args)
|
|
92
|
+
else
|
|
93
|
+
puts "Empty stack, you can't back to a non stacked window."
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
return self
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
##
|
|
100
|
+
## Give model path for model called.
|
|
101
|
+
##
|
|
102
|
+
## @param name The name
|
|
103
|
+
##
|
|
104
|
+
## @return Model path
|
|
105
|
+
##
|
|
106
|
+
def Core.modelPath(name)
|
|
107
|
+
return ROOT + "model/" + name + ".rb"
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
##
|
|
111
|
+
## Give view path for view called.
|
|
112
|
+
##
|
|
113
|
+
## @param name The name
|
|
114
|
+
##
|
|
115
|
+
## @return View path
|
|
116
|
+
##
|
|
117
|
+
def Core.viewPath(name)
|
|
118
|
+
return ROOT + "view/" + name + ".rb"
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
##
|
|
122
|
+
## Give controller path for controller called.
|
|
123
|
+
##
|
|
124
|
+
## @param name The name
|
|
125
|
+
##
|
|
126
|
+
## @return Controller path
|
|
127
|
+
##
|
|
128
|
+
def Core.controllerPath(name)
|
|
129
|
+
return ROOT + "controller/" + name + ".rb"
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
##
|
|
134
|
+
## Force children overriding constructor inherited from parent class to run parent constructor.
|
|
135
|
+
##
|
|
136
|
+
## @return Itself
|
|
137
|
+
##
|
|
138
|
+
def Core.forceParentInit(o)
|
|
139
|
+
|
|
140
|
+
## Force to call parent method if children override it
|
|
141
|
+
if o.method(:initialize).owner != o.class.name
|
|
142
|
+
o.method(:initialize).super_method.call
|
|
143
|
+
o.method(:initialize).call
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
##
|
|
149
|
+
## Loads a controller.
|
|
150
|
+
##
|
|
151
|
+
## @param name The controller to load
|
|
152
|
+
##
|
|
153
|
+
## @return Controller instance
|
|
154
|
+
##
|
|
155
|
+
def Core.loadController(name)
|
|
156
|
+
|
|
157
|
+
name = name + CONTROLLER
|
|
158
|
+
|
|
159
|
+
## Define file path for controller
|
|
160
|
+
filePath = self.controllerPath(name)
|
|
161
|
+
|
|
162
|
+
begin
|
|
163
|
+
require filePath
|
|
164
|
+
rescue LoadError
|
|
165
|
+
|
|
166
|
+
if DEBUG
|
|
167
|
+
puts "Controller: " + name + " not found in " + ROOT + "controller"
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
exit(1)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
## Will retrieve class constant name for dynamic instanciation
|
|
174
|
+
controllerName = Object.const_get(name)
|
|
175
|
+
|
|
176
|
+
controller = controllerName.new()
|
|
177
|
+
|
|
178
|
+
return controller
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
## Define a class from module itself for declaring private methods
|
|
182
|
+
class << self
|
|
183
|
+
private :loadController, :load
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
end
|
data/app/core/Model.rb
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
require 'sqlite3'
|
|
2
|
+
require 'singleton'
|
|
3
|
+
require_relative 'Conf.rb'
|
|
4
|
+
|
|
5
|
+
# => Author:: DanAurea
|
|
6
|
+
# => Version:: 0.1
|
|
7
|
+
# => Copyright:: © 2016
|
|
8
|
+
# => License:: Distributes under the same terms as Ruby
|
|
9
|
+
|
|
10
|
+
##
|
|
11
|
+
## Classe permettant de gérer la base de données sqlite3
|
|
12
|
+
##
|
|
13
|
+
class Model
|
|
14
|
+
include Singleton
|
|
15
|
+
|
|
16
|
+
attr_accessor :db
|
|
17
|
+
|
|
18
|
+
##
|
|
19
|
+
## Initialisation
|
|
20
|
+
##
|
|
21
|
+
def initialize
|
|
22
|
+
## Retrieving configuration from yaml files
|
|
23
|
+
@conf = Conf.instance()
|
|
24
|
+
|
|
25
|
+
@app = @conf.app
|
|
26
|
+
@dbConf = @conf.db
|
|
27
|
+
@@db = nil
|
|
28
|
+
|
|
29
|
+
dbPath = Core::ROOT + Core::DEFAULT_DATABASE_DIR
|
|
30
|
+
|
|
31
|
+
database = dbPath + @dbConf["development"]["database"]
|
|
32
|
+
|
|
33
|
+
self.mkDatabaseDir(dbPath)
|
|
34
|
+
self.connection(database)
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
##
|
|
39
|
+
## Create a new database directory
|
|
40
|
+
##
|
|
41
|
+
## @param dbPath The database path
|
|
42
|
+
##
|
|
43
|
+
## @return Itself
|
|
44
|
+
##
|
|
45
|
+
def mkDatabaseDir(dbPath)
|
|
46
|
+
## Create a new database directory if not existing
|
|
47
|
+
if !Dir.exist?(dbPath)
|
|
48
|
+
if Core::DEBUG
|
|
49
|
+
puts "Database directory not found, it will be created."
|
|
50
|
+
end
|
|
51
|
+
Dir.mkdir(dbPath)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
return self
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
##
|
|
59
|
+
## Connect to a database
|
|
60
|
+
##
|
|
61
|
+
## @param database The database
|
|
62
|
+
##
|
|
63
|
+
## @return Itself
|
|
64
|
+
##
|
|
65
|
+
def connection(database)
|
|
66
|
+
## Create a SQLite database
|
|
67
|
+
if !File.exist?(database)
|
|
68
|
+
if Core::DEBUG
|
|
69
|
+
puts "SQLite3 database not found, it will be created."
|
|
70
|
+
end
|
|
71
|
+
begin
|
|
72
|
+
SQLite3::Database.new(database)
|
|
73
|
+
rescue SQLite3::Exception => e
|
|
74
|
+
puts "SQLite3 couldn't create a new database."
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
## Connect to created dtabase
|
|
79
|
+
@@db = SQLite3::Database.open(database)
|
|
80
|
+
|
|
81
|
+
return self
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
##
|
|
85
|
+
## Invoke methods when inherited
|
|
86
|
+
##
|
|
87
|
+
## @param subclass The subclass
|
|
88
|
+
##
|
|
89
|
+
## @return Itself
|
|
90
|
+
##
|
|
91
|
+
def self.inherited(subclass)
|
|
92
|
+
self.instance()
|
|
93
|
+
super
|
|
94
|
+
|
|
95
|
+
return self
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
##
|
|
99
|
+
## Insert datas in database
|
|
100
|
+
##
|
|
101
|
+
## @param options Hash with columns and values
|
|
102
|
+
##
|
|
103
|
+
## @return Itself
|
|
104
|
+
##
|
|
105
|
+
def insert(**options)
|
|
106
|
+
colsName = Array.new
|
|
107
|
+
values = Array.new
|
|
108
|
+
bonds = Array.new
|
|
109
|
+
|
|
110
|
+
## Parse options to get columns and values
|
|
111
|
+
options.each do |index, value|
|
|
112
|
+
colsName << index
|
|
113
|
+
values << value
|
|
114
|
+
bonds << "?"
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
colsName = colsName.join(",")
|
|
118
|
+
bonds = bonds.join(",")
|
|
119
|
+
|
|
120
|
+
if Core::DEBUG
|
|
121
|
+
puts "Request: INSERT INTO " + self.class.to_s.downcase + " (#{colsName}) VALUES (#{bonds});"
|
|
122
|
+
|
|
123
|
+
print "Values was: "
|
|
124
|
+
options.each do |index, value|
|
|
125
|
+
print "#{index} => #{value} | "
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
puts
|
|
129
|
+
puts
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
@@db.execute "INSERT INTO " + self.class.to_s.downcase + " (#{colsName})
|
|
133
|
+
VALUES (#{bonds});", values
|
|
134
|
+
|
|
135
|
+
return self
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
##
|
|
139
|
+
## Convert an array reques to a hash with columns => values
|
|
140
|
+
##
|
|
141
|
+
## @param req The request
|
|
142
|
+
##
|
|
143
|
+
## @return Request hashed
|
|
144
|
+
##
|
|
145
|
+
def to_h(req)
|
|
146
|
+
response = Array.new()
|
|
147
|
+
|
|
148
|
+
## Transforme la réponse en hash
|
|
149
|
+
(1...req.length).each do |row|
|
|
150
|
+
response[row-1] = Hash.new()
|
|
151
|
+
(0...req[0].length).each do |col|
|
|
152
|
+
response[row-1][req[0][col]] = req[row][col]
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
return response
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
end
|
data/app/core/View.rb
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# => Author:: DanAurea
|
|
2
|
+
# => Version:: 0.1
|
|
3
|
+
# => Copyright:: © 2016
|
|
4
|
+
# => License:: Distributes under the same terms as Ruby
|
|
5
|
+
|
|
6
|
+
##
|
|
7
|
+
## =Visualization of the data that model contains.
|
|
8
|
+
##
|
|
9
|
+
class View
|
|
10
|
+
include Fenetre
|
|
11
|
+
|
|
12
|
+
attr_accessor :headerBar, :window, :controller
|
|
13
|
+
attr_writer :content
|
|
14
|
+
|
|
15
|
+
def initialize()
|
|
16
|
+
@content = Hash.new()
|
|
17
|
+
@controller = nil
|
|
18
|
+
@window = Fenetre::fenetre
|
|
19
|
+
@headerBar = Fenetre::enteteFenetre
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
##
|
|
23
|
+
## Invoke methods when inherited
|
|
24
|
+
##
|
|
25
|
+
## @param subclass The subclass
|
|
26
|
+
##
|
|
27
|
+
## @return Itself
|
|
28
|
+
##
|
|
29
|
+
def self.inherited(subclass)
|
|
30
|
+
self.new()
|
|
31
|
+
super
|
|
32
|
+
|
|
33
|
+
return self
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
##
|
|
37
|
+
## Create instance variables from @content provided by controller.
|
|
38
|
+
##
|
|
39
|
+
## @return Itself
|
|
40
|
+
def setInstanceVars ()
|
|
41
|
+
@content.each { |name, value| instance_variable_set("@" + name, value) }
|
|
42
|
+
|
|
43
|
+
return self
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
##
|
|
48
|
+
## Invoke all methods from view
|
|
49
|
+
##
|
|
50
|
+
def run()
|
|
51
|
+
if Core::DEBUG
|
|
52
|
+
raise "View #{self.class.name} can't be build because run method is not redefined."
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
data/app/db/main.sqlite3
ADDED
|
Binary file
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
|
|
2
|
+
# Author:: DanAurea
|
|
3
|
+
# Version:: 0.1
|
|
4
|
+
# Copyright:: © 2016
|
|
5
|
+
# License:: Distributes under the same terms as Ruby
|
|
6
|
+
#
|
|
7
|
+
|
|
8
|
+
##
|
|
9
|
+
## Déclaration de la table contenant les paramètres
|
|
10
|
+
## Modèle de configuration
|
|
11
|
+
##
|
|
12
|
+
class Configuration < Model
|
|
13
|
+
|
|
14
|
+
#Définit la couleur de la case de base
|
|
15
|
+
CL_CASE_BASE = "65535, 65535, 65535"
|
|
16
|
+
#Définit la couleur de la case fixe
|
|
17
|
+
CL_CASE_FIXE = "55000, 55000, 55000"
|
|
18
|
+
#Définit la couleur de la case sélectionnée
|
|
19
|
+
CL_CASE_SELECTIONNE = "64764, 59881, 20303"
|
|
20
|
+
#Définit la couleur des indices
|
|
21
|
+
CL_INDICES = "0, 32000, 65535"
|
|
22
|
+
#Définit la couleur du texte
|
|
23
|
+
CL_TEXTE = "0, 0, 0"
|
|
24
|
+
#Définit la police du texte
|
|
25
|
+
POLICE = "Sans Regular"
|
|
26
|
+
#Définit la taille de la police
|
|
27
|
+
TAILLE_POLICE = 25
|
|
28
|
+
|
|
29
|
+
##
|
|
30
|
+
## Initialisation
|
|
31
|
+
##
|
|
32
|
+
def initialize()
|
|
33
|
+
|
|
34
|
+
## Crée la table configuration
|
|
35
|
+
@@db.execute "CREATE TABLE IF NOT EXISTS configuration (
|
|
36
|
+
config_id integer primary key autoincrement,
|
|
37
|
+
caseBase varchar(30) DEFAULT '#{CL_CASE_BASE}',
|
|
38
|
+
caseFixe varchar(30) DEFAULT '#{CL_CASE_FIXE}',
|
|
39
|
+
caseSelectionne varchar(30) DEFAULT '#{CL_CASE_SELECTIONNE}',
|
|
40
|
+
couleurTexte varchar(30) DEFAULT '#{CL_TEXTE}',
|
|
41
|
+
couleurIndices varchar(30) DEFAULT '#{CL_INDICES}',
|
|
42
|
+
police varchar(50) DEFAULT 'Sans Regular',
|
|
43
|
+
taillePolice integer DEFAULT #{TAILLE_POLICE},
|
|
44
|
+
utilisateur integer,
|
|
45
|
+
FOREIGN KEY(utilisateur) REFERENCES utilisateur(utilisateur_id)
|
|
46
|
+
);"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
##
|
|
51
|
+
## Enregistre la configuration dans la base de donnée.
|
|
52
|
+
##
|
|
53
|
+
## @param config La Configuration
|
|
54
|
+
##
|
|
55
|
+
def enregistrer(pseudo, config)
|
|
56
|
+
utilisateur_id = @@db.execute "SELECT utilisateur_id FROM utilisateur WHERE pseudo=?", pseudo
|
|
57
|
+
|
|
58
|
+
req = @@db.execute "SELECT * FROM configuration WHERE utilisateur=?", utilisateur_id
|
|
59
|
+
|
|
60
|
+
params = Hash.new()
|
|
61
|
+
|
|
62
|
+
## Définit tout les paramètres à enregistrer à partir de la configuration
|
|
63
|
+
config.each do |key, param|
|
|
64
|
+
params[key.to_sym] = param
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
## Définit l'identifiant de l'utilisateur
|
|
68
|
+
params[:utilisateur] = utilisateur_id[0][0]
|
|
69
|
+
|
|
70
|
+
if(req.length > 0)
|
|
71
|
+
@@db.execute "DELETE FROM configuration WHERE utilisateur = ?", utilisateur_id[0][0]
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
insert(params)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
##
|
|
78
|
+
## Récupère la configuration de l'utilisateur
|
|
79
|
+
##
|
|
80
|
+
## @param pseudo Pseudo utilisateur
|
|
81
|
+
##
|
|
82
|
+
## @return Configuration sous forme de tableau
|
|
83
|
+
##
|
|
84
|
+
def getConfiguration(pseudo)
|
|
85
|
+
utilisateur_id = @@db.execute "SELECT utilisateur_id FROM utilisateur WHERE pseudo=?", pseudo
|
|
86
|
+
|
|
87
|
+
req = @@db.execute2 "SELECT caseBase, caseFixe, caseSelectionne, couleurTexte, couleurIndices, taillePolice, police FROM configuration WHERE utilisateur=?", utilisateur_id
|
|
88
|
+
|
|
89
|
+
## Pas de configuration trouvé donc on en
|
|
90
|
+
## crée une
|
|
91
|
+
if(req .length== 1)
|
|
92
|
+
self.creerConfiguration(pseudo)
|
|
93
|
+
req = @@db.execute2 "SELECT caseBase, caseFixe, caseSelectionne, couleurTexte, couleurIndices, taillePolice, police FROM configuration WHERE utilisateur=?", utilisateur_id
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
return self.to_h(req)[0]
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
##
|
|
100
|
+
## Limite le dépassement de valeur d'une couleur 16 bits
|
|
101
|
+
##
|
|
102
|
+
## @param couleur La couleur à vérifier
|
|
103
|
+
##
|
|
104
|
+
## @return La couleur limitée à la borne si dépassement sinon la couleur elle même
|
|
105
|
+
##
|
|
106
|
+
def verifierCouleur(couleur)
|
|
107
|
+
max = 65535
|
|
108
|
+
min = 0
|
|
109
|
+
|
|
110
|
+
if(couleur > max)
|
|
111
|
+
couleur = max
|
|
112
|
+
elsif(couleur < 0)
|
|
113
|
+
couleur = min
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
return couleur
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
##
|
|
120
|
+
## Convertis un gdk color en composantes
|
|
121
|
+
## sous forme d'une chaîne séparée par une virgule
|
|
122
|
+
##
|
|
123
|
+
## @param gdkColor GDK::Color
|
|
124
|
+
##
|
|
125
|
+
## @return Les composantes sous forme de chaîne
|
|
126
|
+
##
|
|
127
|
+
def couleur(gdkColor)
|
|
128
|
+
red = gdkColor.red
|
|
129
|
+
green = gdkColor.green
|
|
130
|
+
blue = gdkColor.blue
|
|
131
|
+
|
|
132
|
+
return "#{red},#{green},#{blue}"
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
##
|
|
136
|
+
## Crée un gdk color à partir d'une chaîne
|
|
137
|
+
##
|
|
138
|
+
## @param composantes Composantes ("r,g,b")
|
|
139
|
+
##
|
|
140
|
+
## @return Gdk::Color
|
|
141
|
+
##
|
|
142
|
+
def creerCouleur(composantes)
|
|
143
|
+
rgb = composantes.split(",")
|
|
144
|
+
|
|
145
|
+
red = self.verifierCouleur(rgb[0].to_i)
|
|
146
|
+
green = self.verifierCouleur(rgb[1].to_i)
|
|
147
|
+
blue = self.verifierCouleur(rgb[2].to_i)
|
|
148
|
+
|
|
149
|
+
return Gdk::Color.new(red, green, blue)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
##
|
|
153
|
+
## Crée une configuration par défaut pour l'utilisateur
|
|
154
|
+
##
|
|
155
|
+
## @param pseudo L'identifiant de l'utilisateur
|
|
156
|
+
##
|
|
157
|
+
## @return self
|
|
158
|
+
##
|
|
159
|
+
def creerConfiguration(pseudo)
|
|
160
|
+
|
|
161
|
+
## Récupère id utilisateur
|
|
162
|
+
req = @@db.execute "SELECT utilisateur_id FROM utilisateur WHERE pseudo = ?", pseudo
|
|
163
|
+
|
|
164
|
+
params = Hash.new()
|
|
165
|
+
|
|
166
|
+
params[:caseBase] = Configuration::CL_CASE_BASE
|
|
167
|
+
params[:caseFixe] = Configuration::CL_CASE_FIXE
|
|
168
|
+
params[:caseSelectionne] = Configuration::CL_CASE_SELECTIONNE
|
|
169
|
+
params[:couleurTexte] = Configuration::CL_TEXTE
|
|
170
|
+
params[:couleurIndices] = Configuration::CL_INDICES
|
|
171
|
+
params[:police] = Configuration::POLICE
|
|
172
|
+
params[:taillePolice] = Configuration::TAILLE_POLICE
|
|
173
|
+
params[:utilisateur] = req[0]
|
|
174
|
+
|
|
175
|
+
insert(params)
|
|
176
|
+
|
|
177
|
+
return self
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
end
|