0806
Showing
170 changed files
with
14376 additions
and
436 deletions
No preview for this file type
| ... | @@ -36,7 +36,7 @@ function LoadingScene:onCreate() | ... | @@ -36,7 +36,7 @@ function LoadingScene:onCreate() |
| 36 | end | 36 | end |
| 37 | 37 | ||
| 38 | self:addChild(self.ui); | 38 | self:addChild(self.ui); |
| 39 | 39 | --logD("LoadingScene------------->"..display.width); | |
| 40 | self.ui:setContentSize(cc.size(display.width,display.height)); | 40 | self.ui:setContentSize(cc.size(display.width,display.height)); |
| 41 | ccui.Helper:doLayout(self.ui); | 41 | ccui.Helper:doLayout(self.ui); |
| 42 | 42 | ... | ... |
client/rubbish/client/config.json
deleted
100644 → 0
| 1 | { | ||
| 2 | "init_cfg": { | ||
| 3 | "isLandscape": true, | ||
| 4 | "isWindowTop": false, | ||
| 5 | "name": "rubbish", | ||
| 6 | "width": 960, | ||
| 7 | "height": 640, | ||
| 8 | "entry": "src/main.lua", | ||
| 9 | "consolePort": 6050, | ||
| 10 | "uploadPort": 6060 | ||
| 11 | }, | ||
| 12 | "simulator_screen_size": [ | ||
| 13 | { | ||
| 14 | "title": "iPhone 3Gs (480x320)", | ||
| 15 | "width": 480, | ||
| 16 | "height": 320 | ||
| 17 | }, | ||
| 18 | { | ||
| 19 | "title": "iPhone 4 (960x640)", | ||
| 20 | "width": 960, | ||
| 21 | "height": 640 | ||
| 22 | }, | ||
| 23 | { | ||
| 24 | "title": "iPhone 5 (1136x640)", | ||
| 25 | "width": 1136, | ||
| 26 | "height": 640 | ||
| 27 | }, | ||
| 28 | { | ||
| 29 | "title": "iPad (1024x768)", | ||
| 30 | "width": 1024, | ||
| 31 | "height": 768 | ||
| 32 | }, | ||
| 33 | { | ||
| 34 | "title": "iPad Retina (2048x1536)", | ||
| 35 | "width": 2048, | ||
| 36 | "height": 1536 | ||
| 37 | }, | ||
| 38 | { | ||
| 39 | "title": "Android (800x480)", | ||
| 40 | "width": 800, | ||
| 41 | "height": 480 | ||
| 42 | }, | ||
| 43 | { | ||
| 44 | "title": "Android (854x480)", | ||
| 45 | "width": 854, | ||
| 46 | "height": 480 | ||
| 47 | }, | ||
| 48 | { | ||
| 49 | "title": "Android (1280x720)", | ||
| 50 | "width": 1280, | ||
| 51 | "height": 720 | ||
| 52 | }, | ||
| 53 | { | ||
| 54 | "title": "Android (1920x1080)", | ||
| 55 | "width": 1920, | ||
| 56 | "height": 1080 | ||
| 57 | } | ||
| 58 | ] | ||
| 59 | } | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
1.08 KB
1.09 KB
1.13 KB
| 1 | { | ||
| 2 | "content_scale": 0.1, | ||
| 3 | "armature_data": [ | ||
| 4 | { | ||
| 5 | "strVersion": "1.6.0.0", | ||
| 6 | "version": 1.6, | ||
| 7 | "name": "DemoPlayer", | ||
| 8 | "bone_data": [ | ||
| 9 | { | ||
| 10 | "name": "Layer15", | ||
| 11 | "parent": "", | ||
| 12 | "dI": 0, | ||
| 13 | "x": 54.000003814697266, | ||
| 14 | "y": 250.666610717773438, | ||
| 15 | "z": 5, | ||
| 16 | "cX": 1.0, | ||
| 17 | "cY": 1.0, | ||
| 18 | "kX": -1.56170571, | ||
| 19 | "kY": 1.56170571, | ||
| 20 | "arrow_x": 220.00907897949219, | ||
| 21 | "arrow_y": 2.3242086172103882E-05, | ||
| 22 | "effectbyskeleton": true, | ||
| 23 | "bl": 220, | ||
| 24 | "display_data": [ | ||
| 25 | { | ||
| 26 | "name": "defaultarmature6.png", | ||
| 27 | "displayType": 0, | ||
| 28 | "skin_data": [ | ||
| 29 | { | ||
| 30 | "x": 132.297546, | ||
| 31 | "y": 4.536171, | ||
| 32 | "cX": 1.0, | ||
| 33 | "cY": 1.0, | ||
| 34 | "kX": 1.56170583, | ||
| 35 | "kY": -1.56170583 | ||
| 36 | } | ||
| 37 | ] | ||
| 38 | } | ||
| 39 | ] | ||
| 40 | }, | ||
| 41 | { | ||
| 42 | "name": "Layer19", | ||
| 43 | "parent": "Layer15", | ||
| 44 | "dI": 0, | ||
| 45 | "x": 123.36190795898438, | ||
| 46 | "y": -112.550048828125, | ||
| 47 | "z": 10, | ||
| 48 | "cX": 0.9999998, | ||
| 49 | "cY": 1.00000012, | ||
| 50 | "kX": 2.62177181, | ||
| 51 | "kY": -2.62177181, | ||
| 52 | "arrow_x": 275.03634643554688, | ||
| 53 | "arrow_y": -1.7076730728149414E-05, | ||
| 54 | "effectbyskeleton": true, | ||
| 55 | "bl": 275, | ||
| 56 | "display_data": [ | ||
| 57 | { | ||
| 58 | "name": "defaultarmature1.png", | ||
| 59 | "displayType": 0, | ||
| 60 | "skin_data": [ | ||
| 61 | { | ||
| 62 | "x": -20.1246128, | ||
| 63 | "y": 0.0, | ||
| 64 | "cX": 1.0, | ||
| 65 | "cY": 1.0, | ||
| 66 | "kX": -1.10714829, | ||
| 67 | "kY": 1.10714829 | ||
| 68 | } | ||
| 69 | ] | ||
| 70 | } | ||
| 71 | ] | ||
| 72 | }, | ||
| 73 | { | ||
| 74 | "name": "Layer14", | ||
| 75 | "parent": "Layer15", | ||
| 76 | "dI": 0, | ||
| 77 | "x": 257.40774536132812, | ||
| 78 | "y": 29.674480438232422, | ||
| 79 | "z": 8, | ||
| 80 | "cX": 0.999999642, | ||
| 81 | "cY": 0.999999762, | ||
| 82 | "kX": -0.4505118, | ||
| 83 | "kY": 0.4505118, | ||
| 84 | "arrow_x": 301.94369506835938, | ||
| 85 | "arrow_y": -4.1484832763671875E-05, | ||
| 86 | "effectbyskeleton": true, | ||
| 87 | "bl": 301, | ||
| 88 | "display_data": [ | ||
| 89 | { | ||
| 90 | "name": "defaultarmaturehat.png", | ||
| 91 | "displayType": 0, | ||
| 92 | "skin_data": [ | ||
| 93 | { | ||
| 94 | "x": -49.9426651, | ||
| 95 | "y": 66.73429, | ||
| 96 | "cX": 1.0, | ||
| 97 | "cY": 1.0, | ||
| 98 | "kX": 2.012226, | ||
| 99 | "kY": -2.012226 | ||
| 100 | } | ||
| 101 | ] | ||
| 102 | } | ||
| 103 | ] | ||
| 104 | }, | ||
| 105 | { | ||
| 106 | "name": "Layer26", | ||
| 107 | "parent": "Layer15", | ||
| 108 | "dI": 0, | ||
| 109 | "x": 20.608369827270508, | ||
| 110 | "y": -33.655288696289062, | ||
| 111 | "z": 6, | ||
| 112 | "cX": 0.9999997, | ||
| 113 | "cY": 0.9999985, | ||
| 114 | "kX": 2.996584, | ||
| 115 | "kY": -2.996584, | ||
| 116 | "arrow_x": 168.69847106933594, | ||
| 117 | "arrow_y": 4.1231513023376465E-05, | ||
| 118 | "effectbyskeleton": true, | ||
| 119 | "bl": 168, | ||
| 120 | "display_data": [ | ||
| 121 | { | ||
| 122 | "name": "defaultarmature2.png", | ||
| 123 | "displayType": 0, | ||
| 124 | "skin_data": [ | ||
| 125 | { | ||
| 126 | "x": -3.944893, | ||
| 127 | "y": -2.48850441, | ||
| 128 | "cX": 1.0, | ||
| 129 | "cY": 1.0, | ||
| 130 | "kX": -1.43488753, | ||
| 131 | "kY": 1.43488753 | ||
| 132 | } | ||
| 133 | ] | ||
| 134 | } | ||
| 135 | ] | ||
| 136 | }, | ||
| 137 | { | ||
| 138 | "name": "Layer27", | ||
| 139 | "parent": "Layer26", | ||
| 140 | "dI": 0, | ||
| 141 | "x": 200.11383056640625, | ||
| 142 | "y": 55.397323608398438, | ||
| 143 | "z": 7, | ||
| 144 | "cX": 0.999995947, | ||
| 145 | "cY": 1.00000262, | ||
| 146 | "kX": 0.433240652, | ||
| 147 | "kY": -0.433240652, | ||
| 148 | "arrow_x": 122.89031219482422, | ||
| 149 | "arrow_y": 0.00011444091796875, | ||
| 150 | "effectbyskeleton": true, | ||
| 151 | "bl": 122, | ||
| 152 | "display_data": [ | ||
| 153 | { | ||
| 154 | "name": "defaultarmature7.png", | ||
| 155 | "displayType": 0, | ||
| 156 | "skin_data": [ | ||
| 157 | { | ||
| 158 | "x": -17.3824081, | ||
| 159 | "y": -14.7890148, | ||
| 160 | "cX": 1.0, | ||
| 161 | "cY": 1.0, | ||
| 162 | "kX": 4.41505146, | ||
| 163 | "kY": -4.41505146 | ||
| 164 | } | ||
| 165 | ] | ||
| 166 | } | ||
| 167 | ] | ||
| 168 | }, | ||
| 169 | { | ||
| 170 | "name": "Layer16", | ||
| 171 | "parent": "Layer15", | ||
| 172 | "dI": 0, | ||
| 173 | "x": 16.481224060058594, | ||
| 174 | "y": 20.483993530273438, | ||
| 175 | "z": 3, | ||
| 176 | "cX": 0.99999994, | ||
| 177 | "cY": 1.0, | ||
| 178 | "kX": 3.58497715, | ||
| 179 | "kY": -3.58497715, | ||
| 180 | "arrow_x": 160.11247253417969, | ||
| 181 | "arrow_y": 1.8954277038574219E-05, | ||
| 182 | "effectbyskeleton": true, | ||
| 183 | "bl": 160, | ||
| 184 | "display_data": [ | ||
| 185 | { | ||
| 186 | "name": "defaultarmature5.png", | ||
| 187 | "displayType": 0, | ||
| 188 | "skin_data": [ | ||
| 189 | { | ||
| 190 | "x": -16.5717163, | ||
| 191 | "y": 11.21711, | ||
| 192 | "cX": 1.0, | ||
| 193 | "cY": 1.0, | ||
| 194 | "kX": 4.259914, | ||
| 195 | "kY": -4.259914 | ||
| 196 | } | ||
| 197 | ] | ||
| 198 | } | ||
| 199 | ] | ||
| 200 | }, | ||
| 201 | { | ||
| 202 | "name": "Layer17", | ||
| 203 | "parent": "Layer16", | ||
| 204 | "dI": 0, | ||
| 205 | "x": 197.54862976074219, | ||
| 206 | "y": 28.205173492431641, | ||
| 207 | "z": 4, | ||
| 208 | "cX": 1.00000024, | ||
| 209 | "cY": 0.9999992, | ||
| 210 | "kX": 0.214985371, | ||
| 211 | "kY": -0.214985371, | ||
| 212 | "arrow_x": 150.24311828613281, | ||
| 213 | "arrow_y": 3.5464763641357422E-05, | ||
| 214 | "effectbyskeleton": true, | ||
| 215 | "bl": 150, | ||
| 216 | "display_data": [ | ||
| 217 | { | ||
| 218 | "name": "defaultarmature4.png", | ||
| 219 | "displayType": 0, | ||
| 220 | "skin_data": [ | ||
| 221 | { | ||
| 222 | "x": -16.01846, | ||
| 223 | "y": -4.98530674, | ||
| 224 | "cX": 1.00000012, | ||
| 225 | "cY": 1.00000012, | ||
| 226 | "kX": 4.044924, | ||
| 227 | "kY": -4.044924 | ||
| 228 | } | ||
| 229 | ] | ||
| 230 | } | ||
| 231 | ] | ||
| 232 | }, | ||
| 233 | { | ||
| 234 | "name": "Layer21", | ||
| 235 | "parent": "Layer15", | ||
| 236 | "dI": 0, | ||
| 237 | "x": 116.17247009277344, | ||
| 238 | "y": 73.225761413574219, | ||
| 239 | "z": 1, | ||
| 240 | "cX": 0.99999994, | ||
| 241 | "cY": 0.9999998, | ||
| 242 | "kX": 3.90080166, | ||
| 243 | "kY": -3.90080166, | ||
| 244 | "arrow_x": 165.48709106445313, | ||
| 245 | "arrow_y": -2.9265880584716797E-05, | ||
| 246 | "effectbyskeleton": true, | ||
| 247 | "bl": 165, | ||
| 248 | "display_data": [ | ||
| 249 | { | ||
| 250 | "name": "defaultarmature8.png", | ||
| 251 | "displayType": 0, | ||
| 252 | "skin_data": [ | ||
| 253 | { | ||
| 254 | "x": -28.4311485, | ||
| 255 | "y": -8.354063, | ||
| 256 | "cX": 1.0, | ||
| 257 | "cY": 1.0, | ||
| 258 | "kX": 4.061894, | ||
| 259 | "kY": -4.061894 | ||
| 260 | } | ||
| 261 | ] | ||
| 262 | } | ||
| 263 | ] | ||
| 264 | }, | ||
| 265 | { | ||
| 266 | "name": "Layer20", | ||
| 267 | "parent": "Layer21", | ||
| 268 | "dI": 0, | ||
| 269 | "x": 106.61399841308594, | ||
| 270 | "y": 0.1221771240234375, | ||
| 271 | "z": 2, | ||
| 272 | "cX": 1.000001, | ||
| 273 | "cY": 0.9999987, | ||
| 274 | "kX": 0.5211258, | ||
| 275 | "kY": -0.5211258, | ||
| 276 | "arrow_x": 313.3209228515625, | ||
| 277 | "arrow_y": 3.7372112274169922E-05, | ||
| 278 | "effectbyskeleton": true, | ||
| 279 | "bl": 313, | ||
| 280 | "display_data": [ | ||
| 281 | { | ||
| 282 | "name": "defaultarmature3.png", | ||
| 283 | "displayType": 0, | ||
| 284 | "skin_data": [ | ||
| 285 | { | ||
| 286 | "x": -1.5777359, | ||
| 287 | "y": -36.6707153, | ||
| 288 | "cX": 1.0, | ||
| 289 | "cY": 1.0, | ||
| 290 | "kX": 1.46715176, | ||
| 291 | "kY": -1.46715176 | ||
| 292 | } | ||
| 293 | ] | ||
| 294 | } | ||
| 295 | ] | ||
| 296 | } | ||
| 297 | ] | ||
| 298 | } | ||
| 299 | ], | ||
| 300 | "animation_data": [ | ||
| 301 | { | ||
| 302 | "name": "DemoPlayer", | ||
| 303 | "mov_data": [ | ||
| 304 | { | ||
| 305 | "name": "walk", | ||
| 306 | "dr": 40, | ||
| 307 | "lp": true, | ||
| 308 | "to": 0, | ||
| 309 | "drTW": 0, | ||
| 310 | "twE": 0, | ||
| 311 | "sc": 0.6666667, | ||
| 312 | "mov_bone_data": [ | ||
| 313 | { | ||
| 314 | "name": "Layer19", | ||
| 315 | "dl": 0.0, | ||
| 316 | "frame_data": [ | ||
| 317 | { | ||
| 318 | "dI": 0, | ||
| 319 | "x": 0.0, | ||
| 320 | "y": 0.0, | ||
| 321 | "z": 0, | ||
| 322 | "cX": 1.0, | ||
| 323 | "cY": 1.0, | ||
| 324 | "kX": 0.429569155, | ||
| 325 | "kY": -0.429569155, | ||
| 326 | "fi": 0, | ||
| 327 | "twE": 0, | ||
| 328 | "tweenFrame": true, | ||
| 329 | "color": { | ||
| 330 | "a": 255, | ||
| 331 | "r": 255, | ||
| 332 | "g": 255, | ||
| 333 | "b": 255 | ||
| 334 | }, | ||
| 335 | "bd_src": 1, | ||
| 336 | "bd_dst": 771 | ||
| 337 | }, | ||
| 338 | { | ||
| 339 | "dI": 0, | ||
| 340 | "x": 0.0, | ||
| 341 | "y": 0.0, | ||
| 342 | "z": 0, | ||
| 343 | "cX": 1.0, | ||
| 344 | "cY": 1.0, | ||
| 345 | "kX": 1.26362371, | ||
| 346 | "kY": -1.26362371, | ||
| 347 | "fi": 10, | ||
| 348 | "twE": 0, | ||
| 349 | "tweenFrame": true, | ||
| 350 | "bd_src": 1, | ||
| 351 | "bd_dst": 771 | ||
| 352 | }, | ||
| 353 | { | ||
| 354 | "dI": 0, | ||
| 355 | "x": 0.0, | ||
| 356 | "y": 0.0, | ||
| 357 | "z": 0, | ||
| 358 | "cX": 1.0, | ||
| 359 | "cY": 1.0, | ||
| 360 | "kX": 0.429569155, | ||
| 361 | "kY": -0.429569155, | ||
| 362 | "fi": 20, | ||
| 363 | "twE": 0, | ||
| 364 | "tweenFrame": true, | ||
| 365 | "color": { | ||
| 366 | "a": 255, | ||
| 367 | "r": 255, | ||
| 368 | "g": 255, | ||
| 369 | "b": 255 | ||
| 370 | }, | ||
| 371 | "bd_src": 1, | ||
| 372 | "bd_dst": 771 | ||
| 373 | }, | ||
| 374 | { | ||
| 375 | "dI": 0, | ||
| 376 | "x": 0.0, | ||
| 377 | "y": 0.0, | ||
| 378 | "z": 0, | ||
| 379 | "cX": 1.0, | ||
| 380 | "cY": 1.0, | ||
| 381 | "kX": -0.139068469, | ||
| 382 | "kY": 0.139068469, | ||
| 383 | "fi": 30, | ||
| 384 | "twE": 0, | ||
| 385 | "tweenFrame": true, | ||
| 386 | "bd_src": 1, | ||
| 387 | "bd_dst": 771 | ||
| 388 | }, | ||
| 389 | { | ||
| 390 | "dI": 0, | ||
| 391 | "x": 0.0, | ||
| 392 | "y": 0.0, | ||
| 393 | "z": 0, | ||
| 394 | "cX": 1.0, | ||
| 395 | "cY": 1.0, | ||
| 396 | "kX": 0.429569155, | ||
| 397 | "kY": -0.429569155, | ||
| 398 | "fi": 40, | ||
| 399 | "twE": 0, | ||
| 400 | "tweenFrame": true, | ||
| 401 | "color": { | ||
| 402 | "a": 255, | ||
| 403 | "r": 255, | ||
| 404 | "g": 255, | ||
| 405 | "b": 255 | ||
| 406 | }, | ||
| 407 | "bd_src": 1, | ||
| 408 | "bd_dst": 771 | ||
| 409 | } | ||
| 410 | ] | ||
| 411 | }, | ||
| 412 | { | ||
| 413 | "name": "Layer14", | ||
| 414 | "dl": 0.0, | ||
| 415 | "frame_data": [ | ||
| 416 | { | ||
| 417 | "dI": 0, | ||
| 418 | "x": 0.0, | ||
| 419 | "y": 0.0, | ||
| 420 | "z": 0, | ||
| 421 | "cX": 1.0, | ||
| 422 | "cY": 1.0, | ||
| 423 | "kX": 0.239736915, | ||
| 424 | "kY": -0.239736915, | ||
| 425 | "fi": 0, | ||
| 426 | "twE": 0, | ||
| 427 | "tweenFrame": true, | ||
| 428 | "bd_src": 1, | ||
| 429 | "bd_dst": 771 | ||
| 430 | }, | ||
| 431 | { | ||
| 432 | "dI": 0, | ||
| 433 | "x": 0.0, | ||
| 434 | "y": 0.0, | ||
| 435 | "z": 0, | ||
| 436 | "cX": 1.0, | ||
| 437 | "cY": 1.0, | ||
| 438 | "kX": 0.344456673, | ||
| 439 | "kY": -0.344456673, | ||
| 440 | "fi": 20, | ||
| 441 | "twE": 0, | ||
| 442 | "tweenFrame": true, | ||
| 443 | "bd_src": 1, | ||
| 444 | "bd_dst": 771 | ||
| 445 | }, | ||
| 446 | { | ||
| 447 | "dI": 0, | ||
| 448 | "x": 0.0, | ||
| 449 | "y": 0.0, | ||
| 450 | "z": 0, | ||
| 451 | "cX": 1.0, | ||
| 452 | "cY": 1.0, | ||
| 453 | "kX": 0.239736915, | ||
| 454 | "kY": -0.239736915, | ||
| 455 | "fi": 40, | ||
| 456 | "twE": 0, | ||
| 457 | "tweenFrame": true, | ||
| 458 | "bd_src": 1, | ||
| 459 | "bd_dst": 771 | ||
| 460 | } | ||
| 461 | ] | ||
| 462 | }, | ||
| 463 | { | ||
| 464 | "name": "Layer27", | ||
| 465 | "dl": 0.0, | ||
| 466 | "frame_data": [ | ||
| 467 | { | ||
| 468 | "dI": 0, | ||
| 469 | "x": 0.0, | ||
| 470 | "y": 0.0, | ||
| 471 | "z": 0, | ||
| 472 | "cX": 1.0, | ||
| 473 | "cY": 1.0, | ||
| 474 | "kX": -0.6832336, | ||
| 475 | "kY": 0.6832336, | ||
| 476 | "fi": 0, | ||
| 477 | "twE": 0, | ||
| 478 | "tweenFrame": true, | ||
| 479 | "bd_src": 1, | ||
| 480 | "bd_dst": 771 | ||
| 481 | }, | ||
| 482 | { | ||
| 483 | "dI": 0, | ||
| 484 | "x": 0.0, | ||
| 485 | "y": 0.0, | ||
| 486 | "z": 0, | ||
| 487 | "cX": 1.0, | ||
| 488 | "cY": 1.0, | ||
| 489 | "kX": -0.6832336, | ||
| 490 | "kY": 0.6832336, | ||
| 491 | "fi": 10, | ||
| 492 | "twE": 0, | ||
| 493 | "tweenFrame": true, | ||
| 494 | "bd_src": 1, | ||
| 495 | "bd_dst": 771 | ||
| 496 | }, | ||
| 497 | { | ||
| 498 | "dI": 0, | ||
| 499 | "x": 0.0, | ||
| 500 | "y": 0.0, | ||
| 501 | "z": 0, | ||
| 502 | "cX": 1.0, | ||
| 503 | "cY": 1.0, | ||
| 504 | "kX": -0.6832336, | ||
| 505 | "kY": 0.6832336, | ||
| 506 | "fi": 20, | ||
| 507 | "twE": 0, | ||
| 508 | "tweenFrame": true, | ||
| 509 | "bd_src": 1, | ||
| 510 | "bd_dst": 771 | ||
| 511 | }, | ||
| 512 | { | ||
| 513 | "dI": 0, | ||
| 514 | "x": 0.0, | ||
| 515 | "y": 0.0, | ||
| 516 | "z": 0, | ||
| 517 | "cX": 1.0, | ||
| 518 | "cY": 1.0, | ||
| 519 | "kX": -0.6832336, | ||
| 520 | "kY": 0.6832336, | ||
| 521 | "fi": 30, | ||
| 522 | "twE": 0, | ||
| 523 | "tweenFrame": true, | ||
| 524 | "bd_src": 1, | ||
| 525 | "bd_dst": 771 | ||
| 526 | }, | ||
| 527 | { | ||
| 528 | "dI": 0, | ||
| 529 | "x": 0.0, | ||
| 530 | "y": 0.0, | ||
| 531 | "z": 0, | ||
| 532 | "cX": 1.0, | ||
| 533 | "cY": 1.0, | ||
| 534 | "kX": -0.6832336, | ||
| 535 | "kY": 0.6832336, | ||
| 536 | "fi": 40, | ||
| 537 | "twE": 0, | ||
| 538 | "tweenFrame": true, | ||
| 539 | "bd_src": 1, | ||
| 540 | "bd_dst": 771 | ||
| 541 | } | ||
| 542 | ] | ||
| 543 | }, | ||
| 544 | { | ||
| 545 | "name": "Layer26", | ||
| 546 | "dl": 0.0, | ||
| 547 | "frame_data": [ | ||
| 548 | { | ||
| 549 | "dI": 0, | ||
| 550 | "x": -11.804702758789063, | ||
| 551 | "y": 41.322967529296875, | ||
| 552 | "z": 0, | ||
| 553 | "cX": 1.0, | ||
| 554 | "cY": 1.0, | ||
| 555 | "kX": 0.3840222, | ||
| 556 | "kY": -0.3840222, | ||
| 557 | "fi": 0, | ||
| 558 | "twE": 0, | ||
| 559 | "tweenFrame": true, | ||
| 560 | "color": { | ||
| 561 | "a": 255, | ||
| 562 | "r": 255, | ||
| 563 | "g": 255, | ||
| 564 | "b": 255 | ||
| 565 | }, | ||
| 566 | "bd_src": 1, | ||
| 567 | "bd_dst": 771 | ||
| 568 | }, | ||
| 569 | { | ||
| 570 | "dI": 0, | ||
| 571 | "x": -11.804702758789063, | ||
| 572 | "y": 41.322967529296875, | ||
| 573 | "z": 0, | ||
| 574 | "cX": 1.0, | ||
| 575 | "cY": 1.0, | ||
| 576 | "kX": -0.517191947, | ||
| 577 | "kY": 0.517191947, | ||
| 578 | "fi": 10, | ||
| 579 | "twE": 0, | ||
| 580 | "tweenFrame": true, | ||
| 581 | "bd_src": 1, | ||
| 582 | "bd_dst": 771 | ||
| 583 | }, | ||
| 584 | { | ||
| 585 | "dI": 0, | ||
| 586 | "x": -11.804702758789063, | ||
| 587 | "y": 41.322967529296875, | ||
| 588 | "z": 0, | ||
| 589 | "cX": 1.0, | ||
| 590 | "cY": 1.0, | ||
| 591 | "kX": 0.3840222, | ||
| 592 | "kY": -0.3840222, | ||
| 593 | "fi": 20, | ||
| 594 | "twE": 0, | ||
| 595 | "tweenFrame": true, | ||
| 596 | "color": { | ||
| 597 | "a": 255, | ||
| 598 | "r": 255, | ||
| 599 | "g": 255, | ||
| 600 | "b": 255 | ||
| 601 | }, | ||
| 602 | "bd_src": 1, | ||
| 603 | "bd_dst": 771 | ||
| 604 | }, | ||
| 605 | { | ||
| 606 | "dI": 0, | ||
| 607 | "x": -11.804702758789063, | ||
| 608 | "y": 41.322967529296875, | ||
| 609 | "z": 0, | ||
| 610 | "cX": 1.0, | ||
| 611 | "cY": 1.0, | ||
| 612 | "kX": 0.9251928, | ||
| 613 | "kY": -0.9251928, | ||
| 614 | "fi": 30, | ||
| 615 | "twE": 0, | ||
| 616 | "tweenFrame": true, | ||
| 617 | "bd_src": 1, | ||
| 618 | "bd_dst": 771 | ||
| 619 | }, | ||
| 620 | { | ||
| 621 | "dI": 0, | ||
| 622 | "x": -11.804702758789063, | ||
| 623 | "y": 41.322967529296875, | ||
| 624 | "z": 0, | ||
| 625 | "cX": 1.0, | ||
| 626 | "cY": 1.0, | ||
| 627 | "kX": 0.3840222, | ||
| 628 | "kY": -0.3840222, | ||
| 629 | "fi": 40, | ||
| 630 | "twE": 0, | ||
| 631 | "tweenFrame": true, | ||
| 632 | "color": { | ||
| 633 | "a": 255, | ||
| 634 | "r": 255, | ||
| 635 | "g": 255, | ||
| 636 | "b": 255 | ||
| 637 | }, | ||
| 638 | "bd_src": 1, | ||
| 639 | "bd_dst": 771 | ||
| 640 | } | ||
| 641 | ] | ||
| 642 | }, | ||
| 643 | { | ||
| 644 | "name": "Layer15", | ||
| 645 | "dl": 0.0, | ||
| 646 | "frame_data": [ | ||
| 647 | { | ||
| 648 | "dI": 0, | ||
| 649 | "x": 0.0, | ||
| 650 | "y": 0.0, | ||
| 651 | "z": 0, | ||
| 652 | "cX": 1.0, | ||
| 653 | "cY": 1.0, | ||
| 654 | "kX": 0.0, | ||
| 655 | "kY": 0.0, | ||
| 656 | "fi": 0, | ||
| 657 | "twE": 0, | ||
| 658 | "tweenFrame": true, | ||
| 659 | "bd_src": 1, | ||
| 660 | "bd_dst": 771 | ||
| 661 | }, | ||
| 662 | { | ||
| 663 | "dI": 0, | ||
| 664 | "x": 0.0, | ||
| 665 | "y": -10.0, | ||
| 666 | "z": 0, | ||
| 667 | "cX": 1.0, | ||
| 668 | "cY": 1.0, | ||
| 669 | "kX": 1.01589744E-16, | ||
| 670 | "kY": -1.01589744E-16, | ||
| 671 | "fi": 10, | ||
| 672 | "twE": 0, | ||
| 673 | "tweenFrame": true, | ||
| 674 | "bd_src": 1, | ||
| 675 | "bd_dst": 771 | ||
| 676 | }, | ||
| 677 | { | ||
| 678 | "dI": 0, | ||
| 679 | "x": 0.0, | ||
| 680 | "y": 0.0, | ||
| 681 | "z": 0, | ||
| 682 | "cX": 1.0, | ||
| 683 | "cY": 1.0, | ||
| 684 | "kX": 0.0, | ||
| 685 | "kY": 0.0, | ||
| 686 | "fi": 20, | ||
| 687 | "twE": 0, | ||
| 688 | "tweenFrame": true, | ||
| 689 | "bd_src": 1, | ||
| 690 | "bd_dst": 771 | ||
| 691 | }, | ||
| 692 | { | ||
| 693 | "dI": 0, | ||
| 694 | "x": 0.0, | ||
| 695 | "y": -10.0, | ||
| 696 | "z": 0, | ||
| 697 | "cX": 1.0, | ||
| 698 | "cY": 1.0, | ||
| 699 | "kX": 0.0, | ||
| 700 | "kY": 0.0, | ||
| 701 | "fi": 30, | ||
| 702 | "twE": 0, | ||
| 703 | "tweenFrame": true, | ||
| 704 | "bd_src": 1, | ||
| 705 | "bd_dst": 771 | ||
| 706 | }, | ||
| 707 | { | ||
| 708 | "dI": 0, | ||
| 709 | "x": 0.0, | ||
| 710 | "y": 0.0, | ||
| 711 | "z": 0, | ||
| 712 | "cX": 1.0, | ||
| 713 | "cY": 1.0, | ||
| 714 | "kX": 0.0, | ||
| 715 | "kY": 0.0, | ||
| 716 | "fi": 40, | ||
| 717 | "twE": 0, | ||
| 718 | "tweenFrame": true, | ||
| 719 | "bd_src": 1, | ||
| 720 | "bd_dst": 771 | ||
| 721 | } | ||
| 722 | ] | ||
| 723 | }, | ||
| 724 | { | ||
| 725 | "name": "Layer17", | ||
| 726 | "dl": 0.0, | ||
| 727 | "frame_data": [ | ||
| 728 | { | ||
| 729 | "dI": 0, | ||
| 730 | "x": 0.0, | ||
| 731 | "y": 0.0, | ||
| 732 | "z": 0, | ||
| 733 | "cX": 1.0, | ||
| 734 | "cY": 1.0, | ||
| 735 | "kX": -0.07913655, | ||
| 736 | "kY": 0.07913655, | ||
| 737 | "fi": 0, | ||
| 738 | "twE": 0, | ||
| 739 | "tweenFrame": true, | ||
| 740 | "color": { | ||
| 741 | "a": 255, | ||
| 742 | "r": 255, | ||
| 743 | "g": 255, | ||
| 744 | "b": 255 | ||
| 745 | }, | ||
| 746 | "bd_src": 1, | ||
| 747 | "bd_dst": 771 | ||
| 748 | }, | ||
| 749 | { | ||
| 750 | "dI": 0, | ||
| 751 | "x": 0.0, | ||
| 752 | "y": 0.0, | ||
| 753 | "z": 0, | ||
| 754 | "cX": 1.0, | ||
| 755 | "cY": 1.0, | ||
| 756 | "kX": -0.07913655, | ||
| 757 | "kY": 0.07913655, | ||
| 758 | "fi": 10, | ||
| 759 | "twE": 0, | ||
| 760 | "tweenFrame": true, | ||
| 761 | "bd_src": 1, | ||
| 762 | "bd_dst": 771 | ||
| 763 | }, | ||
| 764 | { | ||
| 765 | "dI": 0, | ||
| 766 | "x": 0.0, | ||
| 767 | "y": 0.0, | ||
| 768 | "z": 0, | ||
| 769 | "cX": 1.0, | ||
| 770 | "cY": 1.0, | ||
| 771 | "kX": -0.07913655, | ||
| 772 | "kY": 0.07913655, | ||
| 773 | "fi": 20, | ||
| 774 | "twE": 0, | ||
| 775 | "tweenFrame": true, | ||
| 776 | "color": { | ||
| 777 | "a": 255, | ||
| 778 | "r": 255, | ||
| 779 | "g": 255, | ||
| 780 | "b": 255 | ||
| 781 | }, | ||
| 782 | "bd_src": 1, | ||
| 783 | "bd_dst": 771 | ||
| 784 | }, | ||
| 785 | { | ||
| 786 | "dI": 0, | ||
| 787 | "x": 0.0, | ||
| 788 | "y": 0.0, | ||
| 789 | "z": 0, | ||
| 790 | "cX": 1.0, | ||
| 791 | "cY": 1.0, | ||
| 792 | "kX": -0.07913655, | ||
| 793 | "kY": 0.07913655, | ||
| 794 | "fi": 30, | ||
| 795 | "twE": 0, | ||
| 796 | "tweenFrame": true, | ||
| 797 | "bd_src": 1, | ||
| 798 | "bd_dst": 771 | ||
| 799 | }, | ||
| 800 | { | ||
| 801 | "dI": 0, | ||
| 802 | "x": 0.0, | ||
| 803 | "y": 0.0, | ||
| 804 | "z": 0, | ||
| 805 | "cX": 1.0, | ||
| 806 | "cY": 1.0, | ||
| 807 | "kX": -0.07913655, | ||
| 808 | "kY": 0.07913655, | ||
| 809 | "fi": 40, | ||
| 810 | "twE": 0, | ||
| 811 | "tweenFrame": true, | ||
| 812 | "color": { | ||
| 813 | "a": 255, | ||
| 814 | "r": 255, | ||
| 815 | "g": 255, | ||
| 816 | "b": 255 | ||
| 817 | }, | ||
| 818 | "bd_src": 1, | ||
| 819 | "bd_dst": 771 | ||
| 820 | } | ||
| 821 | ] | ||
| 822 | }, | ||
| 823 | { | ||
| 824 | "name": "Layer16", | ||
| 825 | "dl": 0.0, | ||
| 826 | "frame_data": [ | ||
| 827 | { | ||
| 828 | "dI": 0, | ||
| 829 | "x": -0.026004791259765625, | ||
| 830 | "y": -23.334545135498047, | ||
| 831 | "z": 0, | ||
| 832 | "cX": 1.0, | ||
| 833 | "cY": 1.0, | ||
| 834 | "kX": -0.477984279, | ||
| 835 | "kY": 0.477984279, | ||
| 836 | "fi": 0, | ||
| 837 | "twE": 0, | ||
| 838 | "tweenFrame": true, | ||
| 839 | "bd_src": 1, | ||
| 840 | "bd_dst": 771 | ||
| 841 | }, | ||
| 842 | { | ||
| 843 | "dI": 0, | ||
| 844 | "x": -0.026004791259765625, | ||
| 845 | "y": -23.334545135498047, | ||
| 846 | "z": 0, | ||
| 847 | "cX": 1.0, | ||
| 848 | "cY": 1.0, | ||
| 849 | "kX": 0.289089769, | ||
| 850 | "kY": -0.289089769, | ||
| 851 | "fi": 10, | ||
| 852 | "twE": 0, | ||
| 853 | "tweenFrame": true, | ||
| 854 | "bd_src": 1, | ||
| 855 | "bd_dst": 771 | ||
| 856 | }, | ||
| 857 | { | ||
| 858 | "dI": 0, | ||
| 859 | "x": -0.026004791259765625, | ||
| 860 | "y": -23.334545135498047, | ||
| 861 | "z": 0, | ||
| 862 | "cX": 1.0, | ||
| 863 | "cY": 1.0, | ||
| 864 | "kX": -0.477984279, | ||
| 865 | "kY": 0.477984279, | ||
| 866 | "fi": 20, | ||
| 867 | "twE": 0, | ||
| 868 | "tweenFrame": true, | ||
| 869 | "bd_src": 1, | ||
| 870 | "bd_dst": 771 | ||
| 871 | }, | ||
| 872 | { | ||
| 873 | "dI": 0, | ||
| 874 | "x": -0.026004791259765625, | ||
| 875 | "y": -23.334545135498047, | ||
| 876 | "z": 0, | ||
| 877 | "cX": 1.0, | ||
| 878 | "cY": 1.0, | ||
| 879 | "kX": -1.04626465, | ||
| 880 | "kY": 1.04626465, | ||
| 881 | "fi": 30, | ||
| 882 | "twE": 0, | ||
| 883 | "tweenFrame": true, | ||
| 884 | "bd_src": 1, | ||
| 885 | "bd_dst": 771 | ||
| 886 | }, | ||
| 887 | { | ||
| 888 | "dI": 0, | ||
| 889 | "x": -0.026004791259765625, | ||
| 890 | "y": -23.334545135498047, | ||
| 891 | "z": 0, | ||
| 892 | "cX": 1.0, | ||
| 893 | "cY": 1.0, | ||
| 894 | "kX": -0.477984279, | ||
| 895 | "kY": 0.477984279, | ||
| 896 | "fi": 40, | ||
| 897 | "twE": 0, | ||
| 898 | "tweenFrame": true, | ||
| 899 | "bd_src": 1, | ||
| 900 | "bd_dst": 771 | ||
| 901 | } | ||
| 902 | ] | ||
| 903 | }, | ||
| 904 | { | ||
| 905 | "name": "Layer20", | ||
| 906 | "dl": 0.0, | ||
| 907 | "frame_data": [ | ||
| 908 | { | ||
| 909 | "dI": 0, | ||
| 910 | "x": 0.0, | ||
| 911 | "y": 0.0, | ||
| 912 | "z": 0, | ||
| 913 | "cX": 1.0, | ||
| 914 | "cY": 1.0, | ||
| 915 | "kX": 12.758029, | ||
| 916 | "kY": -12.758029, | ||
| 917 | "fi": 0, | ||
| 918 | "twE": 0, | ||
| 919 | "tweenFrame": true, | ||
| 920 | "bd_src": 1, | ||
| 921 | "bd_dst": 771 | ||
| 922 | }, | ||
| 923 | { | ||
| 924 | "dI": 0, | ||
| 925 | "x": 0.0, | ||
| 926 | "y": 0.0, | ||
| 927 | "z": 0, | ||
| 928 | "cX": 1.0, | ||
| 929 | "cY": 1.0, | ||
| 930 | "kX": 14.4511929, | ||
| 931 | "kY": -14.4511929, | ||
| 932 | "fi": 10, | ||
| 933 | "twE": 0, | ||
| 934 | "tweenFrame": true, | ||
| 935 | "bd_src": 1, | ||
| 936 | "bd_dst": 771 | ||
| 937 | }, | ||
| 938 | { | ||
| 939 | "dI": 0, | ||
| 940 | "x": 0.0, | ||
| 941 | "y": 0.0, | ||
| 942 | "z": 0, | ||
| 943 | "cX": 1.0, | ||
| 944 | "cY": 1.0, | ||
| 945 | "kX": 12.758029, | ||
| 946 | "kY": -12.758029, | ||
| 947 | "fi": 20, | ||
| 948 | "twE": 0, | ||
| 949 | "tweenFrame": true, | ||
| 950 | "bd_src": 1, | ||
| 951 | "bd_dst": 771 | ||
| 952 | }, | ||
| 953 | { | ||
| 954 | "dI": 0, | ||
| 955 | "x": 0.0, | ||
| 956 | "y": 0.0, | ||
| 957 | "z": 0, | ||
| 958 | "cX": 1.0, | ||
| 959 | "cY": 1.0, | ||
| 960 | "kX": 12.5519829, | ||
| 961 | "kY": -12.5519829, | ||
| 962 | "fi": 30, | ||
| 963 | "twE": 0, | ||
| 964 | "tweenFrame": true, | ||
| 965 | "bd_src": 1, | ||
| 966 | "bd_dst": 771 | ||
| 967 | }, | ||
| 968 | { | ||
| 969 | "dI": 0, | ||
| 970 | "x": 0.0, | ||
| 971 | "y": 0.0, | ||
| 972 | "z": 0, | ||
| 973 | "cX": 1.0, | ||
| 974 | "cY": 1.0, | ||
| 975 | "kX": 12.758029, | ||
| 976 | "kY": -12.758029, | ||
| 977 | "fi": 40, | ||
| 978 | "twE": 0, | ||
| 979 | "tweenFrame": true, | ||
| 980 | "bd_src": 1, | ||
| 981 | "bd_dst": 771 | ||
| 982 | } | ||
| 983 | ] | ||
| 984 | }, | ||
| 985 | { | ||
| 986 | "name": "Layer21", | ||
| 987 | "dl": 0.0, | ||
| 988 | "frame_data": [ | ||
| 989 | { | ||
| 990 | "dI": 0, | ||
| 991 | "x": 0.0, | ||
| 992 | "y": 0.0, | ||
| 993 | "z": 0, | ||
| 994 | "cX": 1.0, | ||
| 995 | "cY": 1.0, | ||
| 996 | "kX": -0.6352831, | ||
| 997 | "kY": 0.6352831, | ||
| 998 | "fi": 0, | ||
| 999 | "twE": 0, | ||
| 1000 | "tweenFrame": true, | ||
| 1001 | "color": { | ||
| 1002 | "a": 255, | ||
| 1003 | "r": 255, | ||
| 1004 | "g": 255, | ||
| 1005 | "b": 255 | ||
| 1006 | }, | ||
| 1007 | "bd_src": 1, | ||
| 1008 | "bd_dst": 771 | ||
| 1009 | }, | ||
| 1010 | { | ||
| 1011 | "dI": 0, | ||
| 1012 | "x": 0.0, | ||
| 1013 | "y": 0.0, | ||
| 1014 | "z": 0, | ||
| 1015 | "cX": 1.0, | ||
| 1016 | "cY": 1.0, | ||
| 1017 | "kX": -2.222432, | ||
| 1018 | "kY": 2.222432, | ||
| 1019 | "fi": 10, | ||
| 1020 | "twE": 0, | ||
| 1021 | "tweenFrame": true, | ||
| 1022 | "bd_src": 1, | ||
| 1023 | "bd_dst": 771 | ||
| 1024 | }, | ||
| 1025 | { | ||
| 1026 | "dI": 0, | ||
| 1027 | "x": 0.0, | ||
| 1028 | "y": 0.0, | ||
| 1029 | "z": 0, | ||
| 1030 | "cX": 1.0, | ||
| 1031 | "cY": 1.0, | ||
| 1032 | "kX": -0.6352831, | ||
| 1033 | "kY": 0.6352831, | ||
| 1034 | "fi": 20, | ||
| 1035 | "twE": 0, | ||
| 1036 | "tweenFrame": true, | ||
| 1037 | "color": { | ||
| 1038 | "a": 255, | ||
| 1039 | "r": 255, | ||
| 1040 | "g": 255, | ||
| 1041 | "b": 255 | ||
| 1042 | }, | ||
| 1043 | "bd_src": 1, | ||
| 1044 | "bd_dst": 771 | ||
| 1045 | }, | ||
| 1046 | { | ||
| 1047 | "dI": 0, | ||
| 1048 | "x": 0.0, | ||
| 1049 | "y": 0.0, | ||
| 1050 | "z": 0, | ||
| 1051 | "cX": 1.0, | ||
| 1052 | "cY": 1.0, | ||
| 1053 | "kX": 0.0292310268, | ||
| 1054 | "kY": -0.0292310268, | ||
| 1055 | "fi": 30, | ||
| 1056 | "twE": 0, | ||
| 1057 | "tweenFrame": true, | ||
| 1058 | "bd_src": 1, | ||
| 1059 | "bd_dst": 771 | ||
| 1060 | }, | ||
| 1061 | { | ||
| 1062 | "dI": 0, | ||
| 1063 | "x": 0.0, | ||
| 1064 | "y": 0.0, | ||
| 1065 | "z": 0, | ||
| 1066 | "cX": 1.0, | ||
| 1067 | "cY": 1.0, | ||
| 1068 | "kX": -0.6352831, | ||
| 1069 | "kY": 0.6352831, | ||
| 1070 | "fi": 40, | ||
| 1071 | "twE": 0, | ||
| 1072 | "tweenFrame": true, | ||
| 1073 | "color": { | ||
| 1074 | "a": 255, | ||
| 1075 | "r": 255, | ||
| 1076 | "g": 255, | ||
| 1077 | "b": 255 | ||
| 1078 | }, | ||
| 1079 | "bd_src": 1, | ||
| 1080 | "bd_dst": 771 | ||
| 1081 | } | ||
| 1082 | ] | ||
| 1083 | } | ||
| 1084 | ] | ||
| 1085 | }, | ||
| 1086 | { | ||
| 1087 | "name": "stand", | ||
| 1088 | "dr": 41, | ||
| 1089 | "lp": true, | ||
| 1090 | "to": 0, | ||
| 1091 | "drTW": 0, | ||
| 1092 | "twE": 0, | ||
| 1093 | "sc": 1.0, | ||
| 1094 | "mov_bone_data": [ | ||
| 1095 | { | ||
| 1096 | "name": "Layer19", | ||
| 1097 | "dl": 0.0, | ||
| 1098 | "frame_data": [ | ||
| 1099 | { | ||
| 1100 | "dI": 0, | ||
| 1101 | "x": 0.0, | ||
| 1102 | "y": 0.0, | ||
| 1103 | "z": 0, | ||
| 1104 | "cX": 1.0, | ||
| 1105 | "cY": 1.0, | ||
| 1106 | "kX": 0.0, | ||
| 1107 | "kY": 0.0, | ||
| 1108 | "fi": 0, | ||
| 1109 | "twE": 0, | ||
| 1110 | "tweenFrame": true, | ||
| 1111 | "bd_src": 1, | ||
| 1112 | "bd_dst": 771 | ||
| 1113 | }, | ||
| 1114 | { | ||
| 1115 | "dI": 0, | ||
| 1116 | "x": 0.0, | ||
| 1117 | "y": 0.0, | ||
| 1118 | "z": 0, | ||
| 1119 | "cX": 1.0, | ||
| 1120 | "cY": 1.0, | ||
| 1121 | "kX": 0.0, | ||
| 1122 | "kY": 0.0, | ||
| 1123 | "fi": 20, | ||
| 1124 | "twE": 0, | ||
| 1125 | "tweenFrame": true, | ||
| 1126 | "bd_src": 1, | ||
| 1127 | "bd_dst": 771 | ||
| 1128 | }, | ||
| 1129 | { | ||
| 1130 | "dI": 0, | ||
| 1131 | "x": 0.0, | ||
| 1132 | "y": 0.0, | ||
| 1133 | "z": 0, | ||
| 1134 | "cX": 1.0, | ||
| 1135 | "cY": 1.0, | ||
| 1136 | "kX": 0.0, | ||
| 1137 | "kY": 0.0, | ||
| 1138 | "fi": 40, | ||
| 1139 | "twE": 0, | ||
| 1140 | "tweenFrame": true, | ||
| 1141 | "bd_src": 1, | ||
| 1142 | "bd_dst": 771 | ||
| 1143 | } | ||
| 1144 | ] | ||
| 1145 | }, | ||
| 1146 | { | ||
| 1147 | "name": "Layer14", | ||
| 1148 | "dl": 0.0, | ||
| 1149 | "frame_data": [ | ||
| 1150 | { | ||
| 1151 | "dI": 0, | ||
| 1152 | "x": 0.0, | ||
| 1153 | "y": 0.0, | ||
| 1154 | "z": 0, | ||
| 1155 | "cX": 1.0, | ||
| 1156 | "cY": 1.0, | ||
| 1157 | "kX": 0.0, | ||
| 1158 | "kY": 0.0, | ||
| 1159 | "fi": 0, | ||
| 1160 | "twE": 0, | ||
| 1161 | "tweenFrame": true, | ||
| 1162 | "bd_src": 1, | ||
| 1163 | "bd_dst": 771 | ||
| 1164 | }, | ||
| 1165 | { | ||
| 1166 | "dI": 0, | ||
| 1167 | "x": 0.0, | ||
| 1168 | "y": 0.0, | ||
| 1169 | "z": 0, | ||
| 1170 | "cX": 1.0, | ||
| 1171 | "cY": 1.0, | ||
| 1172 | "kX": 0.0545352064, | ||
| 1173 | "kY": -0.0545352064, | ||
| 1174 | "fi": 20, | ||
| 1175 | "twE": 0, | ||
| 1176 | "tweenFrame": true, | ||
| 1177 | "bd_src": 1, | ||
| 1178 | "bd_dst": 771 | ||
| 1179 | }, | ||
| 1180 | { | ||
| 1181 | "dI": 0, | ||
| 1182 | "x": 0.0, | ||
| 1183 | "y": 0.0, | ||
| 1184 | "z": 0, | ||
| 1185 | "cX": 1.0, | ||
| 1186 | "cY": 1.0, | ||
| 1187 | "kX": 0.0, | ||
| 1188 | "kY": 0.0, | ||
| 1189 | "fi": 40, | ||
| 1190 | "twE": 0, | ||
| 1191 | "tweenFrame": true, | ||
| 1192 | "bd_src": 1, | ||
| 1193 | "bd_dst": 771 | ||
| 1194 | } | ||
| 1195 | ] | ||
| 1196 | }, | ||
| 1197 | { | ||
| 1198 | "name": "Layer27", | ||
| 1199 | "dl": 0.0, | ||
| 1200 | "frame_data": [ | ||
| 1201 | { | ||
| 1202 | "dI": 0, | ||
| 1203 | "x": 0.0, | ||
| 1204 | "y": 0.0, | ||
| 1205 | "z": 0, | ||
| 1206 | "cX": 1.0, | ||
| 1207 | "cY": 1.0, | ||
| 1208 | "kX": 0.0, | ||
| 1209 | "kY": 0.0, | ||
| 1210 | "fi": 0, | ||
| 1211 | "twE": 0, | ||
| 1212 | "tweenFrame": true, | ||
| 1213 | "color": { | ||
| 1214 | "a": 255, | ||
| 1215 | "r": 255, | ||
| 1216 | "g": 255, | ||
| 1217 | "b": 255 | ||
| 1218 | }, | ||
| 1219 | "bd_src": 1, | ||
| 1220 | "bd_dst": 771 | ||
| 1221 | }, | ||
| 1222 | { | ||
| 1223 | "dI": 0, | ||
| 1224 | "x": 0.0, | ||
| 1225 | "y": 0.0, | ||
| 1226 | "z": 0, | ||
| 1227 | "cX": 1.0, | ||
| 1228 | "cY": 1.0, | ||
| 1229 | "kX": 0.0, | ||
| 1230 | "kY": 0.0, | ||
| 1231 | "fi": 20, | ||
| 1232 | "twE": 0, | ||
| 1233 | "tweenFrame": true, | ||
| 1234 | "color": { | ||
| 1235 | "a": 255, | ||
| 1236 | "r": 255, | ||
| 1237 | "g": 255, | ||
| 1238 | "b": 255 | ||
| 1239 | }, | ||
| 1240 | "bd_src": 1, | ||
| 1241 | "bd_dst": 771 | ||
| 1242 | }, | ||
| 1243 | { | ||
| 1244 | "dI": 0, | ||
| 1245 | "x": 0.0, | ||
| 1246 | "y": 0.0, | ||
| 1247 | "z": 0, | ||
| 1248 | "cX": 1.0, | ||
| 1249 | "cY": 1.0, | ||
| 1250 | "kX": 0.0, | ||
| 1251 | "kY": 0.0, | ||
| 1252 | "fi": 40, | ||
| 1253 | "twE": 0, | ||
| 1254 | "tweenFrame": true, | ||
| 1255 | "color": { | ||
| 1256 | "a": 255, | ||
| 1257 | "r": 255, | ||
| 1258 | "g": 255, | ||
| 1259 | "b": 255 | ||
| 1260 | }, | ||
| 1261 | "bd_src": 1, | ||
| 1262 | "bd_dst": 771 | ||
| 1263 | } | ||
| 1264 | ] | ||
| 1265 | }, | ||
| 1266 | { | ||
| 1267 | "name": "Layer26", | ||
| 1268 | "dl": 0.0, | ||
| 1269 | "frame_data": [ | ||
| 1270 | { | ||
| 1271 | "dI": 0, | ||
| 1272 | "x": 0.0, | ||
| 1273 | "y": 0.0, | ||
| 1274 | "z": 0, | ||
| 1275 | "cX": 1.0, | ||
| 1276 | "cY": 1.0, | ||
| 1277 | "kX": 0.0, | ||
| 1278 | "kY": 0.0, | ||
| 1279 | "fi": 0, | ||
| 1280 | "twE": 0, | ||
| 1281 | "tweenFrame": true, | ||
| 1282 | "color": { | ||
| 1283 | "a": 255, | ||
| 1284 | "r": 255, | ||
| 1285 | "g": 255, | ||
| 1286 | "b": 255 | ||
| 1287 | }, | ||
| 1288 | "bd_src": 1, | ||
| 1289 | "bd_dst": 771 | ||
| 1290 | }, | ||
| 1291 | { | ||
| 1292 | "dI": 0, | ||
| 1293 | "x": 0.0, | ||
| 1294 | "y": 0.0, | ||
| 1295 | "z": 0, | ||
| 1296 | "cX": 1.0, | ||
| 1297 | "cY": 1.0, | ||
| 1298 | "kX": 0.0, | ||
| 1299 | "kY": 0.0, | ||
| 1300 | "fi": 20, | ||
| 1301 | "twE": 0, | ||
| 1302 | "tweenFrame": true, | ||
| 1303 | "color": { | ||
| 1304 | "a": 255, | ||
| 1305 | "r": 255, | ||
| 1306 | "g": 255, | ||
| 1307 | "b": 255 | ||
| 1308 | }, | ||
| 1309 | "bd_src": 1, | ||
| 1310 | "bd_dst": 771 | ||
| 1311 | }, | ||
| 1312 | { | ||
| 1313 | "dI": 0, | ||
| 1314 | "x": 0.0, | ||
| 1315 | "y": 0.0, | ||
| 1316 | "z": 0, | ||
| 1317 | "cX": 1.0, | ||
| 1318 | "cY": 1.0, | ||
| 1319 | "kX": 0.0, | ||
| 1320 | "kY": 0.0, | ||
| 1321 | "fi": 40, | ||
| 1322 | "twE": 0, | ||
| 1323 | "tweenFrame": true, | ||
| 1324 | "color": { | ||
| 1325 | "a": 255, | ||
| 1326 | "r": 255, | ||
| 1327 | "g": 255, | ||
| 1328 | "b": 255 | ||
| 1329 | }, | ||
| 1330 | "bd_src": 1, | ||
| 1331 | "bd_dst": 771 | ||
| 1332 | } | ||
| 1333 | ] | ||
| 1334 | }, | ||
| 1335 | { | ||
| 1336 | "name": "Layer15", | ||
| 1337 | "dl": 0.0, | ||
| 1338 | "frame_data": [ | ||
| 1339 | { | ||
| 1340 | "dI": 0, | ||
| 1341 | "x": 0.0, | ||
| 1342 | "y": 0.0, | ||
| 1343 | "z": 0, | ||
| 1344 | "cX": 1.0, | ||
| 1345 | "cY": 1.0, | ||
| 1346 | "kX": 0.0, | ||
| 1347 | "kY": 0.0, | ||
| 1348 | "fi": 0, | ||
| 1349 | "twE": 0, | ||
| 1350 | "tweenFrame": true, | ||
| 1351 | "color": { | ||
| 1352 | "a": 255, | ||
| 1353 | "r": 255, | ||
| 1354 | "g": 255, | ||
| 1355 | "b": 255 | ||
| 1356 | }, | ||
| 1357 | "bd_src": 1, | ||
| 1358 | "bd_dst": 771 | ||
| 1359 | }, | ||
| 1360 | { | ||
| 1361 | "dI": 0, | ||
| 1362 | "x": 0.0, | ||
| 1363 | "y": 0.0, | ||
| 1364 | "z": 0, | ||
| 1365 | "cX": 1.0, | ||
| 1366 | "cY": 1.0, | ||
| 1367 | "kX": 0.0, | ||
| 1368 | "kY": 0.0, | ||
| 1369 | "fi": 20, | ||
| 1370 | "twE": 0, | ||
| 1371 | "tweenFrame": true, | ||
| 1372 | "bd_src": 1, | ||
| 1373 | "bd_dst": 771 | ||
| 1374 | }, | ||
| 1375 | { | ||
| 1376 | "dI": 0, | ||
| 1377 | "x": 0.0, | ||
| 1378 | "y": 0.0, | ||
| 1379 | "z": 0, | ||
| 1380 | "cX": 1.0, | ||
| 1381 | "cY": 1.0, | ||
| 1382 | "kX": 0.0, | ||
| 1383 | "kY": 0.0, | ||
| 1384 | "fi": 40, | ||
| 1385 | "twE": 0, | ||
| 1386 | "tweenFrame": true, | ||
| 1387 | "bd_src": 1, | ||
| 1388 | "bd_dst": 771 | ||
| 1389 | } | ||
| 1390 | ] | ||
| 1391 | }, | ||
| 1392 | { | ||
| 1393 | "name": "Layer17", | ||
| 1394 | "dl": 0.0, | ||
| 1395 | "frame_data": [ | ||
| 1396 | { | ||
| 1397 | "dI": 0, | ||
| 1398 | "x": 0.0, | ||
| 1399 | "y": 0.0, | ||
| 1400 | "z": 0, | ||
| 1401 | "cX": 1.0, | ||
| 1402 | "cY": 1.0, | ||
| 1403 | "kX": 0.0, | ||
| 1404 | "kY": 0.0, | ||
| 1405 | "fi": 0, | ||
| 1406 | "twE": 0, | ||
| 1407 | "tweenFrame": true, | ||
| 1408 | "bd_src": 1, | ||
| 1409 | "bd_dst": 771 | ||
| 1410 | }, | ||
| 1411 | { | ||
| 1412 | "dI": 0, | ||
| 1413 | "x": 0.0, | ||
| 1414 | "y": 0.0, | ||
| 1415 | "z": 0, | ||
| 1416 | "cX": 1.0, | ||
| 1417 | "cY": 1.0, | ||
| 1418 | "kX": -0.1839589, | ||
| 1419 | "kY": 0.1839589, | ||
| 1420 | "fi": 20, | ||
| 1421 | "twE": 0, | ||
| 1422 | "tweenFrame": true, | ||
| 1423 | "bd_src": 1, | ||
| 1424 | "bd_dst": 771 | ||
| 1425 | }, | ||
| 1426 | { | ||
| 1427 | "dI": 0, | ||
| 1428 | "x": 0.0, | ||
| 1429 | "y": 0.0, | ||
| 1430 | "z": 0, | ||
| 1431 | "cX": 1.0, | ||
| 1432 | "cY": 1.0, | ||
| 1433 | "kX": 0.0, | ||
| 1434 | "kY": 0.0, | ||
| 1435 | "fi": 40, | ||
| 1436 | "twE": 0, | ||
| 1437 | "tweenFrame": true, | ||
| 1438 | "bd_src": 1, | ||
| 1439 | "bd_dst": 771 | ||
| 1440 | } | ||
| 1441 | ] | ||
| 1442 | }, | ||
| 1443 | { | ||
| 1444 | "name": "Layer16", | ||
| 1445 | "dl": 0.0, | ||
| 1446 | "frame_data": [ | ||
| 1447 | { | ||
| 1448 | "dI": 0, | ||
| 1449 | "x": 0.0, | ||
| 1450 | "y": 0.0, | ||
| 1451 | "z": 0, | ||
| 1452 | "cX": 1.0, | ||
| 1453 | "cY": 1.0, | ||
| 1454 | "kX": 0.0, | ||
| 1455 | "kY": 0.0, | ||
| 1456 | "fi": 0, | ||
| 1457 | "twE": 0, | ||
| 1458 | "tweenFrame": true, | ||
| 1459 | "bd_src": 1, | ||
| 1460 | "bd_dst": 771 | ||
| 1461 | }, | ||
| 1462 | { | ||
| 1463 | "dI": 0, | ||
| 1464 | "x": 0.0, | ||
| 1465 | "y": 0.0, | ||
| 1466 | "z": 0, | ||
| 1467 | "cX": 1.0, | ||
| 1468 | "cY": 1.0, | ||
| 1469 | "kX": 0.08077191, | ||
| 1470 | "kY": -0.08077191, | ||
| 1471 | "fi": 20, | ||
| 1472 | "twE": 0, | ||
| 1473 | "tweenFrame": true, | ||
| 1474 | "bd_src": 1, | ||
| 1475 | "bd_dst": 771 | ||
| 1476 | }, | ||
| 1477 | { | ||
| 1478 | "dI": 0, | ||
| 1479 | "x": 0.0, | ||
| 1480 | "y": 0.0, | ||
| 1481 | "z": 0, | ||
| 1482 | "cX": 1.0, | ||
| 1483 | "cY": 1.0, | ||
| 1484 | "kX": 0.0, | ||
| 1485 | "kY": 0.0, | ||
| 1486 | "fi": 40, | ||
| 1487 | "twE": 0, | ||
| 1488 | "tweenFrame": true, | ||
| 1489 | "bd_src": 1, | ||
| 1490 | "bd_dst": 771 | ||
| 1491 | } | ||
| 1492 | ] | ||
| 1493 | }, | ||
| 1494 | { | ||
| 1495 | "name": "Layer20", | ||
| 1496 | "dl": 0.0, | ||
| 1497 | "frame_data": [ | ||
| 1498 | { | ||
| 1499 | "dI": 0, | ||
| 1500 | "x": 0.0, | ||
| 1501 | "y": 0.0, | ||
| 1502 | "z": 0, | ||
| 1503 | "cX": 1.0, | ||
| 1504 | "cY": 1.0, | ||
| 1505 | "kX": 0.0, | ||
| 1506 | "kY": 0.0, | ||
| 1507 | "fi": 0, | ||
| 1508 | "twE": 0, | ||
| 1509 | "tweenFrame": true, | ||
| 1510 | "bd_src": 1, | ||
| 1511 | "bd_dst": 771 | ||
| 1512 | }, | ||
| 1513 | { | ||
| 1514 | "dI": 0, | ||
| 1515 | "x": 0.0, | ||
| 1516 | "y": 0.0, | ||
| 1517 | "z": 0, | ||
| 1518 | "cX": 1.0, | ||
| 1519 | "cY": 1.0, | ||
| 1520 | "kX": 0.0, | ||
| 1521 | "kY": 0.0, | ||
| 1522 | "fi": 40, | ||
| 1523 | "twE": 0, | ||
| 1524 | "tweenFrame": true, | ||
| 1525 | "bd_src": 1, | ||
| 1526 | "bd_dst": 771 | ||
| 1527 | } | ||
| 1528 | ] | ||
| 1529 | }, | ||
| 1530 | { | ||
| 1531 | "name": "Layer21", | ||
| 1532 | "dl": 0.0, | ||
| 1533 | "frame_data": [ | ||
| 1534 | { | ||
| 1535 | "dI": 0, | ||
| 1536 | "x": 0.0, | ||
| 1537 | "y": 0.0, | ||
| 1538 | "z": 0, | ||
| 1539 | "cX": 1.0, | ||
| 1540 | "cY": 1.0, | ||
| 1541 | "kX": 0.0, | ||
| 1542 | "kY": 0.0, | ||
| 1543 | "fi": 0, | ||
| 1544 | "twE": 0, | ||
| 1545 | "tweenFrame": true, | ||
| 1546 | "bd_src": 1, | ||
| 1547 | "bd_dst": 771 | ||
| 1548 | }, | ||
| 1549 | { | ||
| 1550 | "dI": 0, | ||
| 1551 | "x": 0.0, | ||
| 1552 | "y": 0.0, | ||
| 1553 | "z": 0, | ||
| 1554 | "cX": 1.0, | ||
| 1555 | "cY": 1.0, | ||
| 1556 | "kX": 0.0, | ||
| 1557 | "kY": 0.0, | ||
| 1558 | "fi": 40, | ||
| 1559 | "twE": 0, | ||
| 1560 | "tweenFrame": true, | ||
| 1561 | "bd_src": 1, | ||
| 1562 | "bd_dst": 771 | ||
| 1563 | } | ||
| 1564 | ] | ||
| 1565 | } | ||
| 1566 | ] | ||
| 1567 | } | ||
| 1568 | ] | ||
| 1569 | } | ||
| 1570 | ], | ||
| 1571 | "texture_data": [ | ||
| 1572 | { | ||
| 1573 | "name": "defaultarmature1", | ||
| 1574 | "width": 201.0, | ||
| 1575 | "height": 320.0, | ||
| 1576 | "pX": 0.149253726, | ||
| 1577 | "pY": 0.921875, | ||
| 1578 | "plistFile": "" | ||
| 1579 | }, | ||
| 1580 | { | ||
| 1581 | "name": "defaultarmature2", | ||
| 1582 | "width": 186.0, | ||
| 1583 | "height": 252.0, | ||
| 1584 | "pX": 0.338709682, | ||
| 1585 | "pY": 0.81349206, | ||
| 1586 | "plistFile": "" | ||
| 1587 | }, | ||
| 1588 | { | ||
| 1589 | "name": "defaultarmature3", | ||
| 1590 | "width": 247.0, | ||
| 1591 | "height": 479.0, | ||
| 1592 | "pX": 0.5951417, | ||
| 1593 | "pY": 0.08768267, | ||
| 1594 | "plistFile": "" | ||
| 1595 | }, | ||
| 1596 | { | ||
| 1597 | "name": "defaultarmature4", | ||
| 1598 | "width": 141.0, | ||
| 1599 | "height": 110.0, | ||
| 1600 | "pX": 0.737588644, | ||
| 1601 | "pY": 0.8818182, | ||
| 1602 | "plistFile": "" | ||
| 1603 | }, | ||
| 1604 | { | ||
| 1605 | "name": "defaultarmature5", | ||
| 1606 | "width": 190.0, | ||
| 1607 | "height": 236.0, | ||
| 1608 | "pX": 0.757894754, | ||
| 1609 | "pY": 0.8305085, | ||
| 1610 | "plistFile": "" | ||
| 1611 | }, | ||
| 1612 | { | ||
| 1613 | "name": "defaultarmature6", | ||
| 1614 | "width": 474.0, | ||
| 1615 | "height": 402.0, | ||
| 1616 | "pX": 0.327004224, | ||
| 1617 | "pY": 0.383084565, | ||
| 1618 | "plistFile": "", | ||
| 1619 | "contour_data": [ | ||
| 1620 | { | ||
| 1621 | "vertex": [ | ||
| 1622 | { | ||
| 1623 | "x": 161.0, | ||
| 1624 | "y": 266.0 | ||
| 1625 | }, | ||
| 1626 | { | ||
| 1627 | "x": 161.0, | ||
| 1628 | "y": -249.0 | ||
| 1629 | }, | ||
| 1630 | { | ||
| 1631 | "x": -147.0, | ||
| 1632 | "y": -249.0 | ||
| 1633 | }, | ||
| 1634 | { | ||
| 1635 | "x": -147.0, | ||
| 1636 | "y": 266.0 | ||
| 1637 | } | ||
| 1638 | ] | ||
| 1639 | } | ||
| 1640 | ] | ||
| 1641 | }, | ||
| 1642 | { | ||
| 1643 | "name": "defaultarmature7", | ||
| 1644 | "width": 146.0, | ||
| 1645 | "height": 112.0, | ||
| 1646 | "pX": 0.4520548, | ||
| 1647 | "pY": 0.9285714, | ||
| 1648 | "plistFile": "" | ||
| 1649 | }, | ||
| 1650 | { | ||
| 1651 | "name": "defaultarmature8", | ||
| 1652 | "width": 135.0, | ||
| 1653 | "height": 180.0, | ||
| 1654 | "pX": 0.8518519, | ||
| 1655 | "pY": 0.9166667, | ||
| 1656 | "plistFile": "" | ||
| 1657 | }, | ||
| 1658 | { | ||
| 1659 | "name": "defaultarmaturehat", | ||
| 1660 | "width": 452.0, | ||
| 1661 | "height": 458.0, | ||
| 1662 | "pX": 0.6681416, | ||
| 1663 | "pY": 0.04366812, | ||
| 1664 | "plistFile": "" | ||
| 1665 | } | ||
| 1666 | ], | ||
| 1667 | "config_file_path": [ | ||
| 1668 | "DemoPlayer0.plist" | ||
| 1669 | ], | ||
| 1670 | "config_png_path": [ | ||
| 1671 | "DemoPlayer0.png" | ||
| 1672 | ] | ||
| 1673 | } | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | <?xml version="1.0" encoding="utf-8"?> | ||
| 2 | <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| 3 | <plist version="1.0"> | ||
| 4 | <dict> | ||
| 5 | <key>frames</key> | ||
| 6 | <dict> | ||
| 7 | <key>defaultarmature1.png</key> | ||
| 8 | <dict> | ||
| 9 | <key>width</key> | ||
| 10 | <integer>20</integer> | ||
| 11 | <key>height</key> | ||
| 12 | <integer>32</integer> | ||
| 13 | <key>originalWidth</key> | ||
| 14 | <integer>20</integer> | ||
| 15 | <key>originalHeight</key> | ||
| 16 | <integer>32</integer> | ||
| 17 | <key>x</key> | ||
| 18 | <integer>0</integer> | ||
| 19 | <key>y</key> | ||
| 20 | <integer>0</integer> | ||
| 21 | <key>offsetX</key> | ||
| 22 | <real>0</real> | ||
| 23 | <key>offsetY</key> | ||
| 24 | <real>0</real> | ||
| 25 | </dict> | ||
| 26 | <key>defaultarmaturehat.png</key> | ||
| 27 | <dict> | ||
| 28 | <key>width</key> | ||
| 29 | <integer>45</integer> | ||
| 30 | <key>height</key> | ||
| 31 | <integer>45</integer> | ||
| 32 | <key>originalWidth</key> | ||
| 33 | <integer>45</integer> | ||
| 34 | <key>originalHeight</key> | ||
| 35 | <integer>45</integer> | ||
| 36 | <key>x</key> | ||
| 37 | <integer>22</integer> | ||
| 38 | <key>y</key> | ||
| 39 | <integer>0</integer> | ||
| 40 | <key>offsetX</key> | ||
| 41 | <real>0</real> | ||
| 42 | <key>offsetY</key> | ||
| 43 | <real>0</real> | ||
| 44 | </dict> | ||
| 45 | <key>defaultarmature7.png</key> | ||
| 46 | <dict> | ||
| 47 | <key>width</key> | ||
| 48 | <integer>14</integer> | ||
| 49 | <key>height</key> | ||
| 50 | <integer>11</integer> | ||
| 51 | <key>originalWidth</key> | ||
| 52 | <integer>14</integer> | ||
| 53 | <key>originalHeight</key> | ||
| 54 | <integer>11</integer> | ||
| 55 | <key>x</key> | ||
| 56 | <integer>69</integer> | ||
| 57 | <key>y</key> | ||
| 58 | <integer>0</integer> | ||
| 59 | <key>offsetX</key> | ||
| 60 | <real>0</real> | ||
| 61 | <key>offsetY</key> | ||
| 62 | <real>0</real> | ||
| 63 | </dict> | ||
| 64 | <key>defaultarmature2.png</key> | ||
| 65 | <dict> | ||
| 66 | <key>width</key> | ||
| 67 | <integer>18</integer> | ||
| 68 | <key>height</key> | ||
| 69 | <integer>25</integer> | ||
| 70 | <key>originalWidth</key> | ||
| 71 | <integer>18</integer> | ||
| 72 | <key>originalHeight</key> | ||
| 73 | <integer>25</integer> | ||
| 74 | <key>x</key> | ||
| 75 | <integer>85</integer> | ||
| 76 | <key>y</key> | ||
| 77 | <integer>0</integer> | ||
| 78 | <key>offsetX</key> | ||
| 79 | <real>0</real> | ||
| 80 | <key>offsetY</key> | ||
| 81 | <real>0</real> | ||
| 82 | </dict> | ||
| 83 | <key>defaultarmature6.png</key> | ||
| 84 | <dict> | ||
| 85 | <key>width</key> | ||
| 86 | <integer>47</integer> | ||
| 87 | <key>height</key> | ||
| 88 | <integer>40</integer> | ||
| 89 | <key>originalWidth</key> | ||
| 90 | <integer>47</integer> | ||
| 91 | <key>originalHeight</key> | ||
| 92 | <integer>40</integer> | ||
| 93 | <key>x</key> | ||
| 94 | <integer>105</integer> | ||
| 95 | <key>y</key> | ||
| 96 | <integer>0</integer> | ||
| 97 | <key>offsetX</key> | ||
| 98 | <real>0</real> | ||
| 99 | <key>offsetY</key> | ||
| 100 | <real>0</real> | ||
| 101 | </dict> | ||
| 102 | <key>defaultarmature4.png</key> | ||
| 103 | <dict> | ||
| 104 | <key>width</key> | ||
| 105 | <integer>14</integer> | ||
| 106 | <key>height</key> | ||
| 107 | <integer>11</integer> | ||
| 108 | <key>originalWidth</key> | ||
| 109 | <integer>14</integer> | ||
| 110 | <key>originalHeight</key> | ||
| 111 | <integer>11</integer> | ||
| 112 | <key>x</key> | ||
| 113 | <integer>154</integer> | ||
| 114 | <key>y</key> | ||
| 115 | <integer>0</integer> | ||
| 116 | <key>offsetX</key> | ||
| 117 | <real>0</real> | ||
| 118 | <key>offsetY</key> | ||
| 119 | <real>0</real> | ||
| 120 | </dict> | ||
| 121 | <key>defaultarmature5.png</key> | ||
| 122 | <dict> | ||
| 123 | <key>width</key> | ||
| 124 | <integer>19</integer> | ||
| 125 | <key>height</key> | ||
| 126 | <integer>23</integer> | ||
| 127 | <key>originalWidth</key> | ||
| 128 | <integer>19</integer> | ||
| 129 | <key>originalHeight</key> | ||
| 130 | <integer>23</integer> | ||
| 131 | <key>x</key> | ||
| 132 | <integer>170</integer> | ||
| 133 | <key>y</key> | ||
| 134 | <integer>0</integer> | ||
| 135 | <key>offsetX</key> | ||
| 136 | <real>0</real> | ||
| 137 | <key>offsetY</key> | ||
| 138 | <real>0</real> | ||
| 139 | </dict> | ||
| 140 | <key>defaultarmature3.png</key> | ||
| 141 | <dict> | ||
| 142 | <key>width</key> | ||
| 143 | <integer>24</integer> | ||
| 144 | <key>height</key> | ||
| 145 | <integer>47</integer> | ||
| 146 | <key>originalWidth</key> | ||
| 147 | <integer>24</integer> | ||
| 148 | <key>originalHeight</key> | ||
| 149 | <integer>47</integer> | ||
| 150 | <key>x</key> | ||
| 151 | <integer>191</integer> | ||
| 152 | <key>y</key> | ||
| 153 | <integer>0</integer> | ||
| 154 | <key>offsetX</key> | ||
| 155 | <real>0</real> | ||
| 156 | <key>offsetY</key> | ||
| 157 | <real>0</real> | ||
| 158 | </dict> | ||
| 159 | <key>defaultarmature8.png</key> | ||
| 160 | <dict> | ||
| 161 | <key>width</key> | ||
| 162 | <integer>13</integer> | ||
| 163 | <key>height</key> | ||
| 164 | <integer>18</integer> | ||
| 165 | <key>originalWidth</key> | ||
| 166 | <integer>13</integer> | ||
| 167 | <key>originalHeight</key> | ||
| 168 | <integer>18</integer> | ||
| 169 | <key>x</key> | ||
| 170 | <integer>217</integer> | ||
| 171 | <key>y</key> | ||
| 172 | <integer>0</integer> | ||
| 173 | <key>offsetX</key> | ||
| 174 | <real>0</real> | ||
| 175 | <key>offsetY</key> | ||
| 176 | <real>0</real> | ||
| 177 | </dict> | ||
| 178 | </dict> | ||
| 179 | <key>metadata</key> | ||
| 180 | <dict> | ||
| 181 | <key>format</key> | ||
| 182 | <integer>0</integer> | ||
| 183 | <key>textureFileName</key> | ||
| 184 | <string>DemoPlayer0.png</string> | ||
| 185 | <key>realTextureFileName</key> | ||
| 186 | <string>DemoPlayer0.png</string> | ||
| 187 | <key>size</key> | ||
| 188 | <string>{1024,1024}</string> | ||
| 189 | </dict> | ||
| 190 | <key>texture</key> | ||
| 191 | <dict> | ||
| 192 | <key>width</key> | ||
| 193 | <integer>1024</integer> | ||
| 194 | <key>height</key> | ||
| 195 | <integer>1024</integer> | ||
| 196 | </dict> | ||
| 197 | </dict> | ||
| 198 | </plist> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
13 KB
client/rubbish/client/res/Default/Sprite.png
0 → 100644
1.73 KB
12.9 KB
38.1 KB
31 KB
3.22 KB
6.67 KB
6.72 KB
3.44 KB
6.35 KB
8.52 KB
2.45 KB
6.71 KB
6.69 KB
6.69 KB
2.45 KB
9.61 KB
2.09 KB
2.38 KB
client/rubbish/client/res/ui/AlertLayer.csb
0 → 100644
No preview for this file type
No preview for this file type
| 1 | info face="ź" size=-72 bold=1 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=1,1,1,1 spacing=1,1 outline=0 | ||
| 2 | common lineHeight=96 base=76 scaleW=256 scaleH=512 pages=1 packed=0 alphaChnl=0 redChnl=4 greenChnl=4 blueChnl=4 | ||
| 3 | page id=0 file="num_cake_green_0.png" | ||
| 4 | chars count=11 | ||
| 5 | char id=43 x=93 y=336 width=78 height=70 xoffset=-1 yoffset=-1 xadvance=76 page=0 chnl=15 | ||
| 6 | char id=48 x=101 y=84 width=98 height=83 xoffset=-1 yoffset=-1 xadvance=96 page=0 chnl=15 | ||
| 7 | char id=49 x=202 y=0 width=52 height=83 xoffset=-1 yoffset=-1 xadvance=50 page=0 chnl=15 | ||
| 8 | char id=50 x=0 y=336 width=92 height=83 xoffset=-1 yoffset=-1 xadvance=90 page=0 chnl=15 | ||
| 9 | char id=51 x=0 y=168 width=96 height=83 xoffset=-1 yoffset=-1 xadvance=94 page=0 chnl=15 | ||
| 10 | char id=52 x=97 y=168 width=96 height=83 xoffset=-1 yoffset=-1 xadvance=94 page=0 chnl=15 | ||
| 11 | char id=53 x=0 y=252 width=96 height=83 xoffset=-1 yoffset=-1 xadvance=94 page=0 chnl=15 | ||
| 12 | char id=54 x=97 y=252 width=96 height=83 xoffset=-1 yoffset=-1 xadvance=94 page=0 chnl=15 | ||
| 13 | char id=55 x=0 y=0 width=100 height=83 xoffset=-1 yoffset=-1 xadvance=98 page=0 chnl=15 | ||
| 14 | char id=56 x=101 y=0 width=100 height=83 xoffset=-1 yoffset=-1 xadvance=98 page=0 chnl=15 | ||
| 15 | char id=57 x=0 y=84 width=100 height=83 xoffset=-1 yoffset=-1 xadvance=98 page=0 chnl=15 |
26.9 KB
| 1 | info face="ź" size=-72 bold=1 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=1,1,1,1 spacing=1,1 outline=0 | ||
| 2 | common lineHeight=96 base=76 scaleW=128 scaleH=256 pages=1 packed=0 alphaChnl=0 redChnl=4 greenChnl=4 blueChnl=4 | ||
| 3 | page id=0 file="num_clock_0.png" | ||
| 4 | chars count=10 | ||
| 5 | char id=48 x=0 y=0 width=43 height=54 xoffset=-1 yoffset=-1 xadvance=41 page=0 chnl=15 | ||
| 6 | char id=49 x=0 y=165 width=27 height=54 xoffset=-1 yoffset=-1 xadvance=25 page=0 chnl=15 | ||
| 7 | char id=50 x=88 y=0 width=39 height=54 xoffset=-1 yoffset=-1 xadvance=37 page=0 chnl=15 | ||
| 8 | char id=51 x=42 y=55 width=40 height=54 xoffset=-1 yoffset=-1 xadvance=38 page=0 chnl=15 | ||
| 9 | char id=52 x=44 y=0 width=43 height=54 xoffset=-1 yoffset=-1 xadvance=41 page=0 chnl=15 | ||
| 10 | char id=53 x=82 y=110 width=39 height=54 xoffset=-1 yoffset=-1 xadvance=37 page=0 chnl=15 | ||
| 11 | char id=54 x=83 y=55 width=40 height=54 xoffset=-1 yoffset=-1 xadvance=38 page=0 chnl=15 | ||
| 12 | char id=55 x=0 y=55 width=41 height=54 xoffset=-1 yoffset=-1 xadvance=39 page=0 chnl=15 | ||
| 13 | char id=56 x=0 y=110 width=40 height=54 xoffset=-1 yoffset=-1 xadvance=38 page=0 chnl=15 | ||
| 14 | char id=57 x=41 y=110 width=40 height=54 xoffset=-1 yoffset=-1 xadvance=38 page=0 chnl=15 |
11.6 KB
client/rubbish/client/res/ui/font/yahei.ttf
0 → 100644
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
client/rubbish/client/res/ui/rubbish/bg.png
0 → 100644
103 KB
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| 3 | <plist version="1.0"> | ||
| 4 | <dict> | ||
| 5 | <key>frames</key> | ||
| 6 | <dict> | ||
| 7 | <key>bg_best_show.png</key> | ||
| 8 | <dict> | ||
| 9 | <key>frame</key> | ||
| 10 | <string>{{270,2},{202,82}}</string> | ||
| 11 | <key>offset</key> | ||
| 12 | <string>{0,0}</string> | ||
| 13 | <key>rotated</key> | ||
| 14 | <false/> | ||
| 15 | <key>sourceColorRect</key> | ||
| 16 | <string>{{0,1},{202,82}}</string> | ||
| 17 | <key>sourceSize</key> | ||
| 18 | <string>{202,84}</string> | ||
| 19 | </dict> | ||
| 20 | <key>bg_fanpai_num.png</key> | ||
| 21 | <dict> | ||
| 22 | <key>frame</key> | ||
| 23 | <string>{{270,86},{198,54}}</string> | ||
| 24 | <key>offset</key> | ||
| 25 | <string>{-1,1}</string> | ||
| 26 | <key>rotated</key> | ||
| 27 | <false/> | ||
| 28 | <key>sourceColorRect</key> | ||
| 29 | <string>{{0,2},{198,54}}</string> | ||
| 30 | <key>sourceSize</key> | ||
| 31 | <string>{200,60}</string> | ||
| 32 | </dict> | ||
| 33 | <key>btn_guess_introduce.png</key> | ||
| 34 | <dict> | ||
| 35 | <key>frame</key> | ||
| 36 | <string>{{260,399},{93,90}}</string> | ||
| 37 | <key>offset</key> | ||
| 38 | <string>{0,1}</string> | ||
| 39 | <key>rotated</key> | ||
| 40 | <true/> | ||
| 41 | <key>sourceColorRect</key> | ||
| 42 | <string>{{2,1},{93,90}}</string> | ||
| 43 | <key>sourceSize</key> | ||
| 44 | <string>{97,94}</string> | ||
| 45 | </dict> | ||
| 46 | <key>btn_guess_next.png</key> | ||
| 47 | <dict> | ||
| 48 | <key>frame</key> | ||
| 49 | <string>{{2,2},{266,91}}</string> | ||
| 50 | <key>offset</key> | ||
| 51 | <string>{0,0}</string> | ||
| 52 | <key>rotated</key> | ||
| 53 | <false/> | ||
| 54 | <key>sourceColorRect</key> | ||
| 55 | <string>{{0,0},{266,91}}</string> | ||
| 56 | <key>sourceSize</key> | ||
| 57 | <string>{266,91}</string> | ||
| 58 | </dict> | ||
| 59 | <key>candy_1.png</key> | ||
| 60 | <dict> | ||
| 61 | <key>frame</key> | ||
| 62 | <string>{{96,294},{107,106}}</string> | ||
| 63 | <key>offset</key> | ||
| 64 | <string>{0,0}</string> | ||
| 65 | <key>rotated</key> | ||
| 66 | <true/> | ||
| 67 | <key>sourceColorRect</key> | ||
| 68 | <string>{{0,0},{107,106}}</string> | ||
| 69 | <key>sourceSize</key> | ||
| 70 | <string>{107,106}</string> | ||
| 71 | </dict> | ||
| 72 | <key>candy_1001.png</key> | ||
| 73 | <dict> | ||
| 74 | <key>frame</key> | ||
| 75 | <string>{{265,142},{42,60}}</string> | ||
| 76 | <key>offset</key> | ||
| 77 | <string>{0,0}</string> | ||
| 78 | <key>rotated</key> | ||
| 79 | <false/> | ||
| 80 | <key>sourceColorRect</key> | ||
| 81 | <string>{{0,0},{42,60}}</string> | ||
| 82 | <key>sourceSize</key> | ||
| 83 | <string>{42,60}</string> | ||
| 84 | </dict> | ||
| 85 | <key>candy_1002.png</key> | ||
| 86 | <dict> | ||
| 87 | <key>frame</key> | ||
| 88 | <string>{{2,427},{72,78}}</string> | ||
| 89 | <key>offset</key> | ||
| 90 | <string>{0,0}</string> | ||
| 91 | <key>rotated</key> | ||
| 92 | <false/> | ||
| 93 | <key>sourceColorRect</key> | ||
| 94 | <string>{{0,0},{72,78}}</string> | ||
| 95 | <key>sourceSize</key> | ||
| 96 | <string>{72,78}</string> | ||
| 97 | </dict> | ||
| 98 | <key>candy_1003.png</key> | ||
| 99 | <dict> | ||
| 100 | <key>frame</key> | ||
| 101 | <string>{{76,427},{88,75}}</string> | ||
| 102 | <key>offset</key> | ||
| 103 | <string>{0,0}</string> | ||
| 104 | <key>rotated</key> | ||
| 105 | <false/> | ||
| 106 | <key>sourceColorRect</key> | ||
| 107 | <string>{{0,0},{88,75}}</string> | ||
| 108 | <key>sourceSize</key> | ||
| 109 | <string>{88,75}</string> | ||
| 110 | </dict> | ||
| 111 | <key>candy_1004.png</key> | ||
| 112 | <dict> | ||
| 113 | <key>frame</key> | ||
| 114 | <string>{{136,224},{93,67}}</string> | ||
| 115 | <key>offset</key> | ||
| 116 | <string>{0,0}</string> | ||
| 117 | <key>rotated</key> | ||
| 118 | <false/> | ||
| 119 | <key>sourceColorRect</key> | ||
| 120 | <string>{{0,0},{93,67}}</string> | ||
| 121 | <key>sourceSize</key> | ||
| 122 | <string>{93,67}</string> | ||
| 123 | </dict> | ||
| 124 | <key>candy_1005.png</key> | ||
| 125 | <dict> | ||
| 126 | <key>frame</key> | ||
| 127 | <string>{{231,224},{61,44}}</string> | ||
| 128 | <key>offset</key> | ||
| 129 | <string>{0,0}</string> | ||
| 130 | <key>rotated</key> | ||
| 131 | <true/> | ||
| 132 | <key>sourceColorRect</key> | ||
| 133 | <string>{{0,0},{61,44}}</string> | ||
| 134 | <key>sourceSize</key> | ||
| 135 | <string>{61,44}</string> | ||
| 136 | </dict> | ||
| 137 | <key>candy_2.png</key> | ||
| 138 | <dict> | ||
| 139 | <key>frame</key> | ||
| 140 | <string>{{166,403},{104,92}}</string> | ||
| 141 | <key>offset</key> | ||
| 142 | <string>{0,0}</string> | ||
| 143 | <key>rotated</key> | ||
| 144 | <true/> | ||
| 145 | <key>sourceColorRect</key> | ||
| 146 | <string>{{0,0},{104,92}}</string> | ||
| 147 | <key>sourceSize</key> | ||
| 148 | <string>{104,92}</string> | ||
| 149 | </dict> | ||
| 150 | <key>candy_2001.png</key> | ||
| 151 | <dict> | ||
| 152 | <key>frame</key> | ||
| 153 | <string>{{2,294},{131,92}}</string> | ||
| 154 | <key>offset</key> | ||
| 155 | <string>{0,0}</string> | ||
| 156 | <key>rotated</key> | ||
| 157 | <true/> | ||
| 158 | <key>sourceColorRect</key> | ||
| 159 | <string>{{0,0},{131,92}}</string> | ||
| 160 | <key>sourceSize</key> | ||
| 161 | <string>{131,92}</string> | ||
| 162 | </dict> | ||
| 163 | <key>candy_2002.png</key> | ||
| 164 | <dict> | ||
| 165 | <key>frame</key> | ||
| 166 | <string>{{165,95},{98,127}}</string> | ||
| 167 | <key>offset</key> | ||
| 168 | <string>{0,0}</string> | ||
| 169 | <key>rotated</key> | ||
| 170 | <false/> | ||
| 171 | <key>sourceColorRect</key> | ||
| 172 | <string>{{0,0},{98,127}}</string> | ||
| 173 | <key>sourceSize</key> | ||
| 174 | <string>{98,127}</string> | ||
| 175 | </dict> | ||
| 176 | <key>candy_2003.png</key> | ||
| 177 | <dict> | ||
| 178 | <key>frame</key> | ||
| 179 | <string>{{2,198},{94,132}}</string> | ||
| 180 | <key>offset</key> | ||
| 181 | <string>{0,0}</string> | ||
| 182 | <key>rotated</key> | ||
| 183 | <true/> | ||
| 184 | <key>sourceColorRect</key> | ||
| 185 | <string>{{0,0},{94,132}}</string> | ||
| 186 | <key>sourceSize</key> | ||
| 187 | <string>{94,132}</string> | ||
| 188 | </dict> | ||
| 189 | <key>candy_3.png</key> | ||
| 190 | <dict> | ||
| 191 | <key>frame</key> | ||
| 192 | <string>{{204,293},{88,104}}</string> | ||
| 193 | <key>offset</key> | ||
| 194 | <string>{0,0}</string> | ||
| 195 | <key>rotated</key> | ||
| 196 | <false/> | ||
| 197 | <key>sourceColorRect</key> | ||
| 198 | <string>{{0,0},{88,104}}</string> | ||
| 199 | <key>sourceSize</key> | ||
| 200 | <string>{88,104}</string> | ||
| 201 | </dict> | ||
| 202 | <key>candy_3001.png</key> | ||
| 203 | <dict> | ||
| 204 | <key>frame</key> | ||
| 205 | <string>{{2,95},{161,101}}</string> | ||
| 206 | <key>offset</key> | ||
| 207 | <string>{0,0}</string> | ||
| 208 | <key>rotated</key> | ||
| 209 | <false/> | ||
| 210 | <key>sourceColorRect</key> | ||
| 211 | <string>{{0,0},{161,101}}</string> | ||
| 212 | <key>sourceSize</key> | ||
| 213 | <string>{161,101}</string> | ||
| 214 | </dict> | ||
| 215 | </dict> | ||
| 216 | <key>metadata</key> | ||
| 217 | <dict> | ||
| 218 | <key>format</key> | ||
| 219 | <integer>2</integer> | ||
| 220 | <key>realTextureFileName</key> | ||
| 221 | <string>candy_textures.png</string> | ||
| 222 | <key>size</key> | ||
| 223 | <string>{512,512}</string> | ||
| 224 | <key>smartupdate</key> | ||
| 225 | <string>$TexturePacker:SmartUpdate:fcc5e2e8bfcc5afc79643ea454503b13:1/1$</string> | ||
| 226 | <key>textureFileName</key> | ||
| 227 | <string>candy_textures.png</string> | ||
| 228 | </dict> | ||
| 229 | </dict> | ||
| 230 | </plist> |
38.9 KB
10.5 KB
client/rubbish/client/rubbish.config
0 → 100644
| 1 | <?xml version="1.0"?> | ||
| 2 | <Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | ||
| 3 | <propertyGroup> | ||
| 4 | <StartProgram>D:\xhx\client\runtime\win32\GuandanAndroid.exe</StartProgram> | ||
| 5 | <StartArguments>-workdir D:\xhx\client\rubbish\client</StartArguments> | ||
| 6 | <StartWorkingDirectory>D:\xhx\client\runtime\win32</StartWorkingDirectory> | ||
| 7 | </propertyGroup> | ||
| 8 | </Project> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -36,7 +36,7 @@ | ... | @@ -36,7 +36,7 @@ |
| 36 | <Folder Include="src\app\tools\pl\" /> | 36 | <Folder Include="src\app\tools\pl\" /> |
| 37 | <Folder Include="src\app\views\" /> | 37 | <Folder Include="src\app\views\" /> |
| 38 | <Folder Include="src\app\views\effect\" /> | 38 | <Folder Include="src\app\views\effect\" /> |
| 39 | <Folder Include="src\app\views\candy\" /> | 39 | <Folder Include="src\app\views\rubbish\" /> |
| 40 | <Folder Include="src\app\views\scene\" /> | 40 | <Folder Include="src\app\views\scene\" /> |
| 41 | <Folder Include="src\app\views\view\" /> | 41 | <Folder Include="src\app\views\view\" /> |
| 42 | <Folder Include="src\cocos\" /> | 42 | <Folder Include="src\cocos\" /> |
| ... | @@ -91,14 +91,14 @@ | ... | @@ -91,14 +91,14 @@ |
| 91 | <Compile Include="src\app\tools\pl\compat.lua" /> | 91 | <Compile Include="src\app\tools\pl\compat.lua" /> |
| 92 | <Compile Include="src\app\tools\pl\utils.lua" /> | 92 | <Compile Include="src\app\tools\pl\utils.lua" /> |
| 93 | <Compile Include="src\app\tools\pl\xml.lua" /> | 93 | <Compile Include="src\app\tools\pl\xml.lua" /> |
| 94 | <Compile Include="src\app\views\candy\Candy.lua" /> | 94 | <Compile Include="src\app\views\rubbish\Rubbish.lua" /> |
| 95 | <Compile Include="src\app\views\candy\GameFailView.lua" /> | 95 | <Compile Include="src\app\views\rubbish\GameFailView.lua" /> |
| 96 | <Compile Include="src\app\views\candy\GameNextView.lua" /> | 96 | <Compile Include="src\app\views\rubbish\GameNextView.lua" /> |
| 97 | <Compile Include="src\app\views\candy\GamePayConfirmView.lua" /> | 97 | <Compile Include="src\app\views\rubbish\GamePayConfirmView.lua" /> |
| 98 | <Compile Include="src\app\views\candy\GamePayView.lua" /> | 98 | <Compile Include="src\app\views\rubbish\GamePayView.lua" /> |
| 99 | <Compile Include="src\app\views\candy\game_data.lua" /> | 99 | <Compile Include="src\app\views\rubbish\game_data.lua" /> |
| 100 | <Compile Include="src\app\views\candy\GameOverView.lua" /> | 100 | <Compile Include="src\app\views\rubbish\GameOverView.lua" /> |
| 101 | <Compile Include="src\app\views\candy\GameStartView.lua" /> | 101 | <Compile Include="src\app\views\rubbish\GameStartView.lua" /> |
| 102 | <Compile Include="src\app\views\effect\EffectBoom.lua" /> | 102 | <Compile Include="src\app\views\effect\EffectBoom.lua" /> |
| 103 | <Compile Include="src\app\views\effect\EffectFntPop.lua" /> | 103 | <Compile Include="src\app\views\effect\EffectFntPop.lua" /> |
| 104 | <Compile Include="src\app\views\effect\EffectFruitLight.lua" /> | 104 | <Compile Include="src\app\views\effect\EffectFruitLight.lua" /> |
| ... | @@ -110,9 +110,9 @@ | ... | @@ -110,9 +110,9 @@ |
| 110 | <Compile Include="src\app\views\effect\EffectStright.lua" /> | 110 | <Compile Include="src\app\views\effect\EffectStright.lua" /> |
| 111 | <Compile Include="src\app\views\effect\EffectVoiceChat.lua" /> | 111 | <Compile Include="src\app\views\effect\EffectVoiceChat.lua" /> |
| 112 | <Compile Include="src\app\views\scene\BaseScene.lua" /> | 112 | <Compile Include="src\app\views\scene\BaseScene.lua" /> |
| 113 | <Compile Include="src\app\views\candy\LoadingScene.lua" /> | ||
| 114 | <Compile Include="src\app\views\candy\GameScene.lua" /> | ||
| 115 | <Compile Include="src\app\views\scene\BaseSceneNew.lua" /> | 113 | <Compile Include="src\app\views\scene\BaseSceneNew.lua" /> |
| 114 | <Compile Include="src\app\views\rubbish\LoadingScene.lua" /> | ||
| 115 | <Compile Include="src\app\views\rubbish\GameScene.lua" /> | ||
| 116 | <Compile Include="src\app\views\view\AlertView.lua" /> | 116 | <Compile Include="src\app\views\view\AlertView.lua" /> |
| 117 | <Compile Include="src\app\views\view\BaseView.lua" /> | 117 | <Compile Include="src\app\views\view\BaseView.lua" /> |
| 118 | <Compile Include="src\app\views\view\BaseViewNew.lua" /> | 118 | <Compile Include="src\app\views\view\BaseViewNew.lua" /> | ... | ... |
No preview for this file type
| 1 | local BaseData = class("BaseData") | ||
| 2 | |||
| 3 | local password = "zhjianctkj0571"; | ||
| 4 | |||
| 5 | function BaseData:ctor( fileName ) | ||
| 6 | self.fileName = fileName | ||
| 7 | self.data = {} | ||
| 8 | end | ||
| 9 | |||
| 10 | function BaseData:saveToFile( ) | ||
| 11 | local str = json.encode(self.data) | ||
| 12 | local targetPlatform = cc.Application:getInstance():getTargetPlatform() | ||
| 13 | if targetPlatform ~= cc.PLATFORM_OS_WINDOWS then | ||
| 14 | -- str = MCCrypto:encryptXXTEA(str, string.len(str), password, string.len(password)); | ||
| 15 | end | ||
| 16 | local fullFilename = cc.FileUtils:getInstance():getWritablePath()..self.fileName | ||
| 17 | local file = io.open(fullFilename, "w") | ||
| 18 | file:write(str) | ||
| 19 | file:close() | ||
| 20 | end | ||
| 21 | |||
| 22 | function BaseData:readFromFile( ) | ||
| 23 | local result = false | ||
| 24 | local fullFilename = cc.FileUtils:getInstance():getWritablePath()..self.fileName | ||
| 25 | local file = io.open(fullFilename, "r") | ||
| 26 | |||
| 27 | if file then | ||
| 28 | local str= file:read("*all") | ||
| 29 | -- print(str) | ||
| 30 | file:close() | ||
| 31 | if pcall(function() | ||
| 32 | local targetPlatform = cc.Application:getInstance():getTargetPlatform() | ||
| 33 | if targetPlatform ~= cc.PLATFORM_OS_WINDOWS then | ||
| 34 | -- str = MCCrypto:decryptXXTEA(str, string.len(str), password, string.len(password)) | ||
| 35 | end | ||
| 36 | self.data = json.decode(str) | ||
| 37 | result = true | ||
| 38 | end) then | ||
| 39 | --todo | ||
| 40 | else | ||
| 41 | self.data = {} | ||
| 42 | print("invalid json data: "..self.fileName) | ||
| 43 | end | ||
| 44 | else | ||
| 45 | |||
| 46 | self.data = {} | ||
| 47 | end | ||
| 48 | |||
| 49 | return result | ||
| 50 | end | ||
| 51 | |||
| 52 | function BaseData:resetData( ) | ||
| 53 | self.data = {} | ||
| 54 | self:saveToFile() | ||
| 55 | end | ||
| 56 | |||
| 57 | return BaseData | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | |||
| 2 | local MyApp = class("MyApp", cc.load("mvc").AppBase) | 1 | local MyApp = class("MyApp", cc.load("mvc").AppBase) |
| 3 | 2 | ||
| 4 | function MyApp:onCreate() | 3 | function MyApp:onCreate() |
| 5 | math.randomseed(os.time()) | 4 | math.randomseed(os.time()); |
| 5 | end | ||
| 6 | |||
| 7 | --function MyApp:enterScene(sceneName, transition, time, more) | ||
| 8 | -- return display.runScene(display.newScene(sceneName),transition,time,more) | ||
| 9 | --end | ||
| 10 | |||
| 11 | function MyApp:enterScene(sceneName, args, transitionType, time, more) | ||
| 12 | local scenePackageName = "src.app.views.scene."..sceneName; | ||
| 13 | print("볡"..scenePackageName); | ||
| 14 | local sceneClass = require(scenePackageName) | ||
| 15 | -- local scene = sceneClass.new(unpack(checktable(args))) | ||
| 16 | local scene = sceneClass.new(args) | ||
| 17 | display.runScene(scene, transitionType, time, more) | ||
| 18 | end | ||
| 19 | |||
| 20 | function MyApp:enterMiniGameScene(sceneName, args, transitionType, time, more) | ||
| 21 | local scenePackageName = "src.app.views."..sceneName; | ||
| 22 | print("볡"..scenePackageName); | ||
| 23 | local sceneClass = require(scenePackageName) | ||
| 24 | -- local scene = sceneClass.new(unpack(checktable(args))) | ||
| 25 | local scene = sceneClass.new(args) | ||
| 26 | display.runScene(scene, transitionType, time, more) | ||
| 6 | end | 27 | end |
| 7 | 28 | ||
| 8 | return MyApp | 29 | return MyApp | ... | ... |
| 1 | cc.exports.GameConfig={}; local xml = require("core.utils.pl.xml"); GameConfig.relief_cnt = 2;GameConfig.relief_base = 2000; --低保底限 return GameConfig; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | cc.exports.strings = {} | ||
| 2 | strings.msg_100 = "版本已经升级,请更新以便更好的体验游戏!"; | ||
| 3 | strings.msg_101 = "无法获取服务器地址,请联系商家!"; | ||
| 4 | strings.msg_1001 = "服务器出现异常,请重新登录!"; | ||
| 5 | strings.msg_1002 = "网络已断开,请检查网络是否正常!"; | ||
| 6 | strings.msg_1003 = "点券不足,去充值吧?"; | ||
| 7 | strings.msg_1004 = "登录失败,请检查网络连接是否正常!"; | ||
| 8 | strings.msg_1005 = "您的账号已在其他地方登录!"; | ||
| 9 | strings.msg_1006 = "你慢了一步,此昵称已被使用!"; | ||
| 10 | strings.msg_1007 = "昵称修改成功!"; | ||
| 11 | strings.msg_1008 = "请随机选择一个昵称!"; | ||
| 12 | strings.msg_1009 = "头像修改成功!"; | ||
| 13 | strings.msg_1010 = "未知错误"; | ||
| 14 | strings.msg_1011 = "已经是当前头像!"; | ||
| 15 | strings.msg_1012 = "每局扣除1张房卡"; | ||
| 16 | strings.msg_1013 = "房主每局扣除4张房卡"; | ||
| 17 | strings.msg_1014 = "每局开始消耗%s金币"; | ||
| 18 | strings.msg_1015 = "我的房卡数量:%s张"; | ||
| 19 | strings.msg_1016 = "今日抽奖已完成!"; | ||
| 20 | strings.msg_1017 = "需要完成%s局才能进行抽奖"; | ||
| 21 | strings.msg_1018 = "时间没到,无法领取!"; | ||
| 22 | strings.msg_1019 = "每局扣除4张房卡"; | ||
| 23 | strings.msg_1020 = "你的金币太多啦,高倍场才适合您!前往赚个盆满钵满吧!"; | ||
| 24 | strings.msg_1021 = "长时间未操作,你已经离开游戏"; | ||
| 25 | strings.msg_1022 = "你已经离开游戏"; | ||
| 26 | strings.msg_1023 = "目前金币不足,给您发放今日补助\n金币%s,祝您游戏愉快!"; | ||
| 27 | strings.msg_1024 = "返回到游戏大厅?"; | ||
| 28 | strings.msg_1025 = "今日获得%s已达上限"; | ||
| 29 | strings.msg_1026 = "勋章不足"; | ||
| 30 | |||
| 31 | strings.msg_2001 = "牌型不对哦!"; | ||
| 32 | strings.msg_2002 = "是否确定要退出游戏房间?"; | ||
| 33 | strings.msg_2003 = "金币不足"; | ||
| 34 | strings.msg_2004 = "房主离开,房间解散!"; | ||
| 35 | strings.msg_2005 = "游戏正在进行中,确定要退出吗?"; | ||
| 36 | strings.msg_2006 = "无法进入该房间"; | ||
| 37 | strings.msg_2007 = "房间已满"; | ||
| 38 | strings.msg_2008 = "道具不足"; | ||
| 39 | strings.msg_2009 = "房卡不足,是否去购买?"; | ||
| 40 | strings.msg_2010 = "补签卡不足,是否去购买?"; | ||
| 41 | strings.msg_2011 = "该道具不存在"; | ||
| 42 | strings.msg_2012 = "无法使用该道具"; | ||
| 43 | strings.msg_2013 = "金币不足,去快速获得吗?"; | ||
| 44 | strings.msg_2014 = "抗贡"; | ||
| 45 | strings.msg_2015 = "不符合还贡规则!"; | ||
| 46 | strings.msg_2016 = "不符合进贡规则!"; | ||
| 47 | strings.msg_2017 = "购买失败!"; | ||
| 48 | strings.msg_2018 = "没有牌大过上家"; | ||
| 49 | strings.msg_2019 = "牌不够大哦!"; | ||
| 50 | strings.msg_2020 = "出更大的“%s”管他!"; | ||
| 51 | strings.msg_2021 = "不会吧,“天王炸”你也想管!"; | ||
| 52 | strings.msg_2022 = "只能出“三带二”或“三张”哦!"; | ||
| 53 | strings.msg_2023 = "只能出5张连续的“顺子”!"; | ||
| 54 | strings.msg_2024 = "只能出3连对的“木板”!"; | ||
| 55 | strings.msg_2025 = "只能出2连三张的“钢板”!"; | ||
| 56 | strings.msg_2026 = "没有同花顺!"; | ||
| 57 | strings.msg_2027 = "先选中要单独放置的牌!"; | ||
| 58 | strings.msg_2028 = "离开房间会切换至托管模式,确定要离开吗?"; | ||
| 59 | strings.msg_2029 = "正在牌局中,无法退出!"; | ||
| 60 | strings.msg_2030 = "暂无战况信息"; | ||
| 61 | strings.msg_2031 = "请先选择水果押注!"; | ||
| 62 | strings.msg_2032 = "请选择要出的牌!"; | ||
| 63 | return strings; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | EnumErrorCode = {} | ||
| 2 | EnumErrorCode.EC_SUCCESS = 0; --成功 | ||
| 3 | EnumErrorCode.EC_ERR_CODE = 1; --错误 | ||
| 4 | EnumErrorCode.EC_VALUE_INVALID = 2; --无效数值 | ||
| 5 | EnumErrorCode.EC_LOGIN_T = 3; --被登陆上来的用户T掉 | ||
| 6 | EnumErrorCode.EC_INEXISTENT_ITEM = 4; --不存在,道具 | ||
| 7 | EnumErrorCode.EC_INEXISTENT_USER = 5; --不存在,用户 | ||
| 8 | EnumErrorCode.EC_EXISTENT_ROLE = 6; --存在,角色 | ||
| 9 | EnumErrorCode.EC_INEXISTENT_ACCOUNT = 7; --不存在,帐号 | ||
| 10 | EnumErrorCode.EC_NO_APPROVED = 8; --尚未通过身份校验 | ||
| 11 | EnumErrorCode.EC_EVENT_LIMIT = 9; --事件上限 | ||
| 12 | EnumErrorCode.EC_USER_LEVEL = 10; --用户等级不足 | ||
| 13 | EnumErrorCode.EC_USER_BTL = 11; --用户在战斗状态 | ||
| 14 | EnumErrorCode.EC_PASSWORD = 14; --密码错误 | ||
| 15 | EnumErrorCode.EC_CHAT_LEN_MAX = 15; --聊天长度上限 | ||
| 16 | EnumErrorCode.EC_EXCEL_ERROR = 17; --配置表错误 | ||
| 17 | EnumErrorCode.EC_BUY_TIMES_UP_TO_LIMIT = 18; --购买次数达到上限 | ||
| 18 | EnumErrorCode.EC_USER_IN_ROOM = 19; --用户在房间 | ||
| 19 | EnumErrorCode.EC_USER_BASE_MONEY = 20; --用户押金不足 | ||
| 20 | EnumErrorCode.EC_USER_OUT_ROOM = 21; --用户在房间外 | ||
| 21 | EnumErrorCode.EC_USER_IN_RUM_ROOM = 22; --用户在运行的房间 | ||
| 22 | EnumErrorCode.EC_USER_IN_LOBBY = 23; --用户在大厅中 | ||
| 23 | EnumErrorCode.EC_USER_OUT_LOBBY = 24; --用户不在大厅中 | ||
| 24 | EnumErrorCode.EC_USER_NICK_EXIST = 25; --用户昵称已存在 | ||
| 25 | EnumErrorCode.EC_INEXISTENT_ROOM = 26; --不存在,房间 | ||
| 26 | EnumErrorCode.EC_FULL_ROOM = 27; --满,房间 | ||
| 27 | EnumErrorCode.EC_MAIL_INEXISTENT = 28; --邮件不存在 | ||
| 28 | EnumErrorCode.EC_MAIL_ATTACHMENT_INEXISTENT = 29; --邮件无附件 | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | EnumEvent={};EnumEvent.SOCKET_DISCONNECT = "socket_disconnect";EnumEvent.SOCKET_RECONNECT = "socket_reconnect"; EnumEvent.LOGIN_SUCCESS = "login_success";EnumEvent.LOGIN_FAILD = "login_faild"; EnumEvent.USER_INFO = "user_info"; EnumEvent.ROOM_ENTER_MULTI = "room_enter_multi";EnumEvent.ROOM_ENTER_FAILD = "room_enter_faild";EnumEvent.ROOM_ENTER_FAILD_BUY_CARD_SUCCESS = "room_enter_faild_buy_card_success"; EnumEvent.ROOM_USERS = "room_users";EnumEvent.ROOM_USERS_SCORE = "room_users_score";EnumEvent.ROOM_MY_POKERS = "room_my_pokers";EnumEvent.ROOM_GONG_FLAG = "room_gong_flag";EnumEvent.ROOM_JIN_HUAN_GONG = "room_jin_huan_gong";EnumEvent.GAME_WHO_SHOT = "game_who_shot";EnumEvent.GAME_SHOT_POKERS = "game_shot_pokers";EnumEvent.GAME_SHOT_ERROR = "game_shot_error";EnumEvent.GAME_PASS = "game_pass";EnumEvent.GAME_ALL_PASS = "game_all_pass";EnumEvent.GAME_POKER_FINISH = "game_poker_finish";EnumEvent.GAME_RET = "game_ret";EnumEvent.GAME_OVER = "game_over";EnumEvent.GAME_DEBUG_POKER = "game_debug_poker"; EnumEvent.SINGLE_POKER_GONG = "single_poker_gong";EnumEvent.SINGLE_POKER_SHOT = "single_poker_shot"; EnumEvent.POKER_NUM = "poker_num"; --剩余牌数量事件 EnumEvent.UPDATE_ITEMS = "update_items"; --更新道具 EnumEvent.UPDATE_COUPONS = "update_coupons"; --更新点券 EnumEvent.UPDATE_COIN = "update_coin"; --更新金币 EnumEvent.UPDATE_CHARM = "update_charm"; --更新魅力值 EnumEvent.UPDATE_TASK = "update_task"; --更新任务 EnumEvent.UPDATE_MAIL = "update_mail"; --更新邮件 EnumEvent.UPDATE_RANK_REWARD = "update_rank_reward"; --更新排行榜奖励 EnumEvent.UPDATE_ACTIVITY = "update_activity"; --更新活动 EnumEvent.UPDATE_WIN = "update_win"; --更新胜利次数 EnumEvent.UPDATE_LOST = "update_lost"; --更新失败次数 EnumEvent.UPDATE_SCORE = "update_score"; --更新分数 EnumEvent.UPDATE_VIP = "update_vip"; --更新VIP EnumEvent.UPDATE_FIRST_PAY = "update_first_pay"; --更新首充礼包 EnumEvent.UPDATE_FIRST_CYCLE_PAY = "update_first_cycle_pay"; --更新周期首充礼包 EnumEvent.UPDATE_FREE_ITEM = "update_free_item"; --更新免费项信息 EnumEvent.USE_ITEM = "use_item"; --使用道具 EnumEvent.NICK_CHANGE_SUCCESS = "nick_change_success"; --昵称修改成功 EnumEvent.HEAD_CHANGE_SUCCESS = "head_change_success"; --头像修改成功 EnumEvent.HEAD_FRAME_CHANGE_SUCCESS = "head_frame_change_success"; --头像框修改成功 EnumEvent.MJ_ZHUANG = "mj_zhuang"; --麻将庄家 EnumEvent.MJ_DING = "mj_ding"; --麻将定牌 EnumEvent.MJ_DA = "mj_da"; --麻将打牌 EnumEvent.MJ_FA_NOTIFY = "mj_fa_notify"; --麻将发牌通知 EnumEvent.MJ_HGPG = "mj_hgpg"; --麻将胡杠碰过 EnumEvent.MJ_PENG = "mj_peng"; --麻将碰 EnumEvent.MJ_GANG = "mj_gang"; --麻将杠 EnumEvent.MJ_HU = "mj_hu"; --麻将杠 EnumEvent.MJ_GUO = "mj_guo"; --麻将过 EnumEvent.MJ_YI_PAO_DUO_XIANG = "mj_yi_pao_duo_xiang"; --麻将一炮多响 EnumEvent.MJ_NODE_UPDATE = "mj_node_update"; --麻将更新 EnumEvent.MJ_ROOM_ADD_MONEY = "mj_room_add_money"; --麻将加钱 EnumEvent.MJ_ROOM_REDUCE_MONEY = "mj_room_reduce_money"; --麻将减钱 EnumEvent.MJ_UPDATE_SELECTED_STATE = "mj_update_selected_state"; --麻将选中状态更新 EnumEvent.MJ_RECOMMEND_HUAN_KEY = "mj_recommend_huan_key"; --麻将推荐换牌消息 EnumEvent.MJ_HUAN_KEY = "mj_huan_key"; --麻将换牌消息 EnumEvent.NN_TIME_START = "nn_time_start"; --牛牛开始倒计时时间 EnumEvent.ACT_SHOW_FIGHT_LOTTERY = "act_show_fight_lottery"; EnumEvent.ACT_GET_LOTTERY = "act_get_lottery"; EnumEvent.DDZ_NOTIFY_LANDLORD = "ddz_notify_landlord"; EnumEvent.DDZ_ACTION_RES = "ddz_action_res"; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | EnumGame = {} | ||
| 2 | EnumGame.MAIN = 0; --大厅 | ||
| 3 | EnumGame.CAKE = 1; --欢乐叠蛋糕 | ||
| 4 | EnumGame.FANPAI = 2; --记忆翻拍 | ||
| 5 | EnumGame.GUESS = 3; --猜猜我是谁 | ||
| 6 | EnumGame.GUESS_COLOR = 4; --它的颜色 | ||
| 7 | EnumGame.Runbbish = 5; --接糖果 | ||
| 8 | EnumGame.SHUYISHU = 6; --数一数 | ||
| 9 | EnumGame.RABBIT = 7; --奔跑吧小兔子 | ||
| 10 | EnumGame.HAIDAO = 8; --旋转海盗 | ||
| 11 | EnumGame.FEIYANZOUBI = 9; --飞檐走壁 | ||
| 12 | EnumGame.BIRD = 10; --水管小鸟 | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
client/rubbish/client/src/app/enum/init.lua
0 → 100644
| 1 | cc.exports.EventListener = {} | ||
| 2 | |||
| 3 | --事件侦听 node==nil时表示全局侦听 | ||
| 4 | function EventListener.addEventListener(node,customEventName,fun) | ||
| 5 | local listener; | ||
| 6 | if node ~= nil then | ||
| 7 | local eventDispatcher = node:getEventDispatcher(); | ||
| 8 | listener = cc.EventListenerCustom:create(customEventName, fun); | ||
| 9 | eventDispatcher:addEventListenerWithSceneGraphPriority(listener,node); | ||
| 10 | else | ||
| 11 | local eventDispatcher = cc.Director:getInstance():getEventDispatcher(); | ||
| 12 | listener = cc.EventListenerCustom:create(customEventName,fun); | ||
| 13 | eventDispatcher:addEventListenerWithFixedPriority(listener,1); | ||
| 14 | end | ||
| 15 | return listener; | ||
| 16 | end | ||
| 17 | |||
| 18 | function EventListener.removeCustomEventListeners(node,customEventName) | ||
| 19 | local eventDispatcher = nil; | ||
| 20 | if node ~= nil then | ||
| 21 | eventDispatcher = node:getEventDispatcher(); | ||
| 22 | else | ||
| 23 | eventDispatcher = cc.Director:getInstance():getEventDispatcher(); | ||
| 24 | end | ||
| 25 | eventDispatcher:removeCustomEventListeners(customEventName); | ||
| 26 | end | ||
| 27 | |||
| 28 | function EventListener.removeEventListener(node,listener) | ||
| 29 | local eventDispatcher = nil; | ||
| 30 | if node ~= nil then | ||
| 31 | eventDispatcher = node:getEventDispatcher(); | ||
| 32 | else | ||
| 33 | eventDispatcher = cc.Director:getInstance():getEventDispatcher(); | ||
| 34 | end | ||
| 35 | eventDispatcher:removeEventListener(listener) | ||
| 36 | end | ||
| 37 | |||
| 38 | function EventListener.removeAllEventListeners(node) | ||
| 39 | local eventDispatcher = node:getEventDispatcher(); | ||
| 40 | eventDispatcher:removeAllEventListeners(); | ||
| 41 | end | ||
| 42 | |||
| 43 | function EventListener.dispatchEvent(eventType,data) | ||
| 44 | local eventDispatcher = cc.Director:getInstance():getEventDispatcher(); | ||
| 45 | local event = cc.EventCustom:new(eventType) | ||
| 46 | if data ~= nil then | ||
| 47 | event.data = data; | ||
| 48 | end | ||
| 49 | eventDispatcher:dispatchEvent(event); | ||
| 50 | end | ||
| 51 | |||
| 52 | return EventListener | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | cc.exports.ConfigInfo = {} | ||
| 2 | |||
| 3 | local configMap = {}; | ||
| 4 | |||
| 5 | local function str_split(str,split_char) | ||
| 6 | str = tostring(str); | ||
| 7 | local sub_str_tab = {}; | ||
| 8 | while (true) do | ||
| 9 | local pos = nil | ||
| 10 | for i = 1, #str do | ||
| 11 | if string.sub(str, i, i) == split_char then | ||
| 12 | pos = i | ||
| 13 | break | ||
| 14 | end | ||
| 15 | end | ||
| 16 | if (not pos) then | ||
| 17 | sub_str_tab[#sub_str_tab + 1] = str; | ||
| 18 | break; | ||
| 19 | end | ||
| 20 | local sub_str = string.sub(str, 1, pos - 1); | ||
| 21 | sub_str_tab[#sub_str_tab + 1] = sub_str; | ||
| 22 | str = string.sub(str, pos + 1, #str); | ||
| 23 | end | ||
| 24 | |||
| 25 | return sub_str_tab; | ||
| 26 | end | ||
| 27 | |||
| 28 | --配置表信息 | ||
| 29 | local function init() | ||
| 30 | local itemStr = cc.FileUtils:getInstance():getStringFromFile("config.ini"); | ||
| 31 | local function readLineFun(lineStr) | ||
| 32 | local contents = str_split(lineStr,'='); | ||
| 33 | if #contents > 1 then | ||
| 34 | configMap[contents[1]] = contents[2]; | ||
| 35 | end | ||
| 36 | end | ||
| 37 | |||
| 38 | local index = 1; | ||
| 39 | local function readLine(str) | ||
| 40 | local a,b = string.find(str,"\r\n"); | ||
| 41 | if a then | ||
| 42 | local lineStr = string.sub(str,1,a-1); | ||
| 43 | readLineFun(lineStr); | ||
| 44 | |||
| 45 | index = index + 1; | ||
| 46 | str = string.sub(str,b+1); | ||
| 47 | readLine(str); | ||
| 48 | else | ||
| 49 | readLineFun(str); | ||
| 50 | end | ||
| 51 | end | ||
| 52 | readLine(itemStr); | ||
| 53 | end | ||
| 54 | init(); | ||
| 55 | |||
| 56 | --通过ID获取信息 | ||
| 57 | function ConfigInfo.getConfigInfo(id) | ||
| 58 | return configMap[tostring(id)]; | ||
| 59 | end | ||
| 60 | |||
| 61 | --读取txt配置 | ||
| 62 | function ConfigInfo.readTxtLines(linesStr) | ||
| 63 | local lineMap = {}; | ||
| 64 | local function readLineFun(lineStr) | ||
| 65 | local contents = str_split(lineStr,'='); | ||
| 66 | lineMap[contents[1]] = contents[2]; | ||
| 67 | end | ||
| 68 | |||
| 69 | local index = 1; | ||
| 70 | local function readLine(str) | ||
| 71 | local a,b = string.find(str,"\r\n"); | ||
| 72 | if a then | ||
| 73 | local lineStr = string.sub(str,1,a-1); | ||
| 74 | readLineFun(lineStr); | ||
| 75 | |||
| 76 | index = index + 1; | ||
| 77 | str = string.sub(str,b+1); | ||
| 78 | readLine(str); | ||
| 79 | else | ||
| 80 | readLineFun(str); | ||
| 81 | end | ||
| 82 | end | ||
| 83 | readLine(linesStr); | ||
| 84 | return lineMap; | ||
| 85 | end | ||
| 86 | |||
| 87 | return ConfigInfo | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | cc.exports.Alert = {} | ||
| 2 | |||
| 3 | function Alert.showOne(msg,okFun,cancelFun) | ||
| 4 | local receiver = require("app.views.view.AlertOneView"):show(msg,okFun,cancelFun); | ||
| 5 | |||
| 6 | local scene = cc.Director:getInstance():getRunningScene(); | ||
| 7 | scene.keypadManager:addKeypadReceiver(receiver); | ||
| 8 | end | ||
| 9 | |||
| 10 | function Alert.showTwo(msg,okFun,cancelFun,selectedIndex) | ||
| 11 | local receiver = require("app.views.view.AlertTwoView"):show(msg,okFun,cancelFun,selectedIndex); | ||
| 12 | |||
| 13 | local scene = cc.Director:getInstance():getRunningScene(); | ||
| 14 | scene.keypadManager:addKeypadReceiver(receiver); | ||
| 15 | end | ||
| 16 | |||
| 17 | function Alert.showNoMoney(shopID,okFun,cancelFun) | ||
| 18 | local scene = cc.Director:getInstance():getRunningScene(); | ||
| 19 | local receiver; | ||
| 20 | |||
| 21 | local firstPayInfo = ActivityModel.getCurrentFirstPayInfo(); | ||
| 22 | local shopInfo = ShopInfo.getShopInfo(shopID); | ||
| 23 | local costId = shopInfo.costList[1].id; | ||
| 24 | local costNum = shopInfo.costList[1].num; | ||
| 25 | local myNum = UserModel.getItemNum(costId); | ||
| 26 | print(costId,"my num:",myNum,"cost num:",costNum) | ||
| 27 | if UserModel.relief_cnt > 0 and UserModel.getCoin() < GameConfig.relief_base then | ||
| 28 | receiver = require("app.views.view.ReliefView"):show(); | ||
| 29 | receiver.okFun = okFun; | ||
| 30 | elseif firstPayInfo and tonumber(firstPayInfo.costList[1].num) == 1.0 and myNum < costNum then | ||
| 31 | receiver = require("app.views.view.ActivityView"):show("ActivityFirstPayView"); | ||
| 32 | receiver.okFun = okFun; | ||
| 33 | receiver.cancelFun = cancelFun; | ||
| 34 | EffectManager.showFntPop(strings.msg_2003); | ||
| 35 | else | ||
| 36 | receiver = require("app.views.view.AlertNoMoneyView"):show(shopID,okFun,cancelFun); | ||
| 37 | end | ||
| 38 | scene.keypadManager:addKeypadReceiver(receiver); | ||
| 39 | end | ||
| 40 | |||
| 41 | return Alert | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | cc.exports.AppManager = {} | ||
| 2 | |||
| 3 | function AppManager.show(appname,params) | ||
| 4 | local receiver = require("app.views.view."..appname):show(params); | ||
| 5 | |||
| 6 | local scene = cc.Director:getInstance():getRunningScene(); | ||
| 7 | scene.keypadManager:addKeypadReceiver(receiver); | ||
| 8 | end | ||
| 9 | |||
| 10 | return Alert | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | cc.exports.EffectManager=class("EffectManager") | ||
| 2 | |||
| 3 | local EffectScaleIn = require("app.views.effect.EffectScaleIn"); | ||
| 4 | local EffectVoiceChat = require("app.views.effect.EffectVoiceChat"); | ||
| 5 | local EffectBoom = require("app.views.effect.EffectBoom"); | ||
| 6 | local EffectStright = require("app.views.effect.EffectStright"); | ||
| 7 | local EffectPlayLevel = require("app.views.effect.EffectPlayLevel"); | ||
| 8 | local EffectFntPop = require("app.views.effect.EffectFntPop"); | ||
| 9 | |||
| 10 | --显示停留然后缩小特效 | ||
| 11 | function EffectManager.showScaleInEffect(effectName,position) | ||
| 12 | local scene = cc.Director:getInstance():getRunningScene(); | ||
| 13 | |||
| 14 | local eff = EffectScaleIn:create("res/effects/"..effectName..".png"); | ||
| 15 | eff:setPosition(position); | ||
| 16 | scene:addChild(eff); | ||
| 17 | end | ||
| 18 | |||
| 19 | function EffectManager.showFntPop(msg) | ||
| 20 | local scene = cc.Director:getInstance():getRunningScene(); | ||
| 21 | |||
| 22 | local eff = EffectFntPop:create(msg); | ||
| 23 | eff:setPosition(cc.p(display.width/2,display.height*2/3)); | ||
| 24 | scene:addChild(eff,200); | ||
| 25 | end | ||
| 26 | |||
| 27 | --显示语音聊天效果 | ||
| 28 | function EffectManager.showVoiceChatEffect(msg,position) | ||
| 29 | local scene = cc.Director:getInstance():getRunningScene(); | ||
| 30 | |||
| 31 | local eff = EffectVoiceChat:create(msg); | ||
| 32 | eff:setPosition(position); | ||
| 33 | scene:addChild(eff); | ||
| 34 | end | ||
| 35 | |||
| 36 | --显示放大停留然后缩小 特效 | ||
| 37 | function EffectManager.showScaleOutEffect(effectName,position) | ||
| 38 | local scene = cc.Director:getInstance():getRunningScene(); | ||
| 39 | |||
| 40 | local eff = EffectBoom:create("res/effects/"..effectName..".png"); | ||
| 41 | eff:setPosition(position); | ||
| 42 | scene:addChild(eff); | ||
| 43 | end | ||
| 44 | |||
| 45 | --显示顺子特效 从左往右飘过特效 | ||
| 46 | function EffectManager.showStrightEffect(effectName,position) | ||
| 47 | position = position or cc.p(0,0); | ||
| 48 | |||
| 49 | local scene = cc.Director:getInstance():getRunningScene(); | ||
| 50 | |||
| 51 | if scene:getChildByName(effectName) then | ||
| 52 | scene:removeChildByName(effectName); | ||
| 53 | end | ||
| 54 | local eff = EffectStright:create("res/effects/"..effectName..".png"); | ||
| 55 | eff:setName(effectName); | ||
| 56 | eff:setPosition(position); | ||
| 57 | scene:addChild(eff); | ||
| 58 | end | ||
| 59 | |||
| 60 | --显示本局大几特效 | ||
| 61 | function EffectManager.showPlayLevelEffect(poker_point,position) | ||
| 62 | local scene = cc.Director:getInstance():getRunningScene(); | ||
| 63 | |||
| 64 | local eff = EffectPlayLevel:create(poker_point); | ||
| 65 | eff:setPosition(position); | ||
| 66 | scene:addChild(eff); | ||
| 67 | end | ||
| 68 | |||
| 69 | --显示闪光效果 | ||
| 70 | function EffectManager.showFlashEffect(node) | ||
| 71 | if not node.flashAction then | ||
| 72 | local fadeIn = cc.FadeIn:create(0.8); | ||
| 73 | local fadeOut = cc.FadeOut:create(0.8); | ||
| 74 | node.flashAction = cc.RepeatForever:create(cc.Sequence:create(fadeIn,fadeOut)); | ||
| 75 | node:runAction(node.flashAction); | ||
| 76 | end | ||
| 77 | end | ||
| 78 | |||
| 79 | --移除闪光效果 | ||
| 80 | function EffectManager.removeFlashEffect(node) | ||
| 81 | if node.flashAction then | ||
| 82 | node:stopAction(node.flashAction); | ||
| 83 | node.flashAction = nil; | ||
| 84 | end | ||
| 85 | end | ||
| 86 | |||
| 87 | --回弹效果 | ||
| 88 | function EffectManager.bounceNode(node) | ||
| 89 | if not node.scale then | ||
| 90 | node.scale = node:getScale(); | ||
| 91 | end | ||
| 92 | -- node:setScale(node.scale+0.15); | ||
| 93 | local scaleTo = cc.ScaleTo:create(0.2,node.scale+0.15,node.scale+0.15); | ||
| 94 | local scaleTo1 = cc.EaseBounceOut:create(cc.ScaleTo:create(1,node.scale,node.scale)); | ||
| 95 | node:runAction(cc.Sequence:create(scaleTo,scaleTo1)); | ||
| 96 | end | ||
| 97 | |||
| 98 | return EffectManager | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | cc.exports.ItemManager=class("ItemManager") | ||
| 2 | |||
| 3 | ItemManager.lock_pok = false; | ||
| 4 | local queuePopList = {}; | ||
| 5 | local isPopping = false; | ||
| 6 | local runningScene = nil; | ||
| 7 | |||
| 8 | local lastPopTime = 0; | ||
| 9 | |||
| 10 | local function showPopItem() | ||
| 11 | if not isPopping then | ||
| 12 | if #queuePopList > 0 then | ||
| 13 | isPopping = true; | ||
| 14 | |||
| 15 | local obj = queuePopList[1]; | ||
| 16 | table.remove(queuePopList,1); | ||
| 17 | |||
| 18 | local PopItem = cc.CSLoader:createNode("ui/PopItem.csb"); | ||
| 19 | local rect = PopItem:getBoundingBox(); | ||
| 20 | PopItem:setPosition(cc.p(display.width/2-rect.width/2,display.height/2-rect.height/2)); | ||
| 21 | |||
| 22 | local icon = PopItem:getChildByName("icon"); | ||
| 23 | icon:loadTexture("res/iconsmall/"..obj.id..".png"); | ||
| 24 | local item_amount = PopItem:getChildByName("item_amount"); | ||
| 25 | local itemInfo = ItemInfo.getItemInfo(obj.id); | ||
| 26 | item_amount:setString(itemInfo.name.."* "..obj.num); | ||
| 27 | |||
| 28 | runningScene:addChild(PopItem,dialog.ZORDER_POP+1); | ||
| 29 | |||
| 30 | local function fadeOutBack() | ||
| 31 | PopItem:removeSelf(); | ||
| 32 | |||
| 33 | if not isPopping then | ||
| 34 | showPopItem(); | ||
| 35 | end | ||
| 36 | end | ||
| 37 | |||
| 38 | local fadeOut = cc.FadeOut:create(1); | ||
| 39 | local moveBy = cc.MoveBy:create(1, cc.p(0, 200)); | ||
| 40 | PopItem:runAction(moveBy); | ||
| 41 | PopItem:runAction(cc.Sequence:create(fadeOut,cc.CallFunc:create(fadeOutBack))); | ||
| 42 | |||
| 43 | local function nextPopFun() | ||
| 44 | isPopping = false; | ||
| 45 | showPopItem(); | ||
| 46 | end | ||
| 47 | |||
| 48 | runningScene:runAction(cc.Sequence:create(cc.DelayTime:create(0.3),cc.CallFunc:create(nextPopFun))); | ||
| 49 | end | ||
| 50 | end | ||
| 51 | end | ||
| 52 | |||
| 53 | function ItemManager.addPopItem(ID,num) | ||
| 54 | if ID == 100004 or ItemManager.lock_pok then | ||
| 55 | return; | ||
| 56 | end | ||
| 57 | |||
| 58 | local obj = {id=ID,num=num}; | ||
| 59 | if runningScene ~= cc.Director:getInstance():getRunningScene() then | ||
| 60 | queuePopList = {}; | ||
| 61 | runningScene = cc.Director:getInstance():getRunningScene(); | ||
| 62 | end | ||
| 63 | queuePopList[#queuePopList+1] = obj; | ||
| 64 | |||
| 65 | if ID == 100001 then | ||
| 66 | ccs.ArmatureDataManager:getInstance():addArmatureFileInfo(string.format("res/effects/%s/%s.ExportJson","gold","gold")) | ||
| 67 | local effect = ccs.Armature:create("gold"); | ||
| 68 | effect:getAnimation():play("gold"); | ||
| 69 | runningScene:addChild(effect,dialog.ZORDER_POP); | ||
| 70 | effect:setPosition(cc.p(display.width/2,display.height/2)); | ||
| 71 | effect:getAnimation():setMovementEventCallFunc(function(arm, eventType, movmentID) | ||
| 72 | if (eventType == ccs.MovementEventType.complete or eventType == ccs.MovementEventType.loopComplete) then | ||
| 73 | arm:removeSelf(); | ||
| 74 | end | ||
| 75 | end) | ||
| 76 | end | ||
| 77 | |||
| 78 | showPopItem(); | ||
| 79 | end | ||
| 80 | |||
| 81 | return ItemManager | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | cc.exports.KeypadManager = class("KeypadManager") | ||
| 2 | |||
| 3 | require "socket"; | ||
| 4 | |||
| 5 | local keyEventsMapping = { | ||
| 6 | back = "onKeypadBack", | ||
| 7 | menu = "onKeypadMenu", | ||
| 8 | left = "onKeypadLeft", | ||
| 9 | right = "onKeypadRight", | ||
| 10 | up = "onKeypadUp", | ||
| 11 | down = "onKeypadDown", | ||
| 12 | ok = "onKeypadOk" | ||
| 13 | } | ||
| 14 | |||
| 15 | last_ok_time = socket.gettime(); | ||
| 16 | |||
| 17 | last_secrect_time = socket.gettime(); | ||
| 18 | secrect_code_1 = {cc.KeyCode.KEY_UP_ARROW,cc.KeyCode.KEY_UP_ARROW,cc.KeyCode.KEY_DOWN_ARROW,cc.KeyCode.KEY_DOWN_ARROW,cc.KeyCode.KEY_LEFT_ARROW,cc.KeyCode.KEY_LEFT_ARROW,cc.KeyCode.KEY_RIGHT_ARROW,cc.KeyCode.KEY_RIGHT_ARROW,cc.KeyCode.KEY_DOWN_ARROW,cc.KeyCode.KEY_UP_ARROW,cc.KeyCode.KEY_RIGHT_ARROW,cc.KeyCode.KEY_LEFT_ARROW}; | ||
| 19 | secrect_code_2 = {cc.KeyCode.KEY_DPAD_UP,cc.KeyCode.KEY_DPAD_UP,cc.KeyCode.KEY_DPAD_DOWN,cc.KeyCode.KEY_DPAD_DOWN,cc.KeyCode.KEY_DPAD_LEFT,cc.KeyCode.KEY_DPAD_LEFT,cc.KeyCode.KEY_DPAD_RIGHT,cc.KeyCode.KEY_DPAD_RIGHT,cc.KeyCode.KEY_DPAD_DOWN,cc.KeyCode.KEY_DPAD_UP,cc.KeyCode.KEY_DPAD_RIGHT,cc.KeyCode.KEY_DPAD_LEFT}; | ||
| 20 | secrect_arr = {}; | ||
| 21 | |||
| 22 | function KeypadManager:ctor(scene) | ||
| 23 | self.keypadReceivers = {}; | ||
| 24 | self.keypadReceivers[#self.keypadReceivers+1] = scene; | ||
| 25 | |||
| 26 | local eventDispatch = scene:getEventDispatcher() | ||
| 27 | local key_listener = cc.EventListenerKeyboard:create() | ||
| 28 | key_listener:registerScriptHandler(handler(self,self.keyReleasedHandler),cc.Handler.EVENT_KEYBOARD_RELEASED) | ||
| 29 | eventDispatch:addEventListenerWithSceneGraphPriority(key_listener,scene); | ||
| 30 | end | ||
| 31 | |||
| 32 | function KeypadManager:keyReleasedHandler(keyCode, event) | ||
| 33 | -- local targetPlatform = cc.Application:getInstance():getTargetPlatform(); | ||
| 34 | -- if targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 35 | -- logUI("keycode:"..keyCode.." keycodekey:"..cc.KeyCodeKey[keyCode+1]); | ||
| 36 | -- end | ||
| 37 | |||
| 38 | local receiver = self.keypadReceivers[#self.keypadReceivers]; | ||
| 39 | if not receiver then | ||
| 40 | return; | ||
| 41 | end | ||
| 42 | |||
| 43 | local keyname = ""; | ||
| 44 | if keyCode == cc.KeyCode.KEY_BACK or keyCode == cc.KeyCode.KEY_ESCAPE then | ||
| 45 | keyname = "back"; | ||
| 46 | elseif keyCode == cc.KeyCode.KEY_KP_ENTER or keyCode == cc.KeyCode.KEY_DPAD_CENTER or keyCode == cc.KeyCode.KEY_ENTER then | ||
| 47 | keyname = "ok"; | ||
| 48 | elseif keyCode == cc.KeyCode.KEY_LEFT_ARROW or keyCode == cc.KeyCode.KEY_DPAD_LEFT then | ||
| 49 | keyname = "left"; | ||
| 50 | elseif keyCode == cc.KeyCode.KEY_RIGHT_ARROW or keyCode == cc.KeyCode.KEY_DPAD_RIGHT then | ||
| 51 | keyname = "right"; | ||
| 52 | elseif keyCode == cc.KeyCode.KEY_UP_ARROW or keyCode == cc.KeyCode.KEY_DPAD_UP then | ||
| 53 | keyname = "up"; | ||
| 54 | elseif keyCode == cc.KeyCode.KEY_DOWN_ARROW or keyCode == cc.KeyCode.KEY_DPAD_DOWN then | ||
| 55 | keyname = "down"; | ||
| 56 | elseif keyCode == cc.KeyCode.KEY_MENU then | ||
| 57 | keyname = "menu"; | ||
| 58 | end | ||
| 59 | |||
| 60 | local _secrect_time = socket.gettime(); | ||
| 61 | if _secrect_time - last_secrect_time > 1 then | ||
| 62 | secrect_arr = {}; | ||
| 63 | end | ||
| 64 | secrect_arr[#secrect_arr+1] = keyCode; | ||
| 65 | self:check_secrect_down(); | ||
| 66 | last_secrect_time = _secrect_time; | ||
| 67 | |||
| 68 | if keyname == "ok" then | ||
| 69 | local _time = socket.gettime(); | ||
| 70 | print("ok interval:"..(_time - last_ok_time)); | ||
| 71 | if _time - last_ok_time < 0.02 then | ||
| 72 | return; | ||
| 73 | end | ||
| 74 | last_ok_time = _time; | ||
| 75 | end | ||
| 76 | |||
| 77 | if not keyEventsMapping[keyname] then | ||
| 78 | print("invalid eventcode:"..keyCode); | ||
| 79 | return; | ||
| 80 | end | ||
| 81 | |||
| 82 | local fname = keyEventsMapping[keyname]; | ||
| 83 | local fn = receiver[fname]; | ||
| 84 | if fn then | ||
| 85 | fn(receiver); | ||
| 86 | end | ||
| 87 | end | ||
| 88 | |||
| 89 | function KeypadManager:check_secrect_down() | ||
| 90 | local receiver = self.keypadReceivers[#self.keypadReceivers]; | ||
| 91 | if not receiver then | ||
| 92 | return; | ||
| 93 | end | ||
| 94 | |||
| 95 | local is_secrect_down = true; | ||
| 96 | -- logUI("secrect_code_1:"..json.encode(secrect_code_1)); | ||
| 97 | for i,v in ipairs(secrect_code_1) do | ||
| 98 | if not secrect_arr[i] or secrect_arr[i] ~= v then | ||
| 99 | is_secrect_down = false; | ||
| 100 | break; | ||
| 101 | end | ||
| 102 | end | ||
| 103 | if not is_secrect_down then | ||
| 104 | is_secrect_down = true; | ||
| 105 | -- logUI("secrect_code_2:"..json.encode(secrect_code_2)); | ||
| 106 | for i,v in ipairs(secrect_code_2) do | ||
| 107 | if not secrect_arr[i] or secrect_arr[i] ~= v then | ||
| 108 | is_secrect_down = false; | ||
| 109 | break; | ||
| 110 | end | ||
| 111 | end | ||
| 112 | end | ||
| 113 | -- logUI("is_secrect_down"..json.encode(secrect_arr)..tostring(is_secrect_down)); | ||
| 114 | if is_secrect_down then | ||
| 115 | local fn = receiver["onKeypadSecrect"]; | ||
| 116 | if fn then | ||
| 117 | fn(receiver); | ||
| 118 | end | ||
| 119 | end | ||
| 120 | end | ||
| 121 | |||
| 122 | function KeypadManager:addKeypadReceiver(receiver) | ||
| 123 | for i=#self.keypadReceivers,1,-1 do | ||
| 124 | if self.keypadReceivers[i] == receiver then | ||
| 125 | table.remove(self.keypadReceivers,i); | ||
| 126 | end | ||
| 127 | end | ||
| 128 | self.keypadReceivers[#self.keypadReceivers+1] = receiver; | ||
| 129 | end | ||
| 130 | |||
| 131 | function KeypadManager:removeKeypadReceiver(receiver) | ||
| 132 | for i=#self.keypadReceivers,1,-1 do | ||
| 133 | if self.keypadReceivers[i] == receiver then | ||
| 134 | table.remove(self.keypadReceivers,i); | ||
| 135 | end | ||
| 136 | end | ||
| 137 | end | ||
| 138 | |||
| 139 | return KeypadManager | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | cc.exports.LoadingManager = {} | ||
| 2 | |||
| 3 | function LoadingManager.showDataLoading(msg) | ||
| 4 | local scene = cc.Director:getInstance():getRunningScene(); | ||
| 5 | |||
| 6 | if not scene:getChildByName("data_loading_view") then | ||
| 7 | local reciever = require("app.views.view.LoadingDataView"):show(); | ||
| 8 | reciever:setName("data_loading_view"); | ||
| 9 | scene.keypadManager:addKeypadReceiver(reciever); | ||
| 10 | end | ||
| 11 | end | ||
| 12 | |||
| 13 | function LoadingManager.removeDataLoading() | ||
| 14 | local scene = cc.Director:getInstance():getRunningScene(); | ||
| 15 | local dataLoadingView = scene:getChildByName("data_loading_view"); | ||
| 16 | if dataLoadingView then | ||
| 17 | dataLoadingView:close(); | ||
| 18 | end | ||
| 19 | end | ||
| 20 | |||
| 21 | return LoadingManager | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | cc.exports.MedalItemManager=class("MedalItemManager") | ||
| 2 | |||
| 3 | function MedalItemManager.showPopMedal(ID,num) | ||
| 4 | if ID == 100004 or ItemManager.lock_pok then | ||
| 5 | return; | ||
| 6 | end | ||
| 7 | |||
| 8 | local runningScene = cc.Director:getInstance():getRunningScene(); | ||
| 9 | local _medalItemLayer = cc.CSLoader:createNode("ui/MedalItemLayer.csb"); | ||
| 10 | local rect = _medalItemLayer:getBoundingBox(); | ||
| 11 | _medalItemLayer:setPosition(cc.p(display.width/2-rect.width/2,display.height/2-rect.height/2)); | ||
| 12 | |||
| 13 | local item = _medalItemLayer:getChildByName("item"); | ||
| 14 | item:getChildByName("icon"):setSpriteFrame(cc.Sprite:create("res/icon/"..ID..".png"):getSpriteFrame()); | ||
| 15 | |||
| 16 | _medalItemLayer:getChildByName("medal_name"):setSpriteFrame(cc.Sprite:create("res/ui/medal/medal_"..ID..".png"):getSpriteFrame()); | ||
| 17 | |||
| 18 | local function moveToComplete() | ||
| 19 | if _medalItemLayer then | ||
| 20 | _medalItemLayer:removeSelf(); | ||
| 21 | _medalItemLayer = nil; | ||
| 22 | end | ||
| 23 | end | ||
| 24 | |||
| 25 | local moveTo = cc.MoveTo:create(0.8, cc.p(60*display.width/1280,60*display.height/720)); | ||
| 26 | local scaleTo = cc.ScaleTo:create(0.8,0.3); | ||
| 27 | item:runAction(cc.Sequence:create(cc.DelayTime:create(1),scaleTo)); | ||
| 28 | item:runAction(cc.Sequence:create(cc.DelayTime:create(1),moveTo,cc.CallFunc:create(moveToComplete))); | ||
| 29 | |||
| 30 | runningScene:addChild(_medalItemLayer,dialog.ZORDER_POP+1); | ||
| 31 | end | ||
| 32 | |||
| 33 | return MedalItemManager | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | cc.exports.NodeManager=class("NodeManager") | ||
| 2 | |||
| 3 | local EffectSelected = require("app.views.effect.EffectSelected"); | ||
| 4 | |||
| 5 | function NodeManager.setHighlight(node,bool,isBounce) | ||
| 6 | if isBounce == nil then | ||
| 7 | isBounce = true; | ||
| 8 | end | ||
| 9 | local _parent = node:getParent(); | ||
| 10 | local selected_box = _parent:getChildByName("buttonselected"); | ||
| 11 | |||
| 12 | if bool and node:isVisible() then | ||
| 13 | SoundManager.playEffect("res/sound/effect_selected.mp3"); | ||
| 14 | local rect = node:getBoundingBox(); | ||
| 15 | if not selected_box then | ||
| 16 | selected_box = EffectSelected:create(rect,node.type); | ||
| 17 | selected_box:setName("buttonselected"); | ||
| 18 | _parent:addChild(selected_box); | ||
| 19 | else | ||
| 20 | selected_box:setVisible(true); | ||
| 21 | selected_box:resize(rect,node.type); | ||
| 22 | end | ||
| 23 | if node.type == EnumNodeType.POKER or node.type == EnumNodeType.DDZ_POKER then | ||
| 24 | selected_box:setLocalZOrder(node:getLocalZOrder()); | ||
| 25 | else | ||
| 26 | selected_box:setLocalZOrder(100); | ||
| 27 | end | ||
| 28 | |||
| 29 | if node.type ~= EnumNodeType.POKER and node.type ~= EnumNodeType.DDZ_POKER and node.type ~= EnumNodeType.MJ and isBounce then | ||
| 30 | EffectManager.bounceNode(node); | ||
| 31 | EffectManager.bounceNode(selected_box); | ||
| 32 | end | ||
| 33 | |||
| 34 | local function updateSelectedPos() | ||
| 35 | local anchor = node:getAnchorPoint(); | ||
| 36 | local _x,_y = node:getPosition(); | ||
| 37 | if node.type == EnumNodeType.LAYER then | ||
| 38 | _x = _x + (anchor.x)*rect.width; | ||
| 39 | _y = _y + (anchor.y)*rect.height; | ||
| 40 | else | ||
| 41 | _x = _x - (anchor.x-0.5)*rect.width; | ||
| 42 | _y = _y - (anchor.y-0.5)*rect.height; | ||
| 43 | end | ||
| 44 | selected_box:setPosition(cc.p(_x,_y)); | ||
| 45 | end | ||
| 46 | updateSelectedPos(); | ||
| 47 | if node.type == EnumNodeType.MJ or node.type == EnumNodeType.DDZ_POKER then | ||
| 48 | node.posAction = schedule(node,updateSelectedPos,0); | ||
| 49 | end | ||
| 50 | else | ||
| 51 | if selected_box then | ||
| 52 | selected_box:setVisible(false); | ||
| 53 | end | ||
| 54 | if node.posAction then | ||
| 55 | node:stopAction(node.posAction); | ||
| 56 | node.posAction = nil; | ||
| 57 | end | ||
| 58 | end | ||
| 59 | end | ||
| 60 | |||
| 61 | --获取生成圆角头像 | ||
| 62 | function NodeManager.getRoundedHead(headName,anchorPoint) | ||
| 63 | anchorPoint = anchorPoint or cc.p(0.5,0.5); | ||
| 64 | local sprite_mask = cc.Sprite:create("res/common/head_mask.png"); | ||
| 65 | local spriteBg = cc.Sprite:createWithSpriteFrameName(headName); | ||
| 66 | local clipS = cc.ClippingNode:create(); ----创建ClippingNode | ||
| 67 | clipS:setStencil(sprite_mask); | ||
| 68 | if spriteBg then | ||
| 69 | clipS:addChild(spriteBg); | ||
| 70 | end | ||
| 71 | |||
| 72 | sprite_mask:setAnchorPoint(anchorPoint); | ||
| 73 | spriteBg:setAnchorPoint(anchorPoint); | ||
| 74 | |||
| 75 | clipS:setInverted(false) ---设置可视区为裁剪区域,还是裁剪剩余区域 | ||
| 76 | clipS:setAlphaThreshold(0.05) ---根据alpha值控制显示 | ||
| 77 | return clipS; | ||
| 78 | end | ||
| 79 | |||
| 80 | --获取生成圆角头像 | ||
| 81 | function NodeManager.getRoundedHeadBySprite(sp,anchorPoint) | ||
| 82 | anchorPoint = anchorPoint or cc.p(0.5,0.5); | ||
| 83 | local sprite_mask = cc.Sprite:create("res/common/head_mask.png"); | ||
| 84 | local clipS = cc.ClippingNode:create(); ----创建ClippingNode | ||
| 85 | clipS:setStencil(sprite_mask); | ||
| 86 | if sp then | ||
| 87 | clipS:addChild(sp); | ||
| 88 | end | ||
| 89 | |||
| 90 | sprite_mask:setAnchorPoint(anchorPoint); | ||
| 91 | sp:setAnchorPoint(anchorPoint); | ||
| 92 | |||
| 93 | clipS:setInverted(false) ---设置可视区为裁剪区域,还是裁剪剩余区域 | ||
| 94 | clipS:setAlphaThreshold(0.05) ---根据alpha值控制显示 | ||
| 95 | return clipS; | ||
| 96 | end | ||
| 97 | |||
| 98 | function NodeManager.getHeadSprite(headName,scale) | ||
| 99 | scale = scale or 1; | ||
| 100 | local spriteBg = cc.Sprite:createWithSpriteFrameName(headName); | ||
| 101 | spriteBg:setScale(scale); | ||
| 102 | return spriteBg; | ||
| 103 | end | ||
| 104 | |||
| 105 | return NodeManager | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | cc.exports.SoundManager = {} | ||
| 2 | |||
| 3 | soundKindArr = {"loli","ladylike"}; | ||
| 4 | |||
| 5 | SoundManager.isBackgroundMusic = true; | ||
| 6 | SoundManager.isEffect = true; | ||
| 7 | SoundManager.isPlayingBossEffect = false; | ||
| 8 | --local audioEngine = cc.SimpleAudioEngine:getInstance(); | ||
| 9 | |||
| 10 | SoundManager.cur_playing_music_path = ""; | ||
| 11 | |||
| 12 | local function init() | ||
| 13 | if cc.UserDefault:getInstance():getStringForKey("isMusic") == "" then | ||
| 14 | cc.UserDefault:getInstance():setStringForKey("isMusic",1); | ||
| 15 | end | ||
| 16 | if cc.UserDefault:getInstance():getStringForKey("isEffect") == "" then | ||
| 17 | cc.UserDefault:getInstance():setStringForKey("isEffect",1); | ||
| 18 | end | ||
| 19 | if cc.UserDefault:getInstance():getStringForKey("isMusic") == "1" then | ||
| 20 | SoundManager.isBackgroundMusic = true; | ||
| 21 | else | ||
| 22 | SoundManager.isBackgroundMusic = false; | ||
| 23 | end | ||
| 24 | if cc.UserDefault:getInstance():getStringForKey("isEffect") == "1" then | ||
| 25 | SoundManager.isEffect = true; | ||
| 26 | else | ||
| 27 | SoundManager.isEffect = false; | ||
| 28 | end | ||
| 29 | end | ||
| 30 | init(); | ||
| 31 | |||
| 32 | function SoundManager.playMusic(filePath,loop) | ||
| 33 | if filePath then | ||
| 34 | SoundManager.cur_playing_music_path = filePath; | ||
| 35 | end | ||
| 36 | if SoundManager.isBackgroundMusic then | ||
| 37 | -- audioEngine:playMusic(filePath,loop); | ||
| 38 | print("play music:",filePath); | ||
| 39 | audio.playMusic(SoundManager.cur_playing_music_path,loop); | ||
| 40 | SoundManager.setMusicVolume(1.5); | ||
| 41 | -- audioEngine:setMusicVolume(1); | ||
| 42 | end | ||
| 43 | end | ||
| 44 | |||
| 45 | function SoundManager.stopMusic() | ||
| 46 | if audio.isMusicPlaying() then | ||
| 47 | -- audioEngine:stopMusic(false); | ||
| 48 | audio.stopMusic(true) | ||
| 49 | -- audioEngine:setMusicVolume(0); | ||
| 50 | end | ||
| 51 | end | ||
| 52 | |||
| 53 | --暂停音乐 | ||
| 54 | function SoundManager.pauseMusic() | ||
| 55 | audio.pauseMusic() | ||
| 56 | end | ||
| 57 | |||
| 58 | --继续音乐 | ||
| 59 | function SoundManager.resumeMusic(filePath) | ||
| 60 | if filePath then | ||
| 61 | SoundManager.cur_playing_music_path = filePath; | ||
| 62 | end | ||
| 63 | if audio.isMusicPlaying() then | ||
| 64 | audio.resumeMusic() | ||
| 65 | else | ||
| 66 | SoundManager.playMusic(SoundManager.cur_playing_music_path,true) | ||
| 67 | end | ||
| 68 | end | ||
| 69 | |||
| 70 | function SoundManager.setMusicVolume(value) | ||
| 71 | --if SoundManager.isMusicPlaying() then | ||
| 72 | if audio.isMusicPlaying() then | ||
| 73 | audio.setMusicVolume(value) | ||
| 74 | end | ||
| 75 | -- audioEngine:setMusicVolume(value); | ||
| 76 | --end | ||
| 77 | end | ||
| 78 | |||
| 79 | function SoundManager.playEffect(filePath,isLoop,volume) | ||
| 80 | if isLoop==nil then | ||
| 81 | isLoop = false | ||
| 82 | end | ||
| 83 | if SoundManager.isEffect then | ||
| 84 | volume = volume or 1; | ||
| 85 | SoundManager.setSoundsVolume(volume); | ||
| 86 | return audio.playSound(filePath,isLoop) | ||
| 87 | end | ||
| 88 | end | ||
| 89 | |||
| 90 | function SoundManager.setSoundsVolume(value) | ||
| 91 | audio.setSoundsVolume(value); | ||
| 92 | end | ||
| 93 | |||
| 94 | function SoundManager.isMusicPlaying() | ||
| 95 | return audio.isMusicPlaying(); | ||
| 96 | end | ||
| 97 | |||
| 98 | function SoundManager.setIsBackgroundMusic(b) | ||
| 99 | SoundManager.isBackgroundMusic = b; | ||
| 100 | if b then | ||
| 101 | cc.UserDefault:getInstance():setStringForKey("isMusic",1); | ||
| 102 | else | ||
| 103 | cc.UserDefault:getInstance():setStringForKey("isMusic",0); | ||
| 104 | end | ||
| 105 | end | ||
| 106 | |||
| 107 | function SoundManager.setIsEffect(b) | ||
| 108 | SoundManager.isEffect = b; | ||
| 109 | if b then | ||
| 110 | cc.UserDefault:getInstance():setStringForKey("isEffect",1); | ||
| 111 | else | ||
| 112 | cc.UserDefault:getInstance():setStringForKey("isEffect",0); | ||
| 113 | end | ||
| 114 | end | ||
| 115 | |||
| 116 | function SoundManager.stopEffect(handle) | ||
| 117 | audio.stopSound(handle) | ||
| 118 | end | ||
| 119 | |||
| 120 | function SoundManager.getGuandanSoundPath(name) | ||
| 121 | return "res/sound/gd/"..name; | ||
| 122 | end | ||
| 123 | |||
| 124 | function SoundManager.getGuandanVoicePath(name) | ||
| 125 | local kind = math.random(1,2); | ||
| 126 | math.randomseed(tostring(os.time()+kind):reverse():sub(1, 6)); | ||
| 127 | return "res/sound/gd/"..soundKindArr[kind].."/"..name; | ||
| 128 | end | ||
| 129 | |||
| 130 | function SoundManager.getMJEffectPath(name,sex) | ||
| 131 | if sex == 1 then | ||
| 132 | return "res/sound/mj/sichuan/nan/"..name; | ||
| 133 | else | ||
| 134 | return "res/sound/mj/sichuan/nv/"..name; | ||
| 135 | end | ||
| 136 | end | ||
| 137 | |||
| 138 | function SoundManager.getMJChatSoundPath(name,sex) | ||
| 139 | if sex == 1 then | ||
| 140 | return "res/sound/mj/putonghua/nan/"..name; | ||
| 141 | else | ||
| 142 | return "res/sound/mj/putonghua/nv/"..name; | ||
| 143 | end | ||
| 144 | end | ||
| 145 | |||
| 146 | function SoundManager.getNiuniuChatSoundPath(name,sex) | ||
| 147 | local path = "" | ||
| 148 | if sex == 1 then | ||
| 149 | path = "res/sound/nn/nan/"..name; | ||
| 150 | else | ||
| 151 | path = "res/sound/nn/nv/"..name; | ||
| 152 | end | ||
| 153 | print("play nn chat voice:",path); | ||
| 154 | return path; | ||
| 155 | end | ||
| 156 | |||
| 157 | function SoundManager.getDdzEffectPath(name) | ||
| 158 | return "res/sound/ddz/"..name; | ||
| 159 | end | ||
| 160 | |||
| 161 | function SoundManager.getDdzChatPath(name,sex) | ||
| 162 | if sex == 1 then | ||
| 163 | return "res/sound/ddz/boychat/"..name; | ||
| 164 | else | ||
| 165 | return "res/sound/ddz/girlchat/"..name; | ||
| 166 | end | ||
| 167 | end | ||
| 168 | |||
| 169 | function SoundManager.getDdzPaixingPath(name,sex) | ||
| 170 | if sex == 1 then | ||
| 171 | return "res/sound/ddz/man/"..name; | ||
| 172 | else | ||
| 173 | return "res/sound/ddz/woman/"..name; | ||
| 174 | end | ||
| 175 | end | ||
| 176 | |||
| 177 | return SoundManager | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | cc.exports.ShopModel = {} | ||
| 2 | |||
| 3 | function ShopModel.init() | ||
| 4 | cmsg.on("gateway_msg.notify_pay_succ_msg_res",ShopModel.onPayResFun); | ||
| 5 | end | ||
| 6 | |||
| 7 | function ShopModel.onPayResFun(params) | ||
| 8 | local product = params.data.product; | ||
| 9 | print("产品订购成功:"..product); | ||
| 10 | local payInfo = ShopInfo.getPayInfoByProduct(product); | ||
| 11 | if payInfo then | ||
| 12 | local params = nil; | ||
| 13 | if payInfo.type == 1 then | ||
| 14 | params = payInfo.rmb.."&"..payInfo.itemList[1].num; | ||
| 15 | UmengHelper.onEvent("coupons_buy_"..payInfo.itemList[1].num); | ||
| 16 | print("购买点券:".."coupons_buy_"..payInfo.itemList[1].num); | ||
| 17 | elseif payInfo.type == 2 then | ||
| 18 | UserModel.addVip(payInfo.id); | ||
| 19 | params = payInfo.rmb.."&"..1; | ||
| 20 | if payInfo.id == 201 then | ||
| 21 | UmengHelper.onEvent("buy_vip_month"); | ||
| 22 | print("购买vip月卡"); | ||
| 23 | elseif payInfo.id == 202 then | ||
| 24 | UmengHelper.onEvent("buy_vip_season"); | ||
| 25 | print("购买vip季卡"); | ||
| 26 | end | ||
| 27 | elseif payInfo.type == 3 then | ||
| 28 | UserModel.addFirstPayID(payInfo.id); | ||
| 29 | params = payInfo.rmb.."&"..1; | ||
| 30 | UmengHelper.onEvent("buy_first_gift&rmb,"..payInfo.rmb); | ||
| 31 | print("购买首充礼包:".."buy_first_gift&rmb,"..payInfo.rmb); | ||
| 32 | elseif payInfo.type == 4 then | ||
| 33 | UserModel.addFirstPayDailyID(payInfo.id); | ||
| 34 | params = payInfo.rmb.."&"..1; | ||
| 35 | UmengHelper.onEvent("buy_first_daily_gift&rmb,"..payInfo.rmb); | ||
| 36 | print("购买每日首充礼包:".."buy_first_daily_gift&rmb,"..payInfo.rmb); | ||
| 37 | elseif payInfo.type == 5 then | ||
| 38 | UserModel.addFirstCyclePayID(payInfo.id); | ||
| 39 | params = payInfo.rmb.."&"..1; | ||
| 40 | UmengHelper.onEvent("buy_first_cycle_gift&rmb,"..payInfo.rmb); | ||
| 41 | print("周期首充礼包:".."buy_first_cycle_gift&rmb,"..payInfo.rmb); | ||
| 42 | end | ||
| 43 | if params then | ||
| 44 | logUI("umeng pay:"..params); | ||
| 45 | UmengHelper.pay(params,callBack); | ||
| 46 | end | ||
| 47 | end | ||
| 48 | end | ||
| 49 | |||
| 50 | function ShopModel.buy(id,cnt,callBack,timeoutCallBack) | ||
| 51 | num = num or 1; | ||
| 52 | local function onBuyResFun(params) | ||
| 53 | cmsg.off("gateway_msg.shop_buy_msg_res",onBuyResFun); | ||
| 54 | if params.errcode == EnumErrorCode.EC_SUCCESS then | ||
| 55 | if callBack then | ||
| 56 | callBack(params); | ||
| 57 | end | ||
| 58 | local shopInfo = ShopInfo.getShopInfo(id); | ||
| 59 | local costNum = shopInfo.costList[1].num; | ||
| 60 | UmengHelper.buy(id.."&"..cnt.."&"..costNum,nil); | ||
| 61 | elseif params.errcode == EnumErrorCode.EC_INEXISTENT_ITEM then | ||
| 62 | Alert.showOne(strings.msg_1003); | ||
| 63 | else | ||
| 64 | Alert.showOne(strings.msg_1003); | ||
| 65 | end | ||
| 66 | end | ||
| 67 | |||
| 68 | local function timeoutFn(params) | ||
| 69 | cmsg.off("gateway_msg.shop_buy_msg_res",onBuyResFun); | ||
| 70 | if timeoutCallBack then | ||
| 71 | timeoutCallBack(params); | ||
| 72 | end | ||
| 73 | end | ||
| 74 | cmsg.on("gateway_msg.shop_buy_msg_res",onBuyResFun); | ||
| 75 | SocketClient:getInstance():send("gateway_msg.shop_buy_msg", | ||
| 76 | { | ||
| 77 | id = id, | ||
| 78 | cnt = cnt | ||
| 79 | },timeoutFn); | ||
| 80 | end | ||
| 81 | |||
| 82 | --function ShopModel.pay(productId,productName,productPrice,callBack,timeoutCallBack) | ||
| 83 | -- local function onGetOrderResFun(params) | ||
| 84 | -- cmsg.off("gateway_msg.pay_get_id_msg_res",onGetOrderResFun); | ||
| 85 | -- if params.errcode == EnumErrorCode.EC_SUCCESS then | ||
| 86 | -- local tradeNo = params.data.pay_id; --订单号 | ||
| 87 | -- local productId = productId; --商品ID | ||
| 88 | -- local subject = productName; --商品名称 | ||
| 89 | -- local amount = productPrice; --商品价格 | ||
| 90 | -- local notificationURL = params.data.url_callback;--回调URL | ||
| 91 | -- local zfb_url_callback = params.data.zfb_url_callback;--支付宝回调URL | ||
| 92 | -- local wx_url_callback = params.data.wx_url_callback;--微信回调URL | ||
| 93 | -- local peng_bo_shi_token = params.data.peng_bo_shi_token;--鹏博士密钥 | ||
| 94 | -- logUI("订单号获取成功token:"..peng_bo_shi_token); | ||
| 95 | |||
| 96 | -- local function callbackLua(params) | ||
| 97 | -- if params == "success" then | ||
| 98 | -- if callBack then | ||
| 99 | -- callBack(params); | ||
| 100 | -- end | ||
| 101 | -- elseif params == "no" then | ||
| 102 | -- local subject = DeviceUtil.getAppName().." "..productName; | ||
| 103 | -- local reciever = require("app.views.view.QrPayView"):show({trade_no=tradeNo,subject=subject,price=productPrice,zfb_url=zfb_url_callback,wx_url=wx_url_callback,callBackFun=callBack}); | ||
| 104 | -- local scene = cc.Director:getInstance():getRunningScene(); | ||
| 105 | -- scene.keypadManager:addKeypadReceiver(reciever); | ||
| 106 | -- end | ||
| 107 | -- logUI(params); | ||
| 108 | -- end | ||
| 109 | |||
| 110 | -- local pay_params = tradeNo..","..productId..","..subject..","..amount..","..notificationURL..","..peng_bo_shi_token; | ||
| 111 | -- DeviceUtil.sendBilling(pay_params,callbackLua); | ||
| 112 | -- else | ||
| 113 | -- Alert.showOne(strings.msg_1010..params.errcode); | ||
| 114 | -- end | ||
| 115 | -- end | ||
| 116 | |||
| 117 | -- local function timeoutFn(params) | ||
| 118 | -- cmsg.off("gateway_msg.pay_get_id_msg_res",onGetOrderResFun); | ||
| 119 | -- if timeoutCallBack then | ||
| 120 | -- timeoutCallBack(params); | ||
| 121 | -- end | ||
| 122 | -- end | ||
| 123 | -- cmsg.on("gateway_msg.pay_get_id_msg_res",onGetOrderResFun); | ||
| 124 | -- SocketClient:getInstance():send("gateway_msg.pay_get_id_msg", | ||
| 125 | -- { | ||
| 126 | -- product = productId | ||
| 127 | -- },timeoutFn); | ||
| 128 | --end | ||
| 129 | |||
| 130 | function ShopModel.pay(productId,productName,productPrice,callBack,timeoutCallBack) | ||
| 131 | print("start pay----------------:",productId,productName,productPrice); | ||
| 132 | local function onGetPayIDSuccessFun(_params) | ||
| 133 | local data = json.decode(_params); | ||
| 134 | if data.pay_id == "" then | ||
| 135 | Alert.showOne("获取订单号失败!"); | ||
| 136 | return; | ||
| 137 | end | ||
| 138 | local tradeNo = data.pay_id; --订单号 | ||
| 139 | local productId = productId; --商品ID | ||
| 140 | local subject = productName; --商品名称 | ||
| 141 | local amount = productPrice; --商品价格 | ||
| 142 | local notificationURL = data.url_callback;--回调URL | ||
| 143 | local zfb_url_callback = data.zfb_url_callback;--支付宝回调URL | ||
| 144 | local wx_url_callback = data.wx_url_callback;--微信回调URL | ||
| 145 | local peng_bo_shi_token = data.peng_bo_shi_token;--鹏博士密钥 | ||
| 146 | print("get tradeNo success------:",tradeNo,notificationURL); | ||
| 147 | logUI("订单号获取成功token:"..peng_bo_shi_token); | ||
| 148 | |||
| 149 | local function callbackLua(params) | ||
| 150 | if params == "success" then | ||
| 151 | if cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_ANDROID then | ||
| 152 | HttpRequest:getInstance():post("http://139.196.55.173:22999/st",{id=3,gameid=GAME_ID,channel=CHANNEL,account=DeviceUtil.getDeviceId(),price=productPrice}); | ||
| 153 | end | ||
| 154 | if productId == "tjlhxkgddj018" then | ||
| 155 | UserModel.setIsVip(true); | ||
| 156 | end | ||
| 157 | elseif params == "no" then | ||
| 158 | if productId == "tjlhxkgddj018" then | ||
| 159 | UserModel.setIsVip(true); | ||
| 160 | end | ||
| 161 | end | ||
| 162 | if callBack then | ||
| 163 | callBack(params); | ||
| 164 | end | ||
| 165 | logUI(params); | ||
| 166 | end | ||
| 167 | |||
| 168 | local function payCallbackFromJava(params) | ||
| 169 | delayCall(0.5,function() | ||
| 170 | callbackLua(params); | ||
| 171 | end); | ||
| 172 | end | ||
| 173 | |||
| 174 | local pay_params = tradeNo..","..productId..","..subject..","..amount..","..notificationURL..","..peng_bo_shi_token; | ||
| 175 | DeviceUtil.sendBilling(pay_params,payCallbackFromJava); | ||
| 176 | if cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_ANDROID then | ||
| 177 | HttpRequest:getInstance():post("http://139.196.55.173:22999/st",{id=2,gameid=GAME_ID,channel=CHANNEL,account=DeviceUtil.getDeviceId(),price=productPrice}); | ||
| 178 | end | ||
| 179 | end | ||
| 180 | |||
| 181 | local function onGetPayIDFaildFun(params) | ||
| 182 | if timeoutCallBack then | ||
| 183 | timeoutCallBack(params); | ||
| 184 | end | ||
| 185 | end | ||
| 186 | |||
| 187 | if GAME_LOGIN_URL then | ||
| 188 | local get_pay_id_url = string.gsub(GAME_LOGIN_URL,"login","pay_get_id"); | ||
| 189 | if CHANNEL == "cmcc" and cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_ANDROID then | ||
| 190 | local paramsStr = "uid="..UserModel.getStringUID().."&product="..productId.."&account="..UserModel.account; | ||
| 191 | DeviceUtil.sendHttpRequest("POST,"..get_pay_id_url..","..PROXY_HTTP_ADDR..","..paramsStr,onGetPayIDSuccessFun); | ||
| 192 | else | ||
| 193 | HttpRequest:getInstance():post(get_pay_id_url,{uid=UserModel.getStringUID(),product=productId,account=UserModel.account},onGetPayIDSuccessFun,onGetPayIDFaildFun); | ||
| 194 | end | ||
| 195 | else | ||
| 196 | local obj = {}; | ||
| 197 | obj.pay_id = tostring(os.time())..math.random(10000,99999); | ||
| 198 | obj.url_callback = "http://www.baidu.com"; | ||
| 199 | obj.zfb_url_callback = ""; | ||
| 200 | obj.wx_url_callback = ""; | ||
| 201 | obj.peng_bo_shi_token = "1"; | ||
| 202 | onGetPayIDSuccessFun(json.encode(obj)); | ||
| 203 | end | ||
| 204 | end | ||
| 205 | |||
| 206 | return ShopModel | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | ---------------- | ||
| 2 | --- Lua 5.1/5.2 compatibility | ||
| 3 | -- Ensures that `table.pack` and `package.searchpath` are available | ||
| 4 | -- for Lua 5.1 and LuaJIT. | ||
| 5 | -- The exported function `load` is Lua 5.2 compatible. | ||
| 6 | -- `compat.setfenv` and `compat.getfenv` are available for Lua 5.2, although | ||
| 7 | -- they are not always guaranteed to work. | ||
| 8 | -- @module pl.compat | ||
| 9 | |||
| 10 | local compat = {} | ||
| 11 | |||
| 12 | compat.lua51 = _VERSION == 'Lua 5.1' | ||
| 13 | |||
| 14 | --- execute a shell command. | ||
| 15 | -- This is a compatibility function that returns the same for Lua 5.1 and Lua 5.2 | ||
| 16 | -- @param cmd a shell command | ||
| 17 | -- @return true if successful | ||
| 18 | -- @return actual return code | ||
| 19 | function compat.execute (cmd) | ||
| 20 | local res1,res2,res2 = os.execute(cmd) | ||
| 21 | if compat.lua51 then | ||
| 22 | return res1==0,res1 | ||
| 23 | else | ||
| 24 | return not not res1,res2 | ||
| 25 | end | ||
| 26 | end | ||
| 27 | |||
| 28 | ---------------- | ||
| 29 | -- Load Lua code as a text or binary chunk. | ||
| 30 | -- @param ld code string or loader | ||
| 31 | -- @param[opt] source name of chunk for errors | ||
| 32 | -- @param[opt] mode 'b', 't' or 'bt' | ||
| 33 | -- @param[opt] env environment to load the chunk in | ||
| 34 | -- @function compat.load | ||
| 35 | |||
| 36 | --------------- | ||
| 37 | -- Get environment of a function. | ||
| 38 | -- With Lua 5.2, may return nil for a function with no global references! | ||
| 39 | -- Based on code by [Sergey Rozhenko](http://lua-users.org/lists/lua-l/2010-06/msg00313.html) | ||
| 40 | -- @param f a function or a call stack reference | ||
| 41 | -- @function compat.setfenv | ||
| 42 | |||
| 43 | --------------- | ||
| 44 | -- Set environment of a function | ||
| 45 | -- @param f a function or a call stack reference | ||
| 46 | -- @param env a table that becomes the new environment of `f` | ||
| 47 | -- @function compat.setfenv | ||
| 48 | |||
| 49 | if compat.lua51 then -- define Lua 5.2 style load() | ||
| 50 | if not tostring(assert):match 'builtin' then -- but LuaJIT's load _is_ compatible | ||
| 51 | local lua51_load = load | ||
| 52 | function compat.load(str,src,mode,env) | ||
| 53 | local chunk,err | ||
| 54 | if type(str) == 'string' then | ||
| 55 | if str:byte(1) == 27 and not (mode or 'bt'):find 'b' then | ||
| 56 | return nil,"attempt to load a binary chunk" | ||
| 57 | end | ||
| 58 | chunk,err = loadstring(str,src) | ||
| 59 | else | ||
| 60 | chunk,err = lua51_load(str,src) | ||
| 61 | end | ||
| 62 | if chunk and env then setfenv(chunk,env) end | ||
| 63 | return chunk,err | ||
| 64 | end | ||
| 65 | else | ||
| 66 | compat.load = load | ||
| 67 | end | ||
| 68 | compat.setfenv, compat.getfenv = setfenv, getfenv | ||
| 69 | else | ||
| 70 | compat.load = load | ||
| 71 | -- setfenv/getfenv replacements for Lua 5.2 | ||
| 72 | -- by Sergey Rozhenko | ||
| 73 | -- http://lua-users.org/lists/lua-l/2010-06/msg00313.html | ||
| 74 | -- Roberto Ierusalimschy notes that it is possible for getfenv to return nil | ||
| 75 | -- in the case of a function with no globals: | ||
| 76 | -- http://lua-users.org/lists/lua-l/2010-06/msg00315.html | ||
| 77 | function compat.setfenv(f, t) | ||
| 78 | f = (type(f) == 'function' and f or debug.getinfo(f + 1, 'f').func) | ||
| 79 | local name | ||
| 80 | local up = 0 | ||
| 81 | repeat | ||
| 82 | up = up + 1 | ||
| 83 | name = debug.getupvalue(f, up) | ||
| 84 | until name == '_ENV' or name == nil | ||
| 85 | if name then | ||
| 86 | debug.upvaluejoin(f, up, function() return name end, 1) -- use unique upvalue | ||
| 87 | debug.setupvalue(f, up, t) | ||
| 88 | end | ||
| 89 | if f ~= 0 then return f end | ||
| 90 | end | ||
| 91 | |||
| 92 | function compat.getfenv(f) | ||
| 93 | local f = f or 0 | ||
| 94 | f = (type(f) == 'function' and f or debug.getinfo(f + 1, 'f').func) | ||
| 95 | local name, val | ||
| 96 | local up = 0 | ||
| 97 | repeat | ||
| 98 | up = up + 1 | ||
| 99 | name, val = debug.getupvalue(f, up) | ||
| 100 | until name == '_ENV' or name == nil | ||
| 101 | return val | ||
| 102 | end | ||
| 103 | end | ||
| 104 | |||
| 105 | --- Lua 5.2 Functions Available for 5.1 | ||
| 106 | -- @section lua52 | ||
| 107 | |||
| 108 | --- pack an argument list into a table. | ||
| 109 | -- @param ... any arguments | ||
| 110 | -- @return a table with field n set to the length | ||
| 111 | -- @return the length | ||
| 112 | -- @function table.pack | ||
| 113 | if not table.pack then | ||
| 114 | function table.pack (...) | ||
| 115 | return {n=select('#',...); ...} | ||
| 116 | end | ||
| 117 | end | ||
| 118 | |||
| 119 | ------ | ||
| 120 | -- return the full path where a Lua module name would be matched. | ||
| 121 | -- @param mod module name, possibly dotted | ||
| 122 | -- @param path a path in the same form as package.path or package.cpath | ||
| 123 | -- @see path.package_path | ||
| 124 | -- @function package.searchpath | ||
| 125 | if not package.searchpath then | ||
| 126 | local sep = package.config:sub(1,1) | ||
| 127 | function package.searchpath (mod,path) | ||
| 128 | mod = mod:gsub('%.',sep) | ||
| 129 | for m in path:gmatch('[^;]+') do | ||
| 130 | local nm = m:gsub('?',mod) | ||
| 131 | local f = io.open(nm,'r') | ||
| 132 | if f then f:close(); return nm end | ||
| 133 | end | ||
| 134 | end | ||
| 135 | end | ||
| 136 | |||
| 137 | return compat |
| 1 | --- Generally useful routines. | ||
| 2 | -- See @{01-introduction.md.Generally_useful_functions|the Guide}. | ||
| 3 | -- @module pl.utils | ||
| 4 | local format,gsub,byte = string.format,string.gsub,string.byte | ||
| 5 | local compat = import '.compat' | ||
| 6 | local clock = os.clock | ||
| 7 | local stdout = io.stdout | ||
| 8 | local append = table.insert | ||
| 9 | local unpack = rawget(_G,'unpack') or rawget(table,'unpack') | ||
| 10 | |||
| 11 | local collisions = {} | ||
| 12 | |||
| 13 | local utils = { | ||
| 14 | _VERSION = "1.2.1", | ||
| 15 | lua51 = compat.lua51, | ||
| 16 | setfenv = compat.setfenv, | ||
| 17 | getfenv = compat.getfenv, | ||
| 18 | load = compat.load, | ||
| 19 | execute = compat.execute, | ||
| 20 | dir_separator = _G.package.config:sub(1,1), | ||
| 21 | unpack = unpack | ||
| 22 | } | ||
| 23 | |||
| 24 | --- end this program gracefully. | ||
| 25 | -- @param code The exit code or a message to be printed | ||
| 26 | -- @param ... extra arguments for message's format' | ||
| 27 | -- @see utils.fprintf | ||
| 28 | function utils.quit(code,...) | ||
| 29 | if type(code) == 'string' then | ||
| 30 | utils.fprintf(io.stderr,code,...) | ||
| 31 | code = -1 | ||
| 32 | else | ||
| 33 | utils.fprintf(io.stderr,...) | ||
| 34 | end | ||
| 35 | io.stderr:write('\n') | ||
| 36 | os.exit(code) | ||
| 37 | end | ||
| 38 | |||
| 39 | --- print an arbitrary number of arguments using a format. | ||
| 40 | -- @param fmt The format (see string.format) | ||
| 41 | -- @param ... Extra arguments for format | ||
| 42 | function utils.printf(fmt,...) | ||
| 43 | utils.assert_string(1,fmt) | ||
| 44 | utils.fprintf(stdout,fmt,...) | ||
| 45 | end | ||
| 46 | |||
| 47 | --- write an arbitrary number of arguments to a file using a format. | ||
| 48 | -- @param f File handle to write to. | ||
| 49 | -- @param fmt The format (see string.format). | ||
| 50 | -- @param ... Extra arguments for format | ||
| 51 | function utils.fprintf(f,fmt,...) | ||
| 52 | utils.assert_string(2,fmt) | ||
| 53 | f:write(format(fmt,...)) | ||
| 54 | end | ||
| 55 | |||
| 56 | local function import_symbol(T,k,v,libname) | ||
| 57 | local key = rawget(T,k) | ||
| 58 | -- warn about collisions! | ||
| 59 | if key and k ~= '_M' and k ~= '_NAME' and k ~= '_PACKAGE' and k ~= '_VERSION' then | ||
| 60 | utils.printf("warning: '%s.%s' overrides existing symbol\n",libname,k) | ||
| 61 | end | ||
| 62 | rawset(T,k,v) | ||
| 63 | end | ||
| 64 | |||
| 65 | local function lookup_lib(T,t) | ||
| 66 | for k,v in pairs(T) do | ||
| 67 | if v == t then return k end | ||
| 68 | end | ||
| 69 | return '?' | ||
| 70 | end | ||
| 71 | |||
| 72 | local already_imported = {} | ||
| 73 | |||
| 74 | --- take a table and 'inject' it into the local namespace. | ||
| 75 | -- @param t The Table | ||
| 76 | -- @param T An optional destination table (defaults to callers environment) | ||
| 77 | function utils.import(t,T) | ||
| 78 | T = T or _G | ||
| 79 | t = t or utils | ||
| 80 | if type(t) == 'string' then | ||
| 81 | t = require (t) | ||
| 82 | end | ||
| 83 | local libname = lookup_lib(T,t) | ||
| 84 | if already_imported[t] then return end | ||
| 85 | already_imported[t] = libname | ||
| 86 | for k,v in pairs(t) do | ||
| 87 | import_symbol(T,k,v,libname) | ||
| 88 | end | ||
| 89 | end | ||
| 90 | |||
| 91 | utils.patterns = { | ||
| 92 | FLOAT = '[%+%-%d]%d*%.?%d*[eE]?[%+%-]?%d*', | ||
| 93 | INTEGER = '[+%-%d]%d*', | ||
| 94 | IDEN = '[%a_][%w_]*', | ||
| 95 | FILE = '[%a%.\\][:%][%w%._%-\\]*' | ||
| 96 | } | ||
| 97 | |||
| 98 | --- escape any 'magic' characters in a string | ||
| 99 | -- @param s The input string | ||
| 100 | function utils.escape(s) | ||
| 101 | utils.assert_string(1,s) | ||
| 102 | return (s:gsub('[%-%.%+%[%]%(%)%$%^%%%?%*]','%%%1')) | ||
| 103 | end | ||
| 104 | |||
| 105 | --- return either of two values, depending on a condition. | ||
| 106 | -- @param cond A condition | ||
| 107 | -- @param value1 Value returned if cond is true | ||
| 108 | -- @param value2 Value returned if cond is false (can be optional) | ||
| 109 | function utils.choose(cond,value1,value2) | ||
| 110 | if cond then return value1 | ||
| 111 | else return value2 | ||
| 112 | end | ||
| 113 | end | ||
| 114 | |||
| 115 | local raise | ||
| 116 | |||
| 117 | --- return the contents of a file as a string | ||
| 118 | -- @param filename The file path | ||
| 119 | -- @param is_bin open in binary mode | ||
| 120 | -- @return file contents | ||
| 121 | function utils.readfile(filename,is_bin) | ||
| 122 | local mode = is_bin and 'b' or '' | ||
| 123 | utils.assert_string(1,filename) | ||
| 124 | local f,err = io.open(filename,'r'..mode) | ||
| 125 | if not f then return utils.raise (err) end | ||
| 126 | local res,err = f:read('*a') | ||
| 127 | f:close() | ||
| 128 | if not res then return raise (err) end | ||
| 129 | return res | ||
| 130 | end | ||
| 131 | |||
| 132 | --- write a string to a file | ||
| 133 | -- @param filename The file path | ||
| 134 | -- @param str The string | ||
| 135 | -- @return true or nil | ||
| 136 | -- @return error message | ||
| 137 | -- @raise error if filename or str aren't strings | ||
| 138 | function utils.writefile(filename,str) | ||
| 139 | utils.assert_string(1,filename) | ||
| 140 | utils.assert_string(2,str) | ||
| 141 | local f,err = io.open(filename,'w') | ||
| 142 | if not f then return raise(err) end | ||
| 143 | f:write(str) | ||
| 144 | f:close() | ||
| 145 | return true | ||
| 146 | end | ||
| 147 | |||
| 148 | --- return the contents of a file as a list of lines | ||
| 149 | -- @param filename The file path | ||
| 150 | -- @return file contents as a table | ||
| 151 | -- @raise errror if filename is not a string | ||
| 152 | function utils.readlines(filename) | ||
| 153 | utils.assert_string(1,filename) | ||
| 154 | local f,err = io.open(filename,'r') | ||
| 155 | if not f then return raise(err) end | ||
| 156 | local res = {} | ||
| 157 | for line in f:lines() do | ||
| 158 | append(res,line) | ||
| 159 | end | ||
| 160 | f:close() | ||
| 161 | return res | ||
| 162 | end | ||
| 163 | |||
| 164 | --- split a string into a list of strings separated by a delimiter. | ||
| 165 | -- @param s The input string | ||
| 166 | -- @param re A Lua string pattern; defaults to '%s+' | ||
| 167 | -- @param plain don't use Lua patterns | ||
| 168 | -- @param n optional maximum number of splits | ||
| 169 | -- @return a list-like table | ||
| 170 | -- @raise error if s is not a string | ||
| 171 | function utils.split(s,re,plain,n) | ||
| 172 | utils.assert_string(1,s) | ||
| 173 | local find,sub,append = string.find, string.sub, table.insert | ||
| 174 | local i1,ls = 1,{} | ||
| 175 | if not re then re = '%s+' end | ||
| 176 | if re == '' then return {s} end | ||
| 177 | while true do | ||
| 178 | local i2,i3 = find(s,re,i1,plain) | ||
| 179 | if not i2 then | ||
| 180 | local last = sub(s,i1) | ||
| 181 | if last ~= '' then append(ls,last) end | ||
| 182 | if #ls == 1 and ls[1] == '' then | ||
| 183 | return {} | ||
| 184 | else | ||
| 185 | return ls | ||
| 186 | end | ||
| 187 | end | ||
| 188 | append(ls,sub(s,i1,i2-1)) | ||
| 189 | if n and #ls == n then | ||
| 190 | ls[#ls] = sub(s,i1) | ||
| 191 | return ls | ||
| 192 | end | ||
| 193 | i1 = i3+1 | ||
| 194 | end | ||
| 195 | end | ||
| 196 | |||
| 197 | --- split a string into a number of values. | ||
| 198 | -- @param s the string | ||
| 199 | -- @param re the delimiter, default space | ||
| 200 | -- @return n values | ||
| 201 | -- @usage first,next = splitv('jane:doe',':') | ||
| 202 | -- @see split | ||
| 203 | function utils.splitv (s,re) | ||
| 204 | return unpack(utils.split(s,re)) | ||
| 205 | end | ||
| 206 | |||
| 207 | --- convert an array of values to strings. | ||
| 208 | -- @param t a list-like table | ||
| 209 | -- @param temp buffer to use, otherwise allocate | ||
| 210 | -- @param tostr custom tostring function, called with (value,index). | ||
| 211 | -- Otherwise use `tostring` | ||
| 212 | -- @return the converted buffer | ||
| 213 | function utils.array_tostring (t,temp,tostr) | ||
| 214 | temp, tostr = temp or {}, tostr or tostring | ||
| 215 | for i = 1,#t do | ||
| 216 | temp[i] = tostr(t[i],i) | ||
| 217 | end | ||
| 218 | return temp | ||
| 219 | end | ||
| 220 | |||
| 221 | --- execute a shell command and return the output. | ||
| 222 | -- This function redirects the output to tempfiles and returns the content of those files. | ||
| 223 | -- @param cmd a shell command | ||
| 224 | -- @param bin boolean, if true, read output as binary file | ||
| 225 | -- @return true if successful | ||
| 226 | -- @return actual return code | ||
| 227 | -- @return stdout output (string) | ||
| 228 | -- @return errout output (string) | ||
| 229 | function utils.executeex(cmd, bin) | ||
| 230 | local mode | ||
| 231 | local outfile = os.tmpname() | ||
| 232 | local errfile = os.tmpname() | ||
| 233 | |||
| 234 | if utils.dir_separator == '\\' then | ||
| 235 | outfile = os.getenv('TEMP')..outfile | ||
| 236 | errfile = os.getenv('TEMP')..errfile | ||
| 237 | end | ||
| 238 | cmd = cmd .. [[ >"]]..outfile..[[" 2>"]]..errfile..[["]] | ||
| 239 | |||
| 240 | local success, retcode = utils.execute(cmd) | ||
| 241 | local outcontent = utils.readfile(outfile, bin) | ||
| 242 | local errcontent = utils.readfile(errfile, bin) | ||
| 243 | os.remove(outfile) | ||
| 244 | os.remove(errfile) | ||
| 245 | return success, retcode, (outcontent or ""), (errcontent or "") | ||
| 246 | end | ||
| 247 | |||
| 248 | --- 'memoize' a function (cache returned value for next call). | ||
| 249 | -- This is useful if you have a function which is relatively expensive, | ||
| 250 | -- but you don't know in advance what values will be required, so | ||
| 251 | -- building a table upfront is wasteful/impossible. | ||
| 252 | -- @param func a function of at least one argument | ||
| 253 | -- @return a function with at least one argument, which is used as the key. | ||
| 254 | function utils.memoize(func) | ||
| 255 | return setmetatable({}, { | ||
| 256 | __index = function(self, k, ...) | ||
| 257 | local v = func(k,...) | ||
| 258 | self[k] = v | ||
| 259 | return v | ||
| 260 | end, | ||
| 261 | __call = function(self, k) return self[k] end | ||
| 262 | }) | ||
| 263 | end | ||
| 264 | |||
| 265 | |||
| 266 | utils.stdmt = { | ||
| 267 | List = {_name='List'}, Map = {_name='Map'}, | ||
| 268 | Set = {_name='Set'}, MultiMap = {_name='MultiMap'} | ||
| 269 | } | ||
| 270 | |||
| 271 | local _function_factories = {} | ||
| 272 | |||
| 273 | --- associate a function factory with a type. | ||
| 274 | -- A function factory takes an object of the given type and | ||
| 275 | -- returns a function for evaluating it | ||
| 276 | -- @tab mt metatable | ||
| 277 | -- @func fun a callable that returns a function | ||
| 278 | function utils.add_function_factory (mt,fun) | ||
| 279 | _function_factories[mt] = fun | ||
| 280 | end | ||
| 281 | |||
| 282 | local function _string_lambda(f) | ||
| 283 | local raise = utils.raise | ||
| 284 | if f:find '^|' or f:find '_' then | ||
| 285 | local args,body = f:match '|([^|]*)|(.+)' | ||
| 286 | if f:find '_' then | ||
| 287 | args = '_' | ||
| 288 | body = f | ||
| 289 | else | ||
| 290 | if not args then return raise 'bad string lambda' end | ||
| 291 | end | ||
| 292 | local fstr = 'return function('..args..') return '..body..' end' | ||
| 293 | local fn,err = utils.load(fstr) | ||
| 294 | if not fn then return raise(err) end | ||
| 295 | fn = fn() | ||
| 296 | return fn | ||
| 297 | else return raise 'not a string lambda' | ||
| 298 | end | ||
| 299 | end | ||
| 300 | |||
| 301 | --- an anonymous function as a string. This string is either of the form | ||
| 302 | -- '|args| expression' or is a function of one argument, '_' | ||
| 303 | -- @param lf function as a string | ||
| 304 | -- @return a function | ||
| 305 | -- @usage string_lambda '|x|x+1' (2) == 3 | ||
| 306 | -- @usage string_lambda '_+1 (2) == 3 | ||
| 307 | -- @function utils.string_lambda | ||
| 308 | utils.string_lambda = utils.memoize(_string_lambda) | ||
| 309 | |||
| 310 | local ops | ||
| 311 | |||
| 312 | --- process a function argument. | ||
| 313 | -- This is used throughout Penlight and defines what is meant by a function: | ||
| 314 | -- Something that is callable, or an operator string as defined by <code>pl.operator</code>, | ||
| 315 | -- such as '>' or '#'. If a function factory has been registered for the type, it will | ||
| 316 | -- be called to get the function. | ||
| 317 | -- @param idx argument index | ||
| 318 | -- @param f a function, operator string, or callable object | ||
| 319 | -- @param msg optional error message | ||
| 320 | -- @return a callable | ||
| 321 | -- @raise if idx is not a number or if f is not callable | ||
| 322 | function utils.function_arg (idx,f,msg) | ||
| 323 | utils.assert_arg(1,idx,'number') | ||
| 324 | local tp = type(f) | ||
| 325 | if tp == 'function' then return f end -- no worries! | ||
| 326 | -- ok, a string can correspond to an operator (like '==') | ||
| 327 | if tp == 'string' then | ||
| 328 | if not ops then ops = require 'pl.operator'.optable end | ||
| 329 | local fn = ops[f] | ||
| 330 | if fn then return fn end | ||
| 331 | local fn, err = utils.string_lambda(f) | ||
| 332 | if not fn then error(err..': '..f) end | ||
| 333 | return fn | ||
| 334 | elseif tp == 'table' or tp == 'userdata' then | ||
| 335 | local mt = getmetatable(f) | ||
| 336 | if not mt then error('not a callable object',2) end | ||
| 337 | local ff = _function_factories[mt] | ||
| 338 | if not ff then | ||
| 339 | if not mt.__call then error('not a callable object',2) end | ||
| 340 | return f | ||
| 341 | else | ||
| 342 | return ff(f) -- we have a function factory for this type! | ||
| 343 | end | ||
| 344 | end | ||
| 345 | if not msg then msg = " must be callable" end | ||
| 346 | if idx > 0 then | ||
| 347 | error("argument "..idx..": "..msg,2) | ||
| 348 | else | ||
| 349 | error(msg,2) | ||
| 350 | end | ||
| 351 | end | ||
| 352 | |||
| 353 | --- bind the first argument of the function to a value. | ||
| 354 | -- @param fn a function of at least two values (may be an operator string) | ||
| 355 | -- @param p a value | ||
| 356 | -- @return a function such that f(x) is fn(p,x) | ||
| 357 | -- @raise same as @{function_arg} | ||
| 358 | -- @see func.bind1 | ||
| 359 | function utils.bind1 (fn,p) | ||
| 360 | fn = utils.function_arg(1,fn) | ||
| 361 | return function(...) return fn(p,...) end | ||
| 362 | end | ||
| 363 | |||
| 364 | --- bind the second argument of the function to a value. | ||
| 365 | -- @param fn a function of at least two values (may be an operator string) | ||
| 366 | -- @param p a value | ||
| 367 | -- @return a function such that f(x) is fn(x,p) | ||
| 368 | -- @raise same as @{function_arg} | ||
| 369 | function utils.bind2 (fn,p) | ||
| 370 | fn = utils.function_arg(1,fn) | ||
| 371 | return function(x,...) return fn(x,p,...) end | ||
| 372 | end | ||
| 373 | |||
| 374 | |||
| 375 | --- assert that the given argument is in fact of the correct type. | ||
| 376 | -- @param n argument index | ||
| 377 | -- @param val the value | ||
| 378 | -- @param tp the type | ||
| 379 | -- @param verify an optional verfication function | ||
| 380 | -- @param msg an optional custom message | ||
| 381 | -- @param lev optional stack position for trace, default 2 | ||
| 382 | -- @raise if the argument n is not the correct type | ||
| 383 | -- @usage assert_arg(1,t,'table') | ||
| 384 | -- @usage assert_arg(n,val,'string',path.isdir,'not a directory') | ||
| 385 | function utils.assert_arg (n,val,tp,verify,msg,lev) | ||
| 386 | if type(val) ~= tp then | ||
| 387 | error(("argument %d expected a '%s', got a '%s'"):format(n,tp,type(val)),lev or 2) | ||
| 388 | end | ||
| 389 | if verify and not verify(val) then | ||
| 390 | error(("argument %d: '%s' %s"):format(n,val,msg),lev or 2) | ||
| 391 | end | ||
| 392 | end | ||
| 393 | |||
| 394 | --- assert the common case that the argument is a string. | ||
| 395 | -- @param n argument index | ||
| 396 | -- @param val a value that must be a string | ||
| 397 | -- @raise val must be a string | ||
| 398 | function utils.assert_string (n,val) | ||
| 399 | utils.assert_arg(n,val,'string',nil,nil,3) | ||
| 400 | end | ||
| 401 | |||
| 402 | local err_mode = 'default' | ||
| 403 | |||
| 404 | --- control the error strategy used by Penlight. | ||
| 405 | -- Controls how <code>utils.raise</code> works; the default is for it | ||
| 406 | -- to return nil and the error string, but if the mode is 'error' then | ||
| 407 | -- it will throw an error. If mode is 'quit' it will immediately terminate | ||
| 408 | -- the program. | ||
| 409 | -- @param mode - either 'default', 'quit' or 'error' | ||
| 410 | -- @see utils.raise | ||
| 411 | function utils.on_error (mode) | ||
| 412 | if ({['default'] = 1, ['quit'] = 2, ['error'] = 3})[mode] then | ||
| 413 | err_mode = mode | ||
| 414 | else | ||
| 415 | -- fail loudly | ||
| 416 | if err_mode == 'default' then err_mode = 'error' end | ||
| 417 | utils.raise("Bad argument expected string; 'default', 'quit', or 'error'. Got '"..tostring(mode).."'") | ||
| 418 | end | ||
| 419 | end | ||
| 420 | |||
| 421 | --- used by Penlight functions to return errors. Its global behaviour is controlled | ||
| 422 | -- by <code>utils.on_error</code> | ||
| 423 | -- @param err the error string. | ||
| 424 | -- @see utils.on_error | ||
| 425 | function utils.raise (err) | ||
| 426 | if err_mode == 'default' then return nil,err | ||
| 427 | elseif err_mode == 'quit' then utils.quit(err) | ||
| 428 | else error(err,2) | ||
| 429 | end | ||
| 430 | end | ||
| 431 | |||
| 432 | --- is the object of the specified type?. | ||
| 433 | -- If the type is a string, then use type, otherwise compare with metatable | ||
| 434 | -- @param obj An object to check | ||
| 435 | -- @param tp String of what type it should be | ||
| 436 | function utils.is_type (obj,tp) | ||
| 437 | if type(tp) == 'string' then return type(obj) == tp end | ||
| 438 | local mt = getmetatable(obj) | ||
| 439 | return tp == mt | ||
| 440 | end | ||
| 441 | |||
| 442 | raise = utils.raise | ||
| 443 | |||
| 444 | --- load a code string or bytecode chunk. | ||
| 445 | -- @param code Lua code as a string or bytecode | ||
| 446 | -- @param name for source errors | ||
| 447 | -- @param mode kind of chunk, 't' for text, 'b' for bytecode, 'bt' for all (default) | ||
| 448 | -- @param env the environment for the new chunk (default nil) | ||
| 449 | -- @return compiled chunk | ||
| 450 | -- @return error message (chunk is nil) | ||
| 451 | -- @function utils.load | ||
| 452 | |||
| 453 | --------------- | ||
| 454 | -- Get environment of a function. | ||
| 455 | -- With Lua 5.2, may return nil for a function with no global references! | ||
| 456 | -- Based on code by [Sergey Rozhenko](http://lua-users.org/lists/lua-l/2010-06/msg00313.html) | ||
| 457 | -- @param f a function or a call stack reference | ||
| 458 | -- @function utils.setfenv | ||
| 459 | |||
| 460 | --------------- | ||
| 461 | -- Set environment of a function | ||
| 462 | -- @param f a function or a call stack reference | ||
| 463 | -- @param env a table that becomes the new environment of `f` | ||
| 464 | -- @function utils.setfenv | ||
| 465 | |||
| 466 | --- execute a shell command. | ||
| 467 | -- This is a compatibility function that returns the same for Lua 5.1 and Lua 5.2 | ||
| 468 | -- @param cmd a shell command | ||
| 469 | -- @return true if successful | ||
| 470 | -- @return actual return code | ||
| 471 | -- @function utils.execute | ||
| 472 | |||
| 473 | return utils | ||
| 474 | |||
| 475 |
| 1 | --- XML LOM Utilities. | ||
| 2 | -- | ||
| 3 | -- This implements some useful things on [LOM](http://matthewwild.co.uk/projects/luaexpat/lom.html) documents, such as returned by `lxp.lom.parse`. | ||
| 4 | -- In particular, it can convert LOM back into XML text, with optional pretty-printing control. | ||
| 5 | -- It is s based on stanza.lua from [Prosody](http://hg.prosody.im/trunk/file/4621c92d2368/util/stanza.lua) | ||
| 6 | -- | ||
| 7 | -- > d = xml.parse "<nodes><node id='1'>alice</node></nodes>" | ||
| 8 | -- > = d | ||
| 9 | -- <nodes><node id='1'>alice</node></nodes> | ||
| 10 | -- > = xml.tostring(d,'',' ') | ||
| 11 | -- <nodes> | ||
| 12 | -- <node id='1'>alice</node> | ||
| 13 | -- </nodes> | ||
| 14 | -- | ||
| 15 | -- Can be used as a lightweight one-stop-shop for simple XML processing; a simple XML parser is included | ||
| 16 | -- but the default is to use `lxp.lom` if it can be found. | ||
| 17 | -- <pre> | ||
| 18 | -- Prosody IM | ||
| 19 | -- Copyright (C) 2008-2010 Matthew Wild | ||
| 20 | -- Copyright (C) 2008-2010 Waqas Hussain-- | ||
| 21 | -- classic Lua XML parser by Roberto Ierusalimschy. | ||
| 22 | -- modified to output LOM format. | ||
| 23 | -- http://lua-users.org/wiki/LuaXml | ||
| 24 | -- </pre> | ||
| 25 | -- See @{06-data.md.XML|the Guide} | ||
| 26 | -- | ||
| 27 | -- Dependencies: `pl.utils` | ||
| 28 | -- | ||
| 29 | -- Soft Dependencies: `lxp.lom` (fallback is to use basic Lua parser) | ||
| 30 | -- @module pl.xml | ||
| 31 | |||
| 32 | local utils = import '.utils' | ||
| 33 | local split = utils.split; | ||
| 34 | local t_insert = table.insert; | ||
| 35 | local t_concat = table.concat; | ||
| 36 | local t_remove = table.remove; | ||
| 37 | local s_format = string.format; | ||
| 38 | local s_match = string.match; | ||
| 39 | local tostring = tostring; | ||
| 40 | local setmetatable = setmetatable; | ||
| 41 | local getmetatable = getmetatable; | ||
| 42 | local pairs = pairs; | ||
| 43 | local ipairs = ipairs; | ||
| 44 | local type = type; | ||
| 45 | local next = next; | ||
| 46 | local print = print; | ||
| 47 | local unpack = utils.unpack; | ||
| 48 | local s_gsub = string.gsub; | ||
| 49 | local s_char = string.char; | ||
| 50 | local s_find = string.find; | ||
| 51 | local os = os; | ||
| 52 | local pcall,require,io = pcall,require,io | ||
| 53 | |||
| 54 | local _M = {} | ||
| 55 | local Doc = { __type = "doc" }; | ||
| 56 | Doc.__index = Doc; | ||
| 57 | |||
| 58 | --- create a new document node. | ||
| 59 | -- @param tag the tag name | ||
| 60 | -- @param attr optional attributes (table of name-value pairs) | ||
| 61 | function _M.new(tag, attr) | ||
| 62 | local doc = { tag = tag, attr = attr or {}, last_add = {}}; | ||
| 63 | return setmetatable(doc, Doc); | ||
| 64 | end | ||
| 65 | |||
| 66 | --- parse an XML document. By default, this uses lxp.lom.parse, but | ||
| 67 | -- falls back to basic_parse, or if use_basic is true | ||
| 68 | -- @param text_or_file file or string representation | ||
| 69 | -- @param is_file whether text_or_file is a file name or not | ||
| 70 | -- @param use_basic do a basic parse | ||
| 71 | -- @return a parsed LOM document with the document metatatables set | ||
| 72 | -- @return nil, error the error can either be a file error or a parse error | ||
| 73 | function _M.parse(text_or_file, is_file, use_basic) | ||
| 74 | local parser,status,lom | ||
| 75 | if use_basic then parser = _M.basic_parse | ||
| 76 | else | ||
| 77 | status,lom = pcall(require,'lxp.lom') | ||
| 78 | if not status then parser = _M.basic_parse else parser = lom.parse end | ||
| 79 | end | ||
| 80 | if is_file then | ||
| 81 | local f,err = io.open(text_or_file) | ||
| 82 | if not f then return nil,err end | ||
| 83 | text_or_file = f:read '*a' | ||
| 84 | f:close() | ||
| 85 | end | ||
| 86 | local doc,err = parser(text_or_file) | ||
| 87 | if not doc then return nil,err end | ||
| 88 | if lom then | ||
| 89 | _M.walk(doc,false,function(_,d) | ||
| 90 | setmetatable(d,Doc) | ||
| 91 | end) | ||
| 92 | end | ||
| 93 | return doc | ||
| 94 | end | ||
| 95 | |||
| 96 | ---- convenient function to add a document node, This updates the last inserted position. | ||
| 97 | -- @param tag a tag name | ||
| 98 | -- @param attrs optional set of attributes (name-string pairs) | ||
| 99 | function Doc:addtag(tag, attrs) | ||
| 100 | local s = _M.new(tag, attrs); | ||
| 101 | (self.last_add[#self.last_add] or self):add_direct_child(s); | ||
| 102 | t_insert(self.last_add, s); | ||
| 103 | return self; | ||
| 104 | end | ||
| 105 | |||
| 106 | --- convenient function to add a text node. This updates the last inserted position. | ||
| 107 | -- @param text a string | ||
| 108 | function Doc:text(text) | ||
| 109 | (self.last_add[#self.last_add] or self):add_direct_child(text); | ||
| 110 | return self; | ||
| 111 | end | ||
| 112 | |||
| 113 | ---- go up one level in a document | ||
| 114 | function Doc:up() | ||
| 115 | t_remove(self.last_add); | ||
| 116 | return self; | ||
| 117 | end | ||
| 118 | |||
| 119 | function Doc:reset() | ||
| 120 | local last_add = self.last_add; | ||
| 121 | for i = 1,#last_add do | ||
| 122 | last_add[i] = nil; | ||
| 123 | end | ||
| 124 | return self; | ||
| 125 | end | ||
| 126 | |||
| 127 | --- append a child to a document directly. | ||
| 128 | -- @param child a child node (either text or a document) | ||
| 129 | function Doc:add_direct_child(child) | ||
| 130 | t_insert(self, child); | ||
| 131 | end | ||
| 132 | |||
| 133 | --- append a child to a document at the last element added | ||
| 134 | -- @param child a child node (either text or a document) | ||
| 135 | function Doc:add_child(child) | ||
| 136 | (self.last_add[#self.last_add] or self):add_direct_child(child); | ||
| 137 | return self; | ||
| 138 | end | ||
| 139 | |||
| 140 | --accessing attributes: useful not to have to expose implementation (attr) | ||
| 141 | --but also can allow attr to be nil in any future optimizations | ||
| 142 | |||
| 143 | --- set attributes of a document node. | ||
| 144 | -- @param t a table containing attribute/value pairs | ||
| 145 | function Doc:set_attribs (t) | ||
| 146 | for k,v in pairs(t) do | ||
| 147 | self.attr[k] = v | ||
| 148 | end | ||
| 149 | end | ||
| 150 | |||
| 151 | --- set a single attribute of a document node. | ||
| 152 | -- @param a attribute | ||
| 153 | -- @param v its value | ||
| 154 | function Doc:set_attrib(a,v) | ||
| 155 | self.attr[a] = v | ||
| 156 | end | ||
| 157 | |||
| 158 | --- access the attributes of a document node. | ||
| 159 | function Doc:get_attribs() | ||
| 160 | return self.attr | ||
| 161 | end | ||
| 162 | |||
| 163 | local function is_text(s) return type(s) == 'string' end | ||
| 164 | |||
| 165 | --- function to create an element with a given tag name and a set of children. | ||
| 166 | -- @param tag a tag name | ||
| 167 | -- @param items either text or a table where the hash part is the attributes and the list part is the children. | ||
| 168 | function _M.elem(tag,items) | ||
| 169 | local s = _M.new(tag) | ||
| 170 | if is_text(items) then items = {items} end | ||
| 171 | if _M.is_tag(items) then | ||
| 172 | t_insert(s,items) | ||
| 173 | elseif type(items) == 'table' then | ||
| 174 | for k,v in pairs(items) do | ||
| 175 | if is_text(k) then | ||
| 176 | s.attr[k] = v | ||
| 177 | t_insert(s.attr,k) | ||
| 178 | else | ||
| 179 | s[k] = v | ||
| 180 | end | ||
| 181 | end | ||
| 182 | end | ||
| 183 | return s | ||
| 184 | end | ||
| 185 | |||
| 186 | --- given a list of names, return a number of element constructors. | ||
| 187 | -- @param list a list of names, or a comma-separated string. | ||
| 188 | -- @usage local parent,children = doc.tags 'parent,children' <br> | ||
| 189 | -- doc = parent {child 'one', child 'two'} | ||
| 190 | function _M.tags(list) | ||
| 191 | local ctors = {} | ||
| 192 | local elem = _M.elem | ||
| 193 | if is_text(list) then list = split(list,'%s*,%s*') end | ||
| 194 | for _,tag in ipairs(list) do | ||
| 195 | local ctor = function(items) return _M.elem(tag,items) end | ||
| 196 | t_insert(ctors,ctor) | ||
| 197 | end | ||
| 198 | return unpack(ctors) | ||
| 199 | end | ||
| 200 | |||
| 201 | local templ_cache = {} | ||
| 202 | |||
| 203 | local function template_cache (templ) | ||
| 204 | if is_text(templ) then | ||
| 205 | if templ_cache[templ] then | ||
| 206 | templ = templ_cache[templ] | ||
| 207 | else | ||
| 208 | local str,err = templ | ||
| 209 | templ,err = _M.parse(str,false,true) | ||
| 210 | if not templ then return nil,err end | ||
| 211 | templ_cache[str] = templ | ||
| 212 | end | ||
| 213 | elseif not _M.is_tag(templ) then | ||
| 214 | return nil, "template is not a document" | ||
| 215 | end | ||
| 216 | return templ | ||
| 217 | end | ||
| 218 | |||
| 219 | local function is_data(data) | ||
| 220 | return #data == 0 or type(data[1]) ~= 'table' | ||
| 221 | end | ||
| 222 | |||
| 223 | local function prepare_data(data) | ||
| 224 | -- a hack for ensuring that $1 maps to first element of data, etc. | ||
| 225 | -- Either this or could change the gsub call just below. | ||
| 226 | for i,v in ipairs(data) do | ||
| 227 | data[tostring(i)] = v | ||
| 228 | end | ||
| 229 | end | ||
| 230 | |||
| 231 | --- create a substituted copy of a document, | ||
| 232 | -- @param templ may be a document or a string representation which will be parsed and cached | ||
| 233 | -- @param data a table of name-value pairs or a list of such tables | ||
| 234 | -- @return an XML document | ||
| 235 | function Doc.subst(templ, data) | ||
| 236 | local err | ||
| 237 | if type(data) ~= 'table' or not next(data) then return nil, "data must be a non-empty table" end | ||
| 238 | if is_data(data) then | ||
| 239 | prepare_data(data) | ||
| 240 | end | ||
| 241 | templ,err = template_cache(templ) | ||
| 242 | if err then return nil, err end | ||
| 243 | local function _subst(item) | ||
| 244 | return _M.clone(templ,function(s) | ||
| 245 | return s:gsub('%$(%w+)',item) | ||
| 246 | end) | ||
| 247 | end | ||
| 248 | if is_data(data) then return _subst(data) end | ||
| 249 | local list = {} | ||
| 250 | for _,item in ipairs(data) do | ||
| 251 | prepare_data(item) | ||
| 252 | t_insert(list,_subst(item)) | ||
| 253 | end | ||
| 254 | if data.tag then | ||
| 255 | list = _M.elem(data.tag,list) | ||
| 256 | end | ||
| 257 | return list | ||
| 258 | end | ||
| 259 | |||
| 260 | |||
| 261 | --- get the first child with a given tag name. | ||
| 262 | -- @param tag the tag name | ||
| 263 | function Doc:child_with_name(tag) | ||
| 264 | for _, child in ipairs(self) do | ||
| 265 | if child.tag == tag then return child; end | ||
| 266 | end | ||
| 267 | end | ||
| 268 | |||
| 269 | local _children_with_name | ||
| 270 | function _children_with_name(self,tag,list,recurse) | ||
| 271 | for _, child in ipairs(self) do if type(child) == 'table' then | ||
| 272 | if child.tag == tag then t_insert(list,child) end | ||
| 273 | if recurse then _children_with_name(child,tag,list,recurse) end | ||
| 274 | end end | ||
| 275 | end | ||
| 276 | |||
| 277 | --- get all elements in a document that have a given tag. | ||
| 278 | -- @param tag a tag name | ||
| 279 | -- @param dont_recurse optionally only return the immediate children with this tag name | ||
| 280 | -- @return a list of elements | ||
| 281 | function Doc:get_elements_with_name(tag,dont_recurse) | ||
| 282 | local res = {} | ||
| 283 | _children_with_name(self,tag,res,not dont_recurse) | ||
| 284 | return res | ||
| 285 | end | ||
| 286 | |||
| 287 | -- iterate over all children of a document node, including text nodes. | ||
| 288 | function Doc:children() | ||
| 289 | local i = 0; | ||
| 290 | return function (a) | ||
| 291 | i = i + 1 | ||
| 292 | return a[i]; | ||
| 293 | end, self, i; | ||
| 294 | end | ||
| 295 | |||
| 296 | -- return the first child element of a node, if it exists. | ||
| 297 | function Doc:first_childtag() | ||
| 298 | if #self == 0 then return end | ||
| 299 | for _,t in ipairs(self) do | ||
| 300 | if type(t) == 'table' then return t end | ||
| 301 | end | ||
| 302 | end | ||
| 303 | |||
| 304 | function Doc:matching_tags(tag, xmlns) | ||
| 305 | xmlns = xmlns or self.attr.xmlns; | ||
| 306 | local tags = self; | ||
| 307 | local start_i, max_i, v = 1, #tags; | ||
| 308 | return function () | ||
| 309 | for i=start_i,max_i do | ||
| 310 | v = tags[i]; | ||
| 311 | if (not tag or v.tag == tag) | ||
| 312 | and (not xmlns or xmlns == v.attr.xmlns) then | ||
| 313 | start_i = i+1; | ||
| 314 | return v; | ||
| 315 | end | ||
| 316 | end | ||
| 317 | end, tags, start_i; | ||
| 318 | end | ||
| 319 | |||
| 320 | --- iterate over all child elements of a document node. | ||
| 321 | function Doc:childtags() | ||
| 322 | local i = 0; | ||
| 323 | return function (a) | ||
| 324 | local v | ||
| 325 | repeat | ||
| 326 | i = i + 1 | ||
| 327 | v = self[i] | ||
| 328 | if v and type(v) == 'table' then return v; end | ||
| 329 | until not v | ||
| 330 | end, self[1], i; | ||
| 331 | end | ||
| 332 | |||
| 333 | --- visit child element of a node and call a function, possibility modifying the document. | ||
| 334 | -- @param callback a function passed the node (text or element). If it returns nil, that node will be removed. | ||
| 335 | -- If it returns a value, that will replace the current node. | ||
| 336 | function Doc:maptags(callback) | ||
| 337 | local is_tag = _M.is_tag | ||
| 338 | local i = 1; | ||
| 339 | while i <= #self do | ||
| 340 | if is_tag(self[i]) then | ||
| 341 | local ret = callback(self[i]); | ||
| 342 | if ret == nil then | ||
| 343 | t_remove(self, i); | ||
| 344 | else | ||
| 345 | self[i] = ret; | ||
| 346 | i = i + 1; | ||
| 347 | end | ||
| 348 | end | ||
| 349 | end | ||
| 350 | return self; | ||
| 351 | end | ||
| 352 | |||
| 353 | local xml_escape | ||
| 354 | do | ||
| 355 | local escape_table = { ["'"] = "'", ["\""] = """, ["<"] = "<", [">"] = ">", ["&"] = "&" }; | ||
| 356 | function xml_escape(str) return (s_gsub(str, "['&<>\"]", escape_table)); end | ||
| 357 | _M.xml_escape = xml_escape; | ||
| 358 | end | ||
| 359 | |||
| 360 | -- pretty printing | ||
| 361 | -- if indent, then put each new tag on its own line | ||
| 362 | -- if attr_indent, put each new attribute on its own line | ||
| 363 | local function _dostring(t, buf, self, xml_escape, parentns, idn, indent, attr_indent) | ||
| 364 | local nsid = 0; | ||
| 365 | local tag = t.tag | ||
| 366 | local lf,alf = ""," " | ||
| 367 | if indent then lf = '\n'..idn end | ||
| 368 | if attr_indent then alf = '\n'..idn..attr_indent end | ||
| 369 | t_insert(buf, lf.."<"..tag); | ||
| 370 | local function write_attr(k,v) | ||
| 371 | if s_find(k, "\1", 1, true) then | ||
| 372 | local ns, attrk = s_match(k, "^([^\1]*)\1?(.*)$"); | ||
| 373 | nsid = nsid + 1; | ||
| 374 | t_insert(buf, " xmlns:ns"..nsid.."='"..xml_escape(ns).."' ".."ns"..nsid..":"..attrk.."='"..xml_escape(v).."'"); | ||
| 375 | elseif not(k == "xmlns" and v == parentns) then | ||
| 376 | t_insert(buf, alf..k.."='"..xml_escape(v).."'"); | ||
| 377 | end | ||
| 378 | end | ||
| 379 | -- it's useful for testing to have predictable attribute ordering, if available | ||
| 380 | if #t.attr > 0 then | ||
| 381 | for _,k in ipairs(t.attr) do | ||
| 382 | write_attr(k,t.attr[k]) | ||
| 383 | end | ||
| 384 | else | ||
| 385 | for k, v in pairs(t.attr) do | ||
| 386 | write_attr(k,v) | ||
| 387 | end | ||
| 388 | end | ||
| 389 | local len,has_children = #t; | ||
| 390 | if len == 0 then | ||
| 391 | local out = "/>" | ||
| 392 | if attr_indent then out = '\n'..idn..out end | ||
| 393 | t_insert(buf, out); | ||
| 394 | else | ||
| 395 | t_insert(buf, ">"); | ||
| 396 | for n=1,len do | ||
| 397 | local child = t[n]; | ||
| 398 | if child.tag then | ||
| 399 | self(child, buf, self, xml_escape, t.attr.xmlns,idn and idn..indent, indent, attr_indent ); | ||
| 400 | has_children = true | ||
| 401 | else -- text element | ||
| 402 | t_insert(buf, xml_escape(child)); | ||
| 403 | end | ||
| 404 | end | ||
| 405 | t_insert(buf, (has_children and lf or '').."</"..tag..">"); | ||
| 406 | end | ||
| 407 | end | ||
| 408 | |||
| 409 | ---- pretty-print an XML document | ||
| 410 | --- @param t an XML document | ||
| 411 | --- @param idn an initial indent (indents are all strings) | ||
| 412 | --- @param indent an indent for each level | ||
| 413 | --- @param attr_indent if given, indent each attribute pair and put on a separate line | ||
| 414 | --- @param xml force prefacing with <?xml...> | ||
| 415 | --- @return a string representation | ||
| 416 | function _M.tostring(t,idn,indent, attr_indent, xml) | ||
| 417 | local buf = {}; | ||
| 418 | if xml then buf[1] = "<?xml version='1.0'?>" end | ||
| 419 | _dostring(t, buf, _dostring, xml_escape, nil,idn,indent, attr_indent); | ||
| 420 | return t_concat(buf); | ||
| 421 | end | ||
| 422 | |||
| 423 | Doc.__tostring = _M.tostring | ||
| 424 | |||
| 425 | --- get the full text value of an element | ||
| 426 | function Doc:get_text() | ||
| 427 | local res = {} | ||
| 428 | for i,el in ipairs(self) do | ||
| 429 | if is_text(el) then t_insert(res,el) end | ||
| 430 | end | ||
| 431 | return t_concat(res); | ||
| 432 | end | ||
| 433 | |||
| 434 | --- make a copy of a document | ||
| 435 | -- @param doc the original document | ||
| 436 | -- @param strsubst an optional function for handling string copying which could do substitution, etc. | ||
| 437 | function _M.clone(doc, strsubst) | ||
| 438 | local lookup_table = {}; | ||
| 439 | local function _copy(object,kind,parent) | ||
| 440 | if type(object) ~= "table" then | ||
| 441 | if strsubst and is_text(object) then return strsubst(object,kind,parent) | ||
| 442 | else return object | ||
| 443 | end | ||
| 444 | elseif lookup_table[object] then | ||
| 445 | return lookup_table[object] | ||
| 446 | end | ||
| 447 | local new_table = {}; | ||
| 448 | lookup_table[object] = new_table | ||
| 449 | local tag = object.tag | ||
| 450 | new_table.tag = _copy(tag,'*TAG',parent) | ||
| 451 | if object.attr then | ||
| 452 | local res = {} | ||
| 453 | for attr,value in pairs(object.attr) do | ||
| 454 | res[attr] = _copy(value,attr,object) | ||
| 455 | end | ||
| 456 | new_table.attr = res | ||
| 457 | end | ||
| 458 | for index = 1,#object do | ||
| 459 | local v = _copy(object[index],'*TEXT',object) | ||
| 460 | t_insert(new_table,v) | ||
| 461 | end | ||
| 462 | return setmetatable(new_table, getmetatable(object)) | ||
| 463 | end | ||
| 464 | |||
| 465 | return _copy(doc) | ||
| 466 | end | ||
| 467 | |||
| 468 | Doc.filter = _M.clone -- also available as method | ||
| 469 | |||
| 470 | --- compare two documents. | ||
| 471 | -- @param t1 any value | ||
| 472 | -- @param t2 any value | ||
| 473 | function _M.compare(t1,t2) | ||
| 474 | local ty1 = type(t1) | ||
| 475 | local ty2 = type(t2) | ||
| 476 | if ty1 ~= ty2 then return false, 'type mismatch' end | ||
| 477 | if ty1 == 'string' then | ||
| 478 | return t1 == t2 and true or 'text '..t1..' ~= text '..t2 | ||
| 479 | end | ||
| 480 | if ty1 ~= 'table' or ty2 ~= 'table' then return false, 'not a document' end | ||
| 481 | if t1.tag ~= t2.tag then return false, 'tag '..t1.tag..' ~= tag '..t2.tag end | ||
| 482 | if #t1 ~= #t2 then return false, 'size '..#t1..' ~= size '..#t2..' for tag '..t1.tag end | ||
| 483 | -- compare attributes | ||
| 484 | for k,v in pairs(t1.attr) do | ||
| 485 | if t2.attr[k] ~= v then return false, 'mismatch attrib' end | ||
| 486 | end | ||
| 487 | for k,v in pairs(t2.attr) do | ||
| 488 | if t1.attr[k] ~= v then return false, 'mismatch attrib' end | ||
| 489 | end | ||
| 490 | -- compare children | ||
| 491 | for i = 1,#t1 do | ||
| 492 | local yes,err = _M.compare(t1[i],t2[i]) | ||
| 493 | if not yes then return err end | ||
| 494 | end | ||
| 495 | return true | ||
| 496 | end | ||
| 497 | |||
| 498 | --- is this value a document element? | ||
| 499 | -- @param d any value | ||
| 500 | function _M.is_tag(d) | ||
| 501 | return type(d) == 'table' and is_text(d.tag) | ||
| 502 | end | ||
| 503 | |||
| 504 | --- call the desired function recursively over the document. | ||
| 505 | -- @param doc the document | ||
| 506 | -- @param depth_first visit child notes first, then the current node | ||
| 507 | -- @param operation a function which will receive the current tag name and current node. | ||
| 508 | function _M.walk (doc, depth_first, operation) | ||
| 509 | if not depth_first then operation(doc.tag,doc) end | ||
| 510 | for _,d in ipairs(doc) do | ||
| 511 | if _M.is_tag(d) then | ||
| 512 | _M.walk(d,depth_first,operation) | ||
| 513 | end | ||
| 514 | end | ||
| 515 | if depth_first then operation(doc.tag,doc) end | ||
| 516 | end | ||
| 517 | |||
| 518 | local html_empty_elements = { --lists all HTML empty (void) elements | ||
| 519 | br = true, | ||
| 520 | img = true, | ||
| 521 | meta = true, | ||
| 522 | frame = true, | ||
| 523 | area = true, | ||
| 524 | hr = true, | ||
| 525 | base = true, | ||
| 526 | col = true, | ||
| 527 | link = true, | ||
| 528 | input = true, | ||
| 529 | option = true, | ||
| 530 | param = true, | ||
| 531 | isindex = true, | ||
| 532 | embed = true, | ||
| 533 | } | ||
| 534 | |||
| 535 | local escapes = { quot = "\"", apos = "'", lt = "<", gt = ">", amp = "&" } | ||
| 536 | local function unescape(str) return (str:gsub( "&(%a+);", escapes)); end | ||
| 537 | |||
| 538 | --- Parse a well-formed HTML file as a string. | ||
| 539 | -- Tags are case-insenstive, DOCTYPE is ignored, and empty elements can be .. empty. | ||
| 540 | -- @param s the HTML | ||
| 541 | function _M.parsehtml (s) | ||
| 542 | return _M.basic_parse(s,false,true) | ||
| 543 | end | ||
| 544 | |||
| 545 | --- Parse a simple XML document using a pure Lua parser based on Robero Ierusalimschy's original version. | ||
| 546 | -- @param s the XML document to be parsed. | ||
| 547 | -- @param all_text if true, preserves all whitespace. Otherwise only text containing non-whitespace is included. | ||
| 548 | -- @param html if true, uses relaxed HTML rules for parsing | ||
| 549 | function _M.basic_parse(s,all_text,html) | ||
| 550 | local t_insert,t_remove = table.insert,table.remove | ||
| 551 | local s_find,s_sub = string.find,string.sub | ||
| 552 | local stack = {} | ||
| 553 | local top = {} | ||
| 554 | |||
| 555 | local function parseargs(s) | ||
| 556 | local arg = {} | ||
| 557 | s:gsub("([%w:]+)%s*=%s*([\"'])(.-)%2", function (w, _, a) | ||
| 558 | if html then w = w:lower() end | ||
| 559 | arg[w] = unescape(a) | ||
| 560 | end) | ||
| 561 | if html then | ||
| 562 | s:gsub("([%w:]+)%s*=%s*([^\"']+)%s*", function (w, a) | ||
| 563 | w = w:lower() | ||
| 564 | arg[w] = unescape(a) | ||
| 565 | end) | ||
| 566 | end | ||
| 567 | return arg | ||
| 568 | end | ||
| 569 | |||
| 570 | t_insert(stack, top) | ||
| 571 | local ni,c,label,xarg, empty, _, istart | ||
| 572 | local i, j = 1, 1 | ||
| 573 | if not html then -- we're not interested in <?xml version="1.0"?> | ||
| 574 | _,istart = s_find(s,'^%s*<%?[^%?]+%?>%s*') | ||
| 575 | else -- or <!DOCTYPE ...> | ||
| 576 | _,istart = s_find(s,'^%s*<!DOCTYPE.->%s*') | ||
| 577 | end | ||
| 578 | if istart then i = istart+1 end | ||
| 579 | while true do | ||
| 580 | ni,j,c,label,xarg, empty = s_find(s, "<([%/!]?)([%w:%-_]+)(.-)(%/?)>", i) | ||
| 581 | if not ni then break end | ||
| 582 | if c == "!" then -- comment | ||
| 583 | -- case where there's no space inside comment | ||
| 584 | if not (label:match '%-%-$' and xarg == '') then | ||
| 585 | if xarg:match '%-%-$' then -- we've grabbed it all | ||
| 586 | j = j - 2 | ||
| 587 | end | ||
| 588 | -- match end of comment | ||
| 589 | _,j = s_find(s, "-->", j, true) | ||
| 590 | end | ||
| 591 | else | ||
| 592 | local text = s_sub(s, i, ni-1) | ||
| 593 | if html then | ||
| 594 | label = label:lower() | ||
| 595 | if html_empty_elements[label] then empty = "/" end | ||
| 596 | if label == 'script' then | ||
| 597 | end | ||
| 598 | end | ||
| 599 | if all_text or not s_find(text, "^%s*$") then | ||
| 600 | t_insert(top, unescape(text)) | ||
| 601 | end | ||
| 602 | if empty == "/" then -- empty element tag | ||
| 603 | t_insert(top, setmetatable({tag=label, attr=parseargs(xarg), empty=1},Doc)) | ||
| 604 | elseif c == "" then -- start tag | ||
| 605 | top = setmetatable({tag=label, attr=parseargs(xarg)},Doc) | ||
| 606 | t_insert(stack, top) -- new level | ||
| 607 | else -- end tag | ||
| 608 | local toclose = t_remove(stack) -- remove top | ||
| 609 | top = stack[#stack] | ||
| 610 | if #stack < 1 then | ||
| 611 | error("nothing to close with "..label..':'..text) | ||
| 612 | end | ||
| 613 | if toclose.tag ~= label then | ||
| 614 | error("trying to close "..toclose.tag.." with "..label.." "..text) | ||
| 615 | end | ||
| 616 | t_insert(top, toclose) | ||
| 617 | end | ||
| 618 | end | ||
| 619 | i = j+1 | ||
| 620 | end | ||
| 621 | local text = s_sub(s, i) | ||
| 622 | if all_text or not s_find(text, "^%s*$") then | ||
| 623 | t_insert(stack[#stack], unescape(text)) | ||
| 624 | end | ||
| 625 | if #stack > 1 then | ||
| 626 | error("unclosed "..stack[#stack].tag) | ||
| 627 | end | ||
| 628 | local res = stack[1] | ||
| 629 | return is_text(res[1]) and res[2] or res[1] | ||
| 630 | end | ||
| 631 | |||
| 632 | local function empty(attr) return not attr or not next(attr) end | ||
| 633 | local function is_element(d) return type(d) == 'table' and d.tag ~= nil end | ||
| 634 | |||
| 635 | -- returns the key,value pair from a table if it has exactly one entry | ||
| 636 | local function has_one_element(t) | ||
| 637 | local key,value = next(t) | ||
| 638 | if next(t,key) ~= nil then return false end | ||
| 639 | return key,value | ||
| 640 | end | ||
| 641 | |||
| 642 | local function append_capture(res,tbl) | ||
| 643 | if not empty(tbl) then -- no point in capturing empty tables... | ||
| 644 | local key | ||
| 645 | if tbl._ then -- if $_ was set then it is meant as the top-level key for the captured table | ||
| 646 | key = tbl._ | ||
| 647 | tbl._ = nil | ||
| 648 | if empty(tbl) then return end | ||
| 649 | end | ||
| 650 | -- a table with only one pair {[0]=value} shall be reduced to that value | ||
| 651 | local numkey,val = has_one_element(tbl) | ||
| 652 | if numkey == 0 then tbl = val end | ||
| 653 | if key then | ||
| 654 | res[key] = tbl | ||
| 655 | else -- otherwise, we append the captured table | ||
| 656 | t_insert(res,tbl) | ||
| 657 | end | ||
| 658 | end | ||
| 659 | end | ||
| 660 | |||
| 661 | local function make_number(pat) | ||
| 662 | if pat:find '^%d+$' then -- $1 etc means use this as an array location | ||
| 663 | pat = tonumber(pat) | ||
| 664 | end | ||
| 665 | return pat | ||
| 666 | end | ||
| 667 | |||
| 668 | local function capture_attrib(res,pat,value) | ||
| 669 | pat = make_number(pat:sub(2)) | ||
| 670 | res[pat] = value | ||
| 671 | return true | ||
| 672 | end | ||
| 673 | |||
| 674 | local match | ||
| 675 | function match(d,pat,res,keep_going) | ||
| 676 | local ret = true | ||
| 677 | if d == nil then d = '' end --return false end | ||
| 678 | -- attribute string matching is straight equality, except if the pattern is a $ capture, | ||
| 679 | -- which always succeeds. | ||
| 680 | if is_text(d) then | ||
| 681 | if not is_text(pat) then return false end | ||
| 682 | if _M.debug then print(d,pat) end | ||
| 683 | if pat:find '^%$' then | ||
| 684 | return capture_attrib(res,pat,d) | ||
| 685 | else | ||
| 686 | return d == pat | ||
| 687 | end | ||
| 688 | else | ||
| 689 | if _M.debug then print(d.tag,pat.tag) end | ||
| 690 | -- this is an element node. For a match to succeed, the attributes must | ||
| 691 | -- match as well. | ||
| 692 | -- a tagname in the pattern ending with '-' is a wildcard and matches like an attribute | ||
| 693 | local tagpat = pat.tag:match '^(.-)%-$' | ||
| 694 | if tagpat then | ||
| 695 | tagpat = make_number(tagpat) | ||
| 696 | res[tagpat] = d.tag | ||
| 697 | end | ||
| 698 | if d.tag == pat.tag or tagpat then | ||
| 699 | |||
| 700 | if not empty(pat.attr) then | ||
| 701 | if empty(d.attr) then ret = false | ||
| 702 | else | ||
| 703 | for prop,pval in pairs(pat.attr) do | ||
| 704 | local dval = d.attr[prop] | ||
| 705 | if not match(dval,pval,res) then ret = false; break end | ||
| 706 | end | ||
| 707 | end | ||
| 708 | end | ||
| 709 | -- the pattern may have child nodes. We match partially, so that {P1,P2} shall match {X,P1,X,X,P2,..} | ||
| 710 | if ret and #pat > 0 then | ||
| 711 | local i,j = 1,1 | ||
| 712 | local function next_elem() | ||
| 713 | j = j + 1 -- next child element of data | ||
| 714 | if is_text(d[j]) then j = j + 1 end | ||
| 715 | return j <= #d | ||
| 716 | end | ||
| 717 | repeat | ||
| 718 | local p = pat[i] | ||
| 719 | -- repeated {{<...>}} patterns shall match one or more elements | ||
| 720 | -- so e.g. {P+} will match {X,X,P,P,X,P,X,X,X} | ||
| 721 | if is_element(p) and p.repeated then | ||
| 722 | local found | ||
| 723 | repeat | ||
| 724 | local tbl = {} | ||
| 725 | ret = match(d[j],p,tbl,false) | ||
| 726 | if ret then | ||
| 727 | found = false --true | ||
| 728 | append_capture(res,tbl) | ||
| 729 | end | ||
| 730 | until not next_elem() or (found and not ret) | ||
| 731 | i = i + 1 | ||
| 732 | else | ||
| 733 | ret = match(d[j],p,res,false) | ||
| 734 | if ret then i = i + 1 end | ||
| 735 | end | ||
| 736 | until not next_elem() or i > #pat -- run out of elements or patterns to match | ||
| 737 | -- if every element in our pattern matched ok, then it's been a successful match | ||
| 738 | if i > #pat then return true end | ||
| 739 | end | ||
| 740 | if ret then return true end | ||
| 741 | else | ||
| 742 | ret = false | ||
| 743 | end | ||
| 744 | -- keep going anyway - look at the children! | ||
| 745 | if keep_going then | ||
| 746 | for child in d:childtags() do | ||
| 747 | ret = match(child,pat,res,keep_going) | ||
| 748 | if ret then break end | ||
| 749 | end | ||
| 750 | end | ||
| 751 | end | ||
| 752 | return ret | ||
| 753 | end | ||
| 754 | |||
| 755 | function Doc:match(pat) | ||
| 756 | local err | ||
| 757 | pat,err = template_cache(pat) | ||
| 758 | if not pat then return nil, err end | ||
| 759 | _M.walk(pat,false,function(_,d) | ||
| 760 | if is_text(d[1]) and is_element(d[2]) and is_text(d[3]) and | ||
| 761 | d[1]:find '%s*{{' and d[3]:find '}}%s*' then | ||
| 762 | t_remove(d,1) | ||
| 763 | t_remove(d,2) | ||
| 764 | d[1].repeated = true | ||
| 765 | end | ||
| 766 | end) | ||
| 767 | |||
| 768 | local res = {} | ||
| 769 | local ret = match(self,pat,res,true) | ||
| 770 | return res,ret | ||
| 771 | end | ||
| 772 | |||
| 773 | |||
| 774 | return _M | ||
| 775 |
| 1 | |||
| 2 | local MainScene = class("MainScene", cc.load("mvc").ViewBase) | ||
| 3 | |||
| 4 | MainScene.RESOURCE_FILENAME = "MainScene.csb" | ||
| 5 | |||
| 6 | function MainScene:onCreate() | ||
| 7 | printf("resource node = %s", tostring(self:getResourceNode())) | ||
| 8 | |||
| 9 | --[[ you can create scene with following comment code instead of using csb file. | ||
| 10 | -- add background image | ||
| 11 | display.newSprite("HelloWorld.png") | ||
| 12 | :move(display.center) | ||
| 13 | :addTo(self) | ||
| 14 | |||
| 15 | -- add HelloWorld label | ||
| 16 | cc.Label:createWithSystemFont("Hello World", "Arial", 40) | ||
| 17 | :move(display.cx, display.cy + 200) | ||
| 18 | :addTo(self) | ||
| 19 | ]] | ||
| 20 | end | ||
| 21 | |||
| 22 | return MainScene |
| 1 | local EffectBoom = class("EffectBoom",function (path) | ||
| 2 | return cc.Sprite:create(path); | ||
| 3 | end) | ||
| 4 | |||
| 5 | function EffectBoom:ctor() | ||
| 6 | self:init(); | ||
| 7 | end | ||
| 8 | |||
| 9 | function EffectBoom:init() | ||
| 10 | self:setScale(0); | ||
| 11 | local scaleTo1 = cc.EaseBounceOut:create(cc.ScaleTo:create(0.3,1,1)); | ||
| 12 | -- local scaleTo2 = cc.ScaleTo:create(0.5,0,0); | ||
| 13 | local fadeOut = cc.FadeOut:create(0.5); | ||
| 14 | local effAction = cc.Sequence:create(scaleTo1,cc.DelayTime:create(1),fadeOut,cc.CallFunc:create(function() | ||
| 15 | self:removeFromParent(); | ||
| 16 | print("boom effect removed"); | ||
| 17 | end)); | ||
| 18 | self:runAction(effAction); | ||
| 19 | end | ||
| 20 | |||
| 21 | return EffectBoom | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local EffectFntPop = class("EffectFntPop",function () | ||
| 2 | return cc.CSLoader:createNode("ui/PopFntLayer.csb"); | ||
| 3 | end) | ||
| 4 | |||
| 5 | function EffectFntPop:ctor(msg) | ||
| 6 | local rect = self:getBoundingBox(); | ||
| 7 | self.panel = self:getChildByName("panel"); | ||
| 8 | self.panel:getChildByName("txt"):setString(msg); | ||
| 9 | self.panel:setPosition(cc.p(0,0)); | ||
| 10 | self:init(); | ||
| 11 | end | ||
| 12 | |||
| 13 | function EffectFntPop:init() | ||
| 14 | local fadeOut = cc.FadeOut:create(1); | ||
| 15 | local effAction = cc.Sequence:create(cc.DelayTime:create(1.5),fadeOut,cc.CallFunc:create(function() | ||
| 16 | self:removeFromParent(); | ||
| 17 | end)); | ||
| 18 | self:runAction(effAction); | ||
| 19 | end | ||
| 20 | |||
| 21 | return EffectFntPop | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local EffectFruitLight = class("EffectFruitLight",function (spriteFrameName) | ||
| 2 | return cc.Sprite:createWithSpriteFrameName(spriteFrameName) | ||
| 3 | end); | ||
| 4 | |||
| 5 | function EffectFruitLight:ctor(spriteFrameName) | ||
| 6 | end | ||
| 7 | |||
| 8 | function EffectFruitLight:flash() | ||
| 9 | local fadeIn = cc.FadeIn:create(0.3); | ||
| 10 | local fadeOut = cc.FadeOut:create(0.3); | ||
| 11 | |||
| 12 | local repeatAction = cc.RepeatForever:create(cc.Sequence:create(fadeIn,fadeOut)); | ||
| 13 | self:runAction(repeatAction); | ||
| 14 | end | ||
| 15 | |||
| 16 | return EffectFruitLight | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local EffectPlayLevel = class("EffectPlayLevel",function () | ||
| 2 | return cc.CSLoader:createNode("ui/guandan/PlayLevelLayer.csb"); | ||
| 3 | end) | ||
| 4 | |||
| 5 | --ִЧ | ||
| 6 | function EffectPlayLevel:ctor(poker_point) | ||
| 7 | self:init(poker_point); | ||
| 8 | end | ||
| 9 | |||
| 10 | function EffectPlayLevel:init(poker_point) | ||
| 11 | local panel = self:getChildByName("panel"); | ||
| 12 | panel:setPosition(cc.p(0,0)); | ||
| 13 | local sp_level = cc.Sprite:createWithSpriteFrameName("gd_level_"..poker_point..".png"); | ||
| 14 | panel:getChildByName("level"):setSpriteFrame(sp_level:getSpriteFrame()); | ||
| 15 | |||
| 16 | panel:setScale(0); | ||
| 17 | local scaleTo1 = cc.EaseBounceOut:create(cc.ScaleTo:create(0.5,1,1)); | ||
| 18 | local fadeOut = cc.FadeOut:create(0.5); | ||
| 19 | local effAction = cc.Sequence:create(scaleTo1,cc.DelayTime:create(1.5),fadeOut,cc.CallFunc:create(function() | ||
| 20 | self:removeFromParent(); | ||
| 21 | end)); | ||
| 22 | panel:runAction(effAction); | ||
| 23 | end | ||
| 24 | |||
| 25 | return EffectPlayLevel | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local EffectRoomRule = class("EffectRoomRule",function () | ||
| 2 | local item = cc.CSLoader:createNode("ui/RoomRulesLayer.csb"); | ||
| 3 | return item; | ||
| 4 | end) | ||
| 5 | |||
| 6 | function EffectRoomRule:ctor(str) | ||
| 7 | self:init(str); | ||
| 8 | end | ||
| 9 | |||
| 10 | function EffectRoomRule:init(str) | ||
| 11 | self:getChildByName("txt"):setString(str); | ||
| 12 | |||
| 13 | self:setPosition(cc.p(display.width,display.height*0.9)); | ||
| 14 | |||
| 15 | local moveBy = cc.MoveBy:create(0.5, cc.p(-395, 0)); | ||
| 16 | local fadeOut = cc.FadeOut:create(1); | ||
| 17 | local effAction = cc.Sequence:create(moveBy,cc.DelayTime:create(5),fadeOut,cc.CallFunc:create(function() | ||
| 18 | self:removeFromParent(); | ||
| 19 | end)); | ||
| 20 | self:runAction(effAction); | ||
| 21 | end | ||
| 22 | |||
| 23 | return EffectRoomRule | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local EffectScaleIn = class("EffectScaleIn",function (path) | ||
| 2 | return cc.Sprite:create(path); | ||
| 3 | end) | ||
| 4 | |||
| 5 | function EffectScaleIn:ctor(str) | ||
| 6 | self:init(); | ||
| 7 | end | ||
| 8 | |||
| 9 | function EffectScaleIn:init() | ||
| 10 | -- local scaleTo = cc.ScaleTo:create(0.5,0,0); | ||
| 11 | local fadeOut = cc.FadeOut:create(2); | ||
| 12 | local effAction = cc.Sequence:create(cc.DelayTime:create(1),fadeOut,cc.CallFunc:create(function() | ||
| 13 | self:removeFromParent(); | ||
| 14 | end)); | ||
| 15 | self:runAction(effAction); | ||
| 16 | end | ||
| 17 | |||
| 18 | return EffectScaleIn | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local EffectSelected = class("EffectSelected",function (rect,type) | ||
| 2 | local selected_box; | ||
| 3 | if type == EnumNodeType.POKER or type == EnumNodeType.DDZ_POKER then | ||
| 4 | selected_box = ccui.Scale9Sprite:create("res/common/selected_box_common.png"); | ||
| 5 | -- selected_box:setCapInsets(cc.rect(30,30,48,17)); | ||
| 6 | -- selected_box:setContentSize(cc.size(rect.width+30,rect.height+30)); | ||
| 7 | elseif type == EnumNodeType.MAIL then | ||
| 8 | selected_box = ccui.Scale9Sprite:create("res/common/selected_box_mail.png"); | ||
| 9 | -- selected_box:setCapInsets(cc.rect(25,25,1122,52)); | ||
| 10 | -- selected_box:setContentSize(cc.size(rect.width+20,rect.height+20)); | ||
| 11 | else | ||
| 12 | selected_box = ccui.Scale9Sprite:create("res/common/selected_box_common.png"); | ||
| 13 | -- selected_box:setCapInsets(cc.rect(30,30,48,17)); | ||
| 14 | -- selected_box:setContentSize(cc.size(rect.width+35,rect.height+35)); | ||
| 15 | end | ||
| 16 | return selected_box; | ||
| 17 | end) | ||
| 18 | |||
| 19 | function EffectSelected:ctor(rect,type) | ||
| 20 | self:init(rect,type); | ||
| 21 | self:resize(rect,type); | ||
| 22 | end | ||
| 23 | |||
| 24 | function EffectSelected:init(rect,type) | ||
| 25 | local fadeIn = cc.FadeIn:create(0.7); | ||
| 26 | local fadeOut = cc.FadeOut:create(0.7); | ||
| 27 | |||
| 28 | local repeatAction = cc.RepeatForever:create(cc.Sequence:create(fadeIn,fadeOut)); | ||
| 29 | self:runAction(repeatAction); | ||
| 30 | end | ||
| 31 | |||
| 32 | function EffectSelected:resize(rect,type) | ||
| 33 | if type == EnumNodeType.POKER or type == EnumNodeType.DDZ_POKER then | ||
| 34 | self:setCapInsets(cc.rect(30,30,48,17)); | ||
| 35 | self:setContentSize(cc.size(rect.width+30,rect.height+30)); | ||
| 36 | elseif type == EnumNodeType.MAIL then | ||
| 37 | self:setCapInsets(cc.rect(25,25,1122,52)); | ||
| 38 | self:setContentSize(cc.size(rect.width+20,rect.height+20)); | ||
| 39 | else | ||
| 40 | self:setCapInsets(cc.rect(58,58,6,6)); | ||
| 41 | self:setContentSize(cc.size(rect.width+48,rect.height+48)); | ||
| 42 | end | ||
| 43 | end | ||
| 44 | |||
| 45 | return EffectSelected | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local EffectShadow = class("EffectShadow",function (spriteFrameName) | ||
| 2 | return cc.Sprite:createWithSpriteFrameName(spriteFrameName) | ||
| 3 | end); | ||
| 4 | |||
| 5 | function EffectShadow:ctor(spriteFrameName) | ||
| 6 | self:init(spriteFrameName); | ||
| 7 | end | ||
| 8 | |||
| 9 | function EffectShadow:init(spriteFrameName) | ||
| 10 | local fadeOut = cc.FadeOut:create(0.5); | ||
| 11 | self:runAction(cc.Sequence:create(fadeOut,cc.CallFunc:create(function () | ||
| 12 | self:removeSelf(); | ||
| 13 | end))); | ||
| 14 | end | ||
| 15 | |||
| 16 | return EffectShadow | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local EffectStright = class("EffectStright",function (path) | ||
| 2 | return cc.Sprite:create(path); | ||
| 3 | end) | ||
| 4 | |||
| 5 | function EffectStright:ctor(str) | ||
| 6 | self:init(); | ||
| 7 | end | ||
| 8 | |||
| 9 | function EffectStright:init() | ||
| 10 | self:setPosition(0,0); | ||
| 11 | local moveBy1 = cc.MoveBy:create(1,cc.p(display.width/2,0)); | ||
| 12 | local moveBy2 = cc.MoveBy:create(2,cc.p(display.width,0)); | ||
| 13 | |||
| 14 | local completeFun = cc.CallFunc:create(function() | ||
| 15 | self:removeFromParent(); | ||
| 16 | end) | ||
| 17 | local effAction = cc.Sequence:create(moveBy1,moveBy2,completeFun); | ||
| 18 | self:runAction(effAction); | ||
| 19 | |||
| 20 | local fadeOut = cc.FadeOut:create(2); | ||
| 21 | self:runAction(cc.Sequence:create(cc.DelayTime:create(1),fadeOut)); | ||
| 22 | end | ||
| 23 | |||
| 24 | return EffectStright | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local EffectVoiceChat = class("EffectVoiceChat",function () | ||
| 2 | return cc.CSLoader:createNode("ui/VoiceChatPop.csb"); | ||
| 3 | end) | ||
| 4 | |||
| 5 | function EffectVoiceChat:ctor(msg) | ||
| 6 | self:init(msg); | ||
| 7 | end | ||
| 8 | |||
| 9 | function EffectVoiceChat:init(msg) | ||
| 10 | self:getChildByName("txt"):setString(msg); | ||
| 11 | -- local scaleTo = cc.ScaleTo:create(0.5,0,0); | ||
| 12 | local fadeOut = cc.FadeOut:create(2); | ||
| 13 | local effAction = cc.Sequence:create(cc.DelayTime:create(1),fadeOut,cc.CallFunc:create(function() | ||
| 14 | self:removeFromParent(); | ||
| 15 | end)); | ||
| 16 | self:runAction(effAction); | ||
| 17 | end | ||
| 18 | |||
| 19 | return EffectVoiceChat | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local GameFailView = dialog.uinode("ui/rubbish/GameFailLayer.csb",import("..view.BaseView")) | ||
| 2 | |||
| 3 | require("app.model.ShopModel"); | ||
| 4 | |||
| 5 | function GameFailView:ctor() | ||
| 6 | GameFailView.super.ctor(self); | ||
| 7 | end | ||
| 8 | |||
| 9 | function GameFailView:show(info,yesFun,noFun) | ||
| 10 | local scene = cc.Director:getInstance():getRunningScene() | ||
| 11 | local inst = GameFailView:create(); | ||
| 12 | scene:addChild(inst, dialog.ZORDER_POP); | ||
| 13 | |||
| 14 | local panel = inst:getChildByName("panel"); | ||
| 15 | panel:setScale(0.5); | ||
| 16 | local scaleTo = cc.ScaleTo:create(0.2,1); | ||
| 17 | panel:runAction(scaleTo); | ||
| 18 | |||
| 19 | inst.yesFun = yesFun; | ||
| 20 | inst.noFun = noFun; | ||
| 21 | |||
| 22 | inst:init(); | ||
| 23 | |||
| 24 | return inst; | ||
| 25 | end | ||
| 26 | |||
| 27 | function GameFailView:init() | ||
| 28 | self:setContentSize(cc.size(display.width,display.height)); | ||
| 29 | ccui.Helper:doLayout(self); | ||
| 30 | |||
| 31 | local btn_yes = self:getChildByName("panel"):getChildByName("btn_yes"); | ||
| 32 | btn_yes.fn = handler(self,self.onYes); | ||
| 33 | btn_yes:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, btn_yes.fn)end); | ||
| 34 | |||
| 35 | local btn_no = self:getChildByName("panel"):getChildByName("btn_no"); | ||
| 36 | btn_no.fn = handler(self,self.onNo); | ||
| 37 | btn_no:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, btn_no.fn)end); | ||
| 38 | |||
| 39 | self.nodes[1] = {btn_no,btn_yes}; | ||
| 40 | self.nodeIndex = 1 | ||
| 41 | self.selectedIndex = 2; | ||
| 42 | self:updateSelectedState(); | ||
| 43 | end | ||
| 44 | |||
| 45 | function GameFailView:onYes() | ||
| 46 | local function payConfirmSuccessFun() | ||
| 47 | if self.yesFun then | ||
| 48 | self.yesFun(); | ||
| 49 | end | ||
| 50 | self:close(); | ||
| 51 | end | ||
| 52 | |||
| 53 | local reciever = require("app.views.rubbish.GamePayConfirmView"):show("",payConfirmSuccessFun); | ||
| 54 | cc.Director:getInstance():getRunningScene().keypadManager:addKeypadReceiver(reciever); | ||
| 55 | end | ||
| 56 | |||
| 57 | function GameFailView:onNo() | ||
| 58 | if self.noFun then | ||
| 59 | self.noFun(); | ||
| 60 | end | ||
| 61 | self:close(); | ||
| 62 | end | ||
| 63 | |||
| 64 | --返回键处理函数 | ||
| 65 | function GameFailView:onKeypadBack() | ||
| 66 | |||
| 67 | end | ||
| 68 | |||
| 69 | return GameFailView | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local GameNextView = dialog.uinode("ui/rubbish/GameNextLayer.csb",import("..view.BaseViewNew")) | ||
| 2 | |||
| 3 | function GameNextView:ctor() | ||
| 4 | GameNextView.super.ctor(self); | ||
| 5 | end | ||
| 6 | |||
| 7 | function GameNextView:show(showNextAnimal) | ||
| 8 | local scene = cc.Director:getInstance():getRunningScene() | ||
| 9 | local inst = GameNextView:create(); | ||
| 10 | scene:addChild(inst, dialog.ZORDER_POP); | ||
| 11 | |||
| 12 | inst.showNextAnimal = showNextAnimal; | ||
| 13 | |||
| 14 | inst:init(); | ||
| 15 | |||
| 16 | return inst; | ||
| 17 | end | ||
| 18 | |||
| 19 | function GameNextView:init() | ||
| 20 | self:setContentSize(cc.size(display.width,display.height)); | ||
| 21 | ccui.Helper:doLayout(self); | ||
| 22 | |||
| 23 | local btn = self:getChildByName("panel"):getChildByName("btn"); | ||
| 24 | btn.fn = handler(self,self.onNext); | ||
| 25 | btn:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, btn.fn)end); | ||
| 26 | |||
| 27 | self.txt = self:getChildByName("panel"):getChildByName("txt"); | ||
| 28 | |||
| 29 | local _this = self; | ||
| 30 | local _cd = 3; | ||
| 31 | local function countdown_fn() | ||
| 32 | if _cd <= 1 then | ||
| 33 | _this:onNext(); | ||
| 34 | return; | ||
| 35 | end | ||
| 36 | _cd = _cd - 1; | ||
| 37 | |||
| 38 | _this.txt:setString(_cd); | ||
| 39 | end | ||
| 40 | self.txt:setString(_cd); | ||
| 41 | self.countdown_schedule = schedule(self,countdown_fn,1); | ||
| 42 | |||
| 43 | -- btn:setOpacity(0); | ||
| 44 | -- btn:runAction(cc.Repeat:create(cc.Sequence:create( | ||
| 45 | -- cc.FadeIn:create(0.3), | ||
| 46 | -- cc.FadeOut:create(0.3) | ||
| 47 | -- ),2)); | ||
| 48 | -- btn:runAction(cc.Sequence:create( | ||
| 49 | -- cc.DelayTime:create(1.2), | ||
| 50 | -- cc.CallFunc:create(function () | ||
| 51 | -- _this:onNext(); | ||
| 52 | -- end) | ||
| 53 | -- )); | ||
| 54 | |||
| 55 | -- self.nodes[1] = {btn}; | ||
| 56 | -- self:updateSelectedState(btn); | ||
| 57 | end | ||
| 58 | |||
| 59 | function GameNextView:stopCountDown() | ||
| 60 | if self.countdown_schedule then | ||
| 61 | self:stopAction(self.countdown_schedule); | ||
| 62 | self.countdown_schedule = nil; | ||
| 63 | end | ||
| 64 | end | ||
| 65 | |||
| 66 | function GameNextView:onNext() | ||
| 67 | self:stopCountDown(); | ||
| 68 | if self.showNextAnimal then | ||
| 69 | self.showNextAnimal(); | ||
| 70 | end | ||
| 71 | self:close(); | ||
| 72 | end | ||
| 73 | |||
| 74 | --返回键处理函数 | ||
| 75 | function GameNextView:onKeypadBack() | ||
| 76 | |||
| 77 | end | ||
| 78 | |||
| 79 | return GameNextView | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local GameOverView = dialog.uinode("ui/rubbish/GameOverLayer.csb",import("..view.BaseView")) | ||
| 2 | |||
| 3 | local game_data = require("app.views.rubbish.game_data"); | ||
| 4 | |||
| 5 | function GameOverView:ctor() | ||
| 6 | GameOverView.super.ctor(self); | ||
| 7 | end | ||
| 8 | |||
| 9 | function GameOverView:show(info,exitFun,againFun) | ||
| 10 | local scene = cc.Director:getInstance():getRunningScene() | ||
| 11 | local inst = GameOverView:create(); | ||
| 12 | scene:addChild(inst, dialog.ZORDER_POP); | ||
| 13 | |||
| 14 | -- local panel = inst:getChildByName("panel"); | ||
| 15 | -- panel:setScale(0.5); | ||
| 16 | -- local scaleTo = cc.ScaleTo:create(0.2,1); | ||
| 17 | -- panel:runAction(scaleTo); | ||
| 18 | |||
| 19 | inst.exitFun = exitFun; | ||
| 20 | inst.againFun = againFun; | ||
| 21 | |||
| 22 | inst:getChildByName("panel"):getChildByName("txt_level"):setString(info.level..""); | ||
| 23 | inst:getChildByName("panel"):getChildByName("txt_best"):setString("最佳纪录:"..info.best..""); | ||
| 24 | |||
| 25 | inst:init(); | ||
| 26 | |||
| 27 | return inst; | ||
| 28 | end | ||
| 29 | |||
| 30 | function GameOverView:init() | ||
| 31 | self:setContentSize(cc.size(display.width,display.height)); | ||
| 32 | ccui.Helper:doLayout(self); | ||
| 33 | |||
| 34 | game_data.add_game_play_cnt(); | ||
| 35 | |||
| 36 | local btn_exit = self:getChildByName("panel"):getChildByName("btn_exit"); | ||
| 37 | btn_exit.fn = handler(self,self.onExit); | ||
| 38 | btn_exit:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, btn_exit.fn)end); | ||
| 39 | |||
| 40 | local btn_again = self:getChildByName("panel"):getChildByName("btn_again"); | ||
| 41 | btn_again.fn = handler(self,self.onAgain); | ||
| 42 | btn_again:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, btn_again.fn)end); | ||
| 43 | |||
| 44 | self.nodes[1] = {btn_exit,btn_again}; | ||
| 45 | self.nodeIndex = 1 | ||
| 46 | self.selectedIndex = 2; | ||
| 47 | self:updateSelectedState(); | ||
| 48 | end | ||
| 49 | |||
| 50 | function GameOverView:onExit() | ||
| 51 | if self.exitFun then | ||
| 52 | self.exitFun(); | ||
| 53 | end | ||
| 54 | self:close(); | ||
| 55 | end | ||
| 56 | |||
| 57 | function GameOverView:onAgain() | ||
| 58 | local function paySuccessFun() | ||
| 59 | if self.againFun then | ||
| 60 | self.againFun(); | ||
| 61 | end | ||
| 62 | self:close(); | ||
| 63 | end | ||
| 64 | |||
| 65 | if IS_XHX then | ||
| 66 | paySuccessFun(); | ||
| 67 | elseif CHANNEL == "shdx" and game_data.get_game_play_cnt() > 0 then | ||
| 68 | local reciever = require("app.views.rubbish.GamePayView"):show("",paySuccessFun); | ||
| 69 | cc.Director:getInstance():getRunningScene().keypadManager:addKeypadReceiver(reciever); | ||
| 70 | elseif CHANNEL == "ws" then | ||
| 71 | local unlock_price = 9.9; | ||
| 72 | local function onPaySuccessCallBack(result) | ||
| 73 | if result == "success" then | ||
| 74 | UmengHelper.pay(unlock_price.."&1"); | ||
| 75 | game_data.set_is_vip(1); | ||
| 76 | self:onAgain(); | ||
| 77 | end | ||
| 78 | end | ||
| 79 | local function okPayFun() | ||
| 80 | UmengHelper.onEvent("unlock_click"); | ||
| 81 | ShopModel.pay("tjlhxkgxyx_unlock","永久解锁",unlock_price,onPaySuccessCallBack,timeoutCallBack); | ||
| 82 | end | ||
| 83 | if game_data.get_is_vip() == 0 and game_data.get_game_play_cnt() >= 3 then | ||
| 84 | local receiver = require("app.views.view.AlertView"):show({msg="您的免费试玩已结束,是否花"..unlock_price.."元付费解锁?"},okPayFun,nil,1); | ||
| 85 | cc.Director:getInstance():getRunningScene().keypadManager:addKeypadReceiver(receiver); | ||
| 86 | return; | ||
| 87 | else | ||
| 88 | paySuccessFun(); | ||
| 89 | end | ||
| 90 | else | ||
| 91 | paySuccessFun(); | ||
| 92 | end | ||
| 93 | end | ||
| 94 | |||
| 95 | --返回键处理函数 | ||
| 96 | function GameOverView:onKeypadBack() | ||
| 97 | self:onExit(); | ||
| 98 | end | ||
| 99 | |||
| 100 | return GameOverView | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local GamePayConfirmView = dialog.uinode("ui/rubbish/GamePayConfirmLayer.csb",import("..view.BaseView")) | ||
| 2 | |||
| 3 | function GamePayConfirmView:ctor() | ||
| 4 | GamePayConfirmView.super.ctor(self); | ||
| 5 | end | ||
| 6 | |||
| 7 | function GamePayConfirmView:show(info,yesFun,noFun) | ||
| 8 | local scene = cc.Director:getInstance():getRunningScene() | ||
| 9 | local inst = GamePayConfirmView:create(); | ||
| 10 | scene:addChild(inst, dialog.ZORDER_POP); | ||
| 11 | |||
| 12 | inst.yesFun = yesFun; | ||
| 13 | inst.noFun = noFun; | ||
| 14 | |||
| 15 | inst:init(); | ||
| 16 | |||
| 17 | return inst; | ||
| 18 | end | ||
| 19 | |||
| 20 | function GamePayConfirmView:init() | ||
| 21 | self:setContentSize(cc.size(display.width,display.height)); | ||
| 22 | ccui.Helper:doLayout(self); | ||
| 23 | |||
| 24 | local btn_yes = self:getChildByName("panel"):getChildByName("btn_yes"); | ||
| 25 | btn_yes.fn = handler(self,self.onYes); | ||
| 26 | btn_yes:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, btn_yes.fn)end); | ||
| 27 | |||
| 28 | local btn_no = self:getChildByName("panel"):getChildByName("btn_no"); | ||
| 29 | btn_no.fn = handler(self,self.onNo); | ||
| 30 | btn_no:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, btn_no.fn)end); | ||
| 31 | |||
| 32 | self:getChildByName("panel"):getChildByName("txt"):setString(PAY_PRICE_SHDX); | ||
| 33 | |||
| 34 | self.nodes[1] = {btn_yes,btn_no}; | ||
| 35 | self.nodeIndex = 1 | ||
| 36 | self.selectedIndex = 1; | ||
| 37 | self:updateSelectedState(); | ||
| 38 | end | ||
| 39 | |||
| 40 | function GamePayConfirmView:onYes() | ||
| 41 | if self.is_paying then | ||
| 42 | return; | ||
| 43 | end | ||
| 44 | self.is_paying = true; | ||
| 45 | local function onPaySuccessCallBack(result) | ||
| 46 | print("pay result ------------ "..result); | ||
| 47 | if result == "success" then | ||
| 48 | UmengHelper.onEvent("xyx_pay_success"); | ||
| 49 | else | ||
| 50 | UmengHelper.onEvent("xyx_pay_fail"); | ||
| 51 | --失败(概率1/5),后台再调用支付,会闪退,由于上海电信测试流程太复杂,不调了 | ||
| 52 | -- ShopModel.pay(PAY_ID_SHDX,"1元体验游戏",1,nil,nil); | ||
| 53 | end | ||
| 54 | if self.yesFun then | ||
| 55 | self.yesFun(); | ||
| 56 | end | ||
| 57 | self.is_paying = false; | ||
| 58 | self:close(); | ||
| 59 | end | ||
| 60 | |||
| 61 | ShopModel.pay(PAY_ID_SHDX,PAY_PRICE_SHDX.."元体验游戏",PAY_PRICE_SHDX,onPaySuccessCallBack); | ||
| 62 | end | ||
| 63 | |||
| 64 | function GamePayConfirmView:onNo() | ||
| 65 | if self.noFun then | ||
| 66 | self.noFun(); | ||
| 67 | end | ||
| 68 | self:close(); | ||
| 69 | end | ||
| 70 | |||
| 71 | --返回键处理函数 | ||
| 72 | function GamePayConfirmView:onKeypadBack() | ||
| 73 | if self.noFun then | ||
| 74 | self.noFun(); | ||
| 75 | end | ||
| 76 | self:close(); | ||
| 77 | end | ||
| 78 | |||
| 79 | return GamePayConfirmView | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local GamePayView = dialog.uinode("ui/rubbish/GamePayLayer.csb",import("..view.BaseView")) | ||
| 2 | |||
| 3 | require("app.model.ShopModel"); | ||
| 4 | |||
| 5 | function GamePayView:ctor() | ||
| 6 | GamePayView.super.ctor(self); | ||
| 7 | end | ||
| 8 | |||
| 9 | function GamePayView:show(info,yesFun,noFun) | ||
| 10 | local scene = cc.Director:getInstance():getRunningScene() | ||
| 11 | local inst = GamePayView:create(); | ||
| 12 | scene:addChild(inst, dialog.ZORDER_POP); | ||
| 13 | |||
| 14 | local panel = inst:getChildByName("panel"); | ||
| 15 | panel:setScale(0.5); | ||
| 16 | local scaleTo = cc.ScaleTo:create(0.2,1); | ||
| 17 | panel:runAction(scaleTo); | ||
| 18 | |||
| 19 | inst.yesFun = yesFun; | ||
| 20 | inst.noFun = noFun; | ||
| 21 | |||
| 22 | inst:init(); | ||
| 23 | |||
| 24 | return inst; | ||
| 25 | end | ||
| 26 | |||
| 27 | function GamePayView:init() | ||
| 28 | self:setContentSize(cc.size(display.width,display.height)); | ||
| 29 | ccui.Helper:doLayout(self); | ||
| 30 | |||
| 31 | local btn_yes = self:getChildByName("panel"):getChildByName("btn_yes"); | ||
| 32 | btn_yes.fn = handler(self,self.onYes); | ||
| 33 | btn_yes:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, btn_yes.fn)end); | ||
| 34 | |||
| 35 | local btn_no = self:getChildByName("panel"):getChildByName("btn_no"); | ||
| 36 | btn_no.fn = handler(self,self.onNo); | ||
| 37 | btn_no:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, btn_no.fn)end); | ||
| 38 | |||
| 39 | self:getChildByName("panel"):getChildByName("txt"):setString(PAY_PRICE_SHDX); | ||
| 40 | |||
| 41 | self.nodes[1] = {btn_no,btn_yes}; | ||
| 42 | self.nodeIndex = 1; | ||
| 43 | self.selectedIndex = 2; | ||
| 44 | self:updateSelectedState(); | ||
| 45 | end | ||
| 46 | |||
| 47 | function GamePayView:onYes() | ||
| 48 | local function payConfirmSuccessFun() | ||
| 49 | if self.yesFun then | ||
| 50 | self.yesFun(); | ||
| 51 | end | ||
| 52 | self:close(); | ||
| 53 | end | ||
| 54 | |||
| 55 | local reciever = require("app.views.rubbish.GamePayConfirmView"):show("",payConfirmSuccessFun); | ||
| 56 | cc.Director:getInstance():getRunningScene().keypadManager:addKeypadReceiver(reciever); | ||
| 57 | end | ||
| 58 | |||
| 59 | function GamePayView:onNo() | ||
| 60 | if self.noFun then | ||
| 61 | self.noFun(); | ||
| 62 | end | ||
| 63 | self:close(); | ||
| 64 | end | ||
| 65 | |||
| 66 | --返回键处理函数 | ||
| 67 | function GamePayView:onKeypadBack() | ||
| 68 | if self.noFun then | ||
| 69 | self.noFun(); | ||
| 70 | end | ||
| 71 | self:close(); | ||
| 72 | end | ||
| 73 | |||
| 74 | return GamePayView | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local GameScene = class("GameScene", import("..scene/BaseSceneNew")); | ||
| 2 | |||
| 3 | local Rubbish = require("app/views/rubbish/Rubbish"); | ||
| 4 | local game_data = require("app/views/rubbish/game_data"); | ||
| 5 | |||
| 6 | local speed = 100; | ||
| 7 | |||
| 8 | function GameScene:ctor(params) | ||
| 9 | GameScene.super.ctor(self); | ||
| 10 | self:onCreate(params); | ||
| 11 | end | ||
| 12 | |||
| 13 | function GameScene:onCreate(params) | ||
| 14 | self.keypadManager = KeypadManager:create(self); | ||
| 15 | |||
| 16 | self.ui = cc.CSLoader:createNode("ui/rubbish/GameScene.csb"); | ||
| 17 | self:addChild(self.ui); | ||
| 18 | |||
| 19 | self.ui:setContentSize(cc.size(display.width,display.height)); | ||
| 20 | ccui.Helper:doLayout(self.ui); | ||
| 21 | |||
| 22 | self.panel = self.ui:getChildByName("panel"); | ||
| 23 | |||
| 24 | if CHANNEL == "shdx" then | ||
| 25 | self.girl = cc.CSLoader:createNode("ui/rubbish/Girl_shdx.csb"); | ||
| 26 | else | ||
| 27 | self.girl = cc.CSLoader:createNode("ui/rubbish/Girl.csb"); | ||
| 28 | end | ||
| 29 | self.girl:setPosition(cc.p(display.width/2,0)); | ||
| 30 | self.panel:addChild(self.girl); | ||
| 31 | self.shield = self.girl:getChildByName("shield"); | ||
| 32 | self.magnet = self.girl:getChildByName("magnet"); | ||
| 33 | self.flash = self.girl:getChildByName("flash"); | ||
| 34 | self.pokect = self.girl:getChildByName("pokect"); | ||
| 35 | self.shield:hide(); | ||
| 36 | self.magnet:hide(); | ||
| 37 | self.flash:hide(); | ||
| 38 | |||
| 39 | self.direction = 0; | ||
| 40 | |||
| 41 | self.tips_show = self.panel:getChildByName("tips_show"); | ||
| 42 | self.tips_show:setLocalZOrder(50); | ||
| 43 | self.txt_score = self.panel:getChildByName("guess_num"):getChildByName("txt"); | ||
| 44 | self.txt_best = self.panel:getChildByName("best"):getChildByName("txt"); | ||
| 45 | |||
| 46 | SoundManager.playMusic("res/ui/rubbish/BGM.mp3"); | ||
| 47 | audio.preloadSound("res/ui/rubbish/game_lose.mp3"); | ||
| 48 | audio.preloadSound("res/ui/rubbish/maigc.mp3"); | ||
| 49 | |||
| 50 | self.range_value = 50; | ||
| 51 | local function onNodeEventHandler(event) | ||
| 52 | if event == "enter" then | ||
| 53 | self:initGame(); | ||
| 54 | |||
| 55 | if IS_XHX and UserModel.pk_uid > 0 then | ||
| 56 | self:startGame(); | ||
| 57 | else | ||
| 58 | self:showStartView(); | ||
| 59 | end | ||
| 60 | elseif event == "exit" then | ||
| 61 | ccs.ArmatureDataManager:getInstance():removeArmatureFileInfo(string.format("res/ui/rubbish/%s/%s.ExportJson","color_rubbish","color_rubbish")); | ||
| 62 | audio.unloadSound("res/ui/rubbish/game_lose.mp3"); | ||
| 63 | audio.unloadSound("res/ui/rubbish/maigc.mp3"); | ||
| 64 | end | ||
| 65 | end | ||
| 66 | self:registerScriptHandler(onNodeEventHandler); | ||
| 67 | end | ||
| 68 | |||
| 69 | function GameScene:initGame() | ||
| 70 | self.score = 0; | ||
| 71 | self.is_shield = false; | ||
| 72 | self.is_magnet = false; | ||
| 73 | |||
| 74 | self.tips_show:show(); | ||
| 75 | self.tips_show:runAction(cc.FadeIn:create(1)); | ||
| 76 | self.txt_score:setString(self.score); | ||
| 77 | self.txt_best:setString(game_data.best); | ||
| 78 | |||
| 79 | self.girl:setColor(cc.c3b(255,255,255)); | ||
| 80 | |||
| 81 | -- if self.move_schedule then | ||
| 82 | -- self:stopAction(self.move_schedule); | ||
| 83 | -- self.move_schedule = nil; | ||
| 84 | -- end | ||
| 85 | |||
| 86 | if self.rubbish_create_schedule then | ||
| 87 | self:stopAction(self.rubbish_create_schedule); | ||
| 88 | self.rubbish_create_schedule = nil; | ||
| 89 | end | ||
| 90 | if self.boom_create_schedule then | ||
| 91 | self:stopAction(self.boom_create_schedule); | ||
| 92 | self.boom_create_schedule = nil; | ||
| 93 | end | ||
| 94 | if self.shield_create_schedule then | ||
| 95 | self:stopAction(self.shield_create_schedule); | ||
| 96 | self.shield_create_schedule = nil; | ||
| 97 | end | ||
| 98 | if self.color_create_schedule then | ||
| 99 | self:stopAction(self.color_create_schedule); | ||
| 100 | self.color_create_schedule = nil; | ||
| 101 | end | ||
| 102 | if self.collision_schedule then | ||
| 103 | self:stopAction(self.collision_schedule); | ||
| 104 | self.collision_schedule = nil; | ||
| 105 | end | ||
| 106 | |||
| 107 | self.is_rubbish_init = false; | ||
| 108 | self:removeItems(); | ||
| 109 | end | ||
| 110 | |||
| 111 | function GameScene:showStartView() | ||
| 112 | local reciever = require("app.views.rubbish.GameStartView"):show(handler(self,self.startGame)); | ||
| 113 | self.keypadManager:addKeypadReceiver(reciever); | ||
| 114 | end | ||
| 115 | --开始游戏 | ||
| 116 | function GameScene:startGame() | ||
| 117 | self.is_starting = true; | ||
| 118 | |||
| 119 | self.current_item_list = {}; | ||
| 120 | |||
| 121 | -- self.move_schedule = schedule(self,handler(self,self.onMove),0); | ||
| 122 | self.rubbish_create_schedule = schedule(self,handler(self,self.createRubbishFun),3); | ||
| 123 | --self.boom_create_schedule = schedule(self,handler(self,self.createBoomFun),5); | ||
| 124 | --self.shield_create_schedule = schedule(self,handler(self,self.createShieldFun),8); | ||
| 125 | --self.color_create_schedule = schedule(self,handler(self,self.createColorFun),10); | ||
| 126 | --self.collision_schedule = schedule(self,handler(self,self.update),0); | ||
| 127 | |||
| 128 | --self:createRubbishFun(); | ||
| 129 | -- self:createBoomFun(); | ||
| 130 | -- self:createShieldFun(); | ||
| 131 | -- self:createColorFun(); | ||
| 132 | end | ||
| 133 | |||
| 134 | function GameScene:onMove() | ||
| 135 | if self.direction == 0 then | ||
| 136 | return; | ||
| 137 | end | ||
| 138 | |||
| 139 | local _x,_y = self.girl:getPosition(); | ||
| 140 | local to_x = _x + self.direction*speed; | ||
| 141 | if to_x <= 0 then | ||
| 142 | to_x = 0; | ||
| 143 | -- self.direction = -self.direction; | ||
| 144 | elseif to_x >= 1280 then | ||
| 145 | to_x = 1280; | ||
| 146 | -- self.direction = -self.direction; | ||
| 147 | end | ||
| 148 | if self.girl.move_action then | ||
| 149 | self.girl:stopAction(self.girl.move_action); | ||
| 150 | end | ||
| 151 | |||
| 152 | local distance = math.abs(to_x-_x); | ||
| 153 | -- print(distance/1000) | ||
| 154 | self.girl.move_action = self.girl:runAction(cc.MoveTo:create(distance/1000,cc.p(to_x,_y))); | ||
| 155 | -- self.girl:setPositionX(to_x); | ||
| 156 | end | ||
| 157 | |||
| 158 | function GameScene:createRubbishFun() | ||
| 159 | if not self.tmp_index then | ||
| 160 | self.tmp_index = 1; | ||
| 161 | end | ||
| 162 | --该分数情况下的游戏难度 | ||
| 163 | local _info = game_data.get_info_by_score(self.score); | ||
| 164 | |||
| 165 | --创建糖果 | ||
| 166 | local rubbish_id_list = game_data.get_animal_list_by_type(_info.animal_type); | ||
| 167 | math.randomseed(tostring(os.time()+(self.tmp_index+55)):reverse():sub(1, 6)); | ||
| 168 | local _cnt = _info.rubbish_cnt[math.random(1,2)]; | ||
| 169 | for i=1,_cnt do | ||
| 170 | math.randomseed(tostring(os.time()+(self.tmp_index+i+5)):reverse():sub(1, 6)); | ||
| 171 | self.tmp_index = self.tmp_index + 2; | ||
| 172 | local random_id_index = math.random(1,#rubbish_id_list); | ||
| 173 | local id = rubbish_id_list[random_id_index]; | ||
| 174 | |||
| 175 | self:createRubbish(id,-_info.rubbish_speed); | ||
| 176 | end | ||
| 177 | end | ||
| 178 | |||
| 179 | function GameScene:createBoomFun() | ||
| 180 | local _info = game_data.get_info_by_score(self.score); | ||
| 181 | --创建炸弹 | ||
| 182 | math.randomseed(tostring(os.time()+(self.tmp_index+13)):reverse():sub(1, 6)); | ||
| 183 | self.tmp_index = self.tmp_index + 1; | ||
| 184 | local _cnt = _info.boom_cnt[math.random(1,2)]; | ||
| 185 | for i=1,_cnt do | ||
| 186 | self:createRubbish(1,-_info.boom_speed); | ||
| 187 | end | ||
| 188 | end | ||
| 189 | --防护罩 | ||
| 190 | function GameScene:createShieldFun() | ||
| 191 | local _info = game_data.get_info_by_score(self.score); | ||
| 192 | |||
| 193 | --创建磁铁 | ||
| 194 | math.randomseed(tostring(os.time()+(self.tmp_index+33)):reverse():sub(1, 6)); | ||
| 195 | self.tmp_index = self.tmp_index + 6; | ||
| 196 | if math.random(1,100) <= _info.magnet_rate then | ||
| 197 | self:createRubbish(2,-_info.magnet_speed); | ||
| 198 | end | ||
| 199 | |||
| 200 | --创建护盾 | ||
| 201 | math.randomseed(tostring(os.time()+(self.tmp_index+535)):reverse():sub(1, 6)); | ||
| 202 | self.tmp_index = self.tmp_index + 3; | ||
| 203 | if math.random(1,100) <= _info.shield_rate then | ||
| 204 | self:createRubbish(3,-_info.shield_speed); | ||
| 205 | end | ||
| 206 | end | ||
| 207 | |||
| 208 | function GameScene:createColorFun() | ||
| 209 | local _info = game_data.get_info_by_score(self.score); | ||
| 210 | --创建彩糖 | ||
| 211 | math.randomseed(tostring(os.time()+(self.tmp_index+535)):reverse():sub(1, 6)); | ||
| 212 | self.tmp_index = self.tmp_index + 3; | ||
| 213 | if math.random(1,100) <= _info.color_rate then | ||
| 214 | self:createRubbish(4001,-_info.color_speed); | ||
| 215 | end | ||
| 216 | end | ||
| 217 | |||
| 218 | function GameScene:createRubbish(id,speed) | ||
| 219 | local rubbish = Rubbish:create(id); | ||
| 220 | local rect = rubbish:getBoundingBox(); | ||
| 221 | rubbish.id = id; | ||
| 222 | math.randomseed(tostring(os.time()+id+self.tmp_index+3362):reverse():sub(1, 6)); | ||
| 223 | self.tmp_index = self.tmp_index + 4; | ||
| 224 | local rubbish_start_x = math.random(rect.width,display.width-rect.width); | ||
| 225 | local rubbish_start_y = display.height + rect.height/2; | ||
| 226 | if id == 1 then | ||
| 227 | print("炸弹:"..rect.width,display.width-rect.width,rubbish_start_x); | ||
| 228 | end | ||
| 229 | rubbish:setPosition(cc.p(rubbish_start_x,rubbish_start_y)); | ||
| 230 | self.panel:addChild(rubbish,5); | ||
| 231 | math.randomseed(tostring(os.time()+id+(self.tmp_index+5553)):reverse():sub(1, 6)); | ||
| 232 | self.tmp_index = self.tmp_index + 5; | ||
| 233 | self.current_item_list[#self.current_item_list+1] = rubbish; | ||
| 234 | |||
| 235 | local _interval = 0; | ||
| 236 | if not self.is_rubbish_init then | ||
| 237 | self.is_rubbish_init = true; | ||
| 238 | _interval = 2; | ||
| 239 | elseif id == 1 then | ||
| 240 | _interval = 5; | ||
| 241 | elseif id == 2 or id == 3 then | ||
| 242 | _interval = 8; | ||
| 243 | elseif id < 4000 then | ||
| 244 | _interval = 3; | ||
| 245 | elseif id > 4000 then | ||
| 246 | _interval = 10; | ||
| 247 | end | ||
| 248 | |||
| 249 | math.randomseed(tostring(os.time()+id+(self.tmp_index+956)):reverse():sub(1, 6)); | ||
| 250 | rubbish:runAction(cc.Sequence:create(cc.DelayTime:create(math.random(1,_interval*100)*0.01),cc.CallFunc:create(function () | ||
| 251 | rubbish:start_move(speed); | ||
| 252 | end))); | ||
| 253 | end | ||
| 254 | |||
| 255 | function GameScene:update() | ||
| 256 | local girl_p = cc.p(self.girl:getPosition()); | ||
| 257 | local girl_center_p = cc.p(girl_p.x,girl_p.y+189); | ||
| 258 | |||
| 259 | if self.is_shield then | ||
| 260 | for i=#self.current_item_list,1,-1 do | ||
| 261 | local rubbish = self.current_item_list[i]; | ||
| 262 | if rubbish.id == 1 then | ||
| 263 | local p = cc.p(rubbish:getPosition()); | ||
| 264 | local _dis = Point.distance(p,girl_center_p); | ||
| 265 | if _dis <= 225 then | ||
| 266 | table.remove(self.current_item_list,i); | ||
| 267 | rubbish:stopAllActions(); | ||
| 268 | rubbish:removeSelf(); | ||
| 269 | end | ||
| 270 | end | ||
| 271 | end | ||
| 272 | end | ||
| 273 | |||
| 274 | local rc_pocket = self.pokect:getBoundingBox(); | ||
| 275 | local w_p = self.pokect:convertToWorldSpace(cc.p(0,0)); | ||
| 276 | local l_p = self.panel:convertToNodeSpace(w_p); | ||
| 277 | rc_pocket.x = l_p.x; | ||
| 278 | rc_pocket.y = l_p.y; | ||
| 279 | for i=#self.current_item_list,1,-1 do | ||
| 280 | local rubbish = self.current_item_list[i]; | ||
| 281 | local rc_rubbish = rubbish:getBoundingBox(); | ||
| 282 | if cc.rectIntersectsRect(rc_rubbish, rc_pocket) then | ||
| 283 | local w_c_p = rubbish:convertToWorldSpace(cc.p(0,0)); | ||
| 284 | local l_c_p = self.panel:convertToNodeSpace(w_c_p); | ||
| 285 | if rubbish.id == 1 then | ||
| 286 | if not self.is_shield then | ||
| 287 | self:gameOver(); | ||
| 288 | end | ||
| 289 | elseif rubbish.id == 2 then | ||
| 290 | self.is_magnet = true; | ||
| 291 | self.magnet:show(); | ||
| 292 | self:showMagnetCountDown(4,function() | ||
| 293 | self.magnet:hide(); | ||
| 294 | self.is_magnet = false; | ||
| 295 | end); | ||
| 296 | elseif rubbish.id == 3 then | ||
| 297 | self.is_shield = true; | ||
| 298 | self.shield:show(); | ||
| 299 | self:showShieldCountDown(4,function() | ||
| 300 | self.shield:hide(); | ||
| 301 | self.is_shield = false; | ||
| 302 | end); | ||
| 303 | elseif rubbish.id > 1000 then | ||
| 304 | local rubbish_info = game_data.get_animal_info(rubbish.id); | ||
| 305 | self:showScore(rubbish_info.score,l_c_p); | ||
| 306 | self:showRubbishFlash(rubbish); | ||
| 307 | end | ||
| 308 | table.remove(self.current_item_list,i); | ||
| 309 | rubbish:removeSelf(); | ||
| 310 | elseif rc_rubbish.y < -rc_rubbish.height then | ||
| 311 | table.remove(self.current_item_list,i); | ||
| 312 | rubbish:removeSelf(); | ||
| 313 | end | ||
| 314 | end | ||
| 315 | |||
| 316 | if self.is_magnet then | ||
| 317 | local poket_y = 95; | ||
| 318 | for i=#self.current_item_list,1,-1 do | ||
| 319 | local rubbish = self.current_item_list[i]; | ||
| 320 | if rubbish.id > 1000 and not rubbish.is_go then | ||
| 321 | local p = cc.p(rubbish:getPosition()); | ||
| 322 | local _dis = Point.distance(p,girl_center_p); | ||
| 323 | if _dis <= 500 and p.y >= poket_y then | ||
| 324 | table.remove(self.current_item_list,i); | ||
| 325 | rubbish:stopAllActions(); | ||
| 326 | rubbish.is_go = true; | ||
| 327 | rubbish:runAction(cc.Sequence:create(cc.MoveTo:create(0.5,cc.p(girl_center_p.x,poket_y)),cc.CallFunc:create(function() | ||
| 328 | local rubbish_info = game_data.get_animal_info(rubbish.id); | ||
| 329 | self:showScore(rubbish_info.score,cc.p(math.random(girl_center_p.x-100,girl_center_p.x+100),math.random(girl_center_p.y-15,girl_center_p.y+15))); | ||
| 330 | rubbish:removeSelf(); | ||
| 331 | self:showRubbishFlash(rubbish); | ||
| 332 | end))); | ||
| 333 | end | ||
| 334 | end | ||
| 335 | end | ||
| 336 | end | ||
| 337 | end | ||
| 338 | |||
| 339 | function GameScene:showRubbishFlash(rubbish) | ||
| 340 | self.flash:show(); | ||
| 341 | self.flash:getAnimation():play("Animation1"); | ||
| 342 | self.flash:getAnimation():setMovementEventCallFunc(function(arm, eventType, movmentID) | ||
| 343 | if (eventType == ccs.MovementEventType.complete or eventType == ccs.MovementEventType.loopComplete) then | ||
| 344 | self.flash:hide(); | ||
| 345 | end | ||
| 346 | end) | ||
| 347 | end | ||
| 348 | |||
| 349 | function GameScene:showScore(score,point) | ||
| 350 | -- 飘+1 | ||
| 351 | local level_pop = cc.CSLoader:createNode("ui/rubbish/LevelPop.csb"); | ||
| 352 | |||
| 353 | local add_score = score or 1; | ||
| 354 | -- for i=self.score+1,self.score + add_score do | ||
| 355 | -- if IS_XHX then | ||
| 356 | -- local game_info = SingleGameInfo.get_game_info(EnumGame.RUBBISH); | ||
| 357 | -- if TableUtil.IsInTable(game_info.score_list,i) then | ||
| 358 | -- SocketClient:getInstance():send("gateway_msg.single_game_msg",{id = game_info.id,score=i}); | ||
| 359 | -- end | ||
| 360 | -- end | ||
| 361 | -- end | ||
| 362 | |||
| 363 | self.score = self.score + score; | ||
| 364 | if self.score > game_data.best then | ||
| 365 | game_data.set_best_score(self.score); | ||
| 366 | end | ||
| 367 | self.txt_score:setString(self.score); | ||
| 368 | level_pop:getChildByName("txt"):setString("+"..score); | ||
| 369 | self.panel:addChild(level_pop); | ||
| 370 | level_pop:setPosition(point); | ||
| 371 | level_pop:runAction(cc.MoveBy:create(1,cc.p(0,30))); | ||
| 372 | local effAction = cc.Sequence:create(cc.FadeOut:create(1),cc.CallFunc:create(function() | ||
| 373 | level_pop:removeFromParent(); | ||
| 374 | end)); | ||
| 375 | level_pop:runAction(effAction); | ||
| 376 | end | ||
| 377 | |||
| 378 | function GameScene:onShowNextComplete() | ||
| 379 | self.is_show_result = false; | ||
| 380 | self:showNextAnimal(); | ||
| 381 | end | ||
| 382 | |||
| 383 | function GameScene:removeItems() | ||
| 384 | if self.current_item_list then | ||
| 385 | for i,v in ipairs(self.current_item_list) do | ||
| 386 | v:removeSelf(); | ||
| 387 | end | ||
| 388 | end | ||
| 389 | self.current_item_list = {}; | ||
| 390 | end | ||
| 391 | |||
| 392 | function GameScene:showShieldCountDown(_countdown,_callback) | ||
| 393 | self:stopShieldCountDown(); | ||
| 394 | |||
| 395 | local _cd = _countdown; | ||
| 396 | |||
| 397 | local _this = self; | ||
| 398 | local function countdown_fn() | ||
| 399 | if _cd <= 0 then | ||
| 400 | _this:stopShieldCountDown(); | ||
| 401 | if _callback then | ||
| 402 | _callback(); | ||
| 403 | end | ||
| 404 | return; | ||
| 405 | end | ||
| 406 | _cd = _cd - 1; | ||
| 407 | end | ||
| 408 | self.shield_countdown_schedule = schedule(self,countdown_fn,1); | ||
| 409 | end | ||
| 410 | |||
| 411 | function GameScene:stopShieldCountDown() | ||
| 412 | if self.shield_countdown_schedule then | ||
| 413 | self:stopAction(self.shield_countdown_schedule); | ||
| 414 | self.shield_countdown_schedule = nil; | ||
| 415 | end | ||
| 416 | end | ||
| 417 | |||
| 418 | function GameScene:showMagnetCountDown(_countdown,_callback) | ||
| 419 | self:stopMagnetCountDown(); | ||
| 420 | |||
| 421 | local _cd = _countdown; | ||
| 422 | |||
| 423 | local _this = self; | ||
| 424 | local _is_clock_ring = false; | ||
| 425 | local function countdown_fn() | ||
| 426 | if _cd <= 0 then | ||
| 427 | _this:stopMagnetCountDown(); | ||
| 428 | if _callback then | ||
| 429 | _callback(); | ||
| 430 | end | ||
| 431 | return; | ||
| 432 | end | ||
| 433 | _cd = _cd - 1; | ||
| 434 | end | ||
| 435 | self.magnet_countdown_schedule = schedule(self,countdown_fn,1); | ||
| 436 | end | ||
| 437 | |||
| 438 | function GameScene:stopMagnetCountDown() | ||
| 439 | if self.magnet_countdown_schedule then | ||
| 440 | self:stopAction(self.magnet_countdown_schedule); | ||
| 441 | self.magnet_countdown_schedule = nil; | ||
| 442 | end | ||
| 443 | end | ||
| 444 | |||
| 445 | function GameScene:gameOver() | ||
| 446 | SoundManager.playEffect("res/ui/rubbish/game_lose.mp3"); | ||
| 447 | |||
| 448 | self.magnet:hide(); | ||
| 449 | self.shield:hide(); | ||
| 450 | self.flash:hide(); | ||
| 451 | self.girl:setColor(cc.c3b(0,0,0)); | ||
| 452 | self:pause(); | ||
| 453 | |||
| 454 | local function game_over_fn() | ||
| 455 | if IS_XHX then | ||
| 456 | if UserModel.pk_uid > 0 then | ||
| 457 | local reciever = require("app.views.view.XyxPkResultView"):show(self.score,handler(self,self.onGamePkExit)); | ||
| 458 | self.keypadManager:addKeypadReceiver(reciever); | ||
| 459 | SocketClient:getInstance():send("gateway_msg.single_game_pk_end_msg",{id = EnumGame.RUBBISH,score=self.score,peer_score=UserModel.pk_other_score,peer_uid=UserModel.pk_uid}); | ||
| 460 | else | ||
| 461 | local reciever = require("app.views.view.XyxGameOver"):show({level=self.score,best=tonumber(self.txt_best:getString())},handler(self,self.onGameExit),handler(self,self.onGameAgain)); | ||
| 462 | self.keypadManager:addKeypadReceiver(reciever); | ||
| 463 | SocketClient:getInstance():send("gateway_msg.single_game_end_msg",{id = EnumGame.RUBBISH,score=self.score}); | ||
| 464 | end | ||
| 465 | elseif CHANNEL == "shdx" then | ||
| 466 | local reciever = require("app.views.rubbish.GameOverView"):show({level=self.score,best=tonumber(self.txt_best:getString())},handler(self,self.onGameExit),handler(self,self.onGameAgain)); | ||
| 467 | self.keypadManager:addKeypadReceiver(reciever); | ||
| 468 | else | ||
| 469 | local reciever = require("app.views.rubbish.GameOverView"):show({level=self.score,best=tonumber(self.txt_best:getString())},handler(self,self.onGameExit),handler(self,self.onGameAgain)); | ||
| 470 | self.keypadManager:addKeypadReceiver(reciever); | ||
| 471 | end | ||
| 472 | end | ||
| 473 | |||
| 474 | self.girl:runAction(cc.Sequence:create(cc.DelayTime:create(0.5),cc.CallFunc:create(game_over_fn))); | ||
| 475 | end | ||
| 476 | |||
| 477 | function GameScene:pause() | ||
| 478 | for i,v in ipairs(self.current_item_list) do | ||
| 479 | cc.Director:getInstance():getActionManager():pauseTarget(v); | ||
| 480 | end | ||
| 481 | cc.Director:getInstance():getActionManager():pauseTarget(self); | ||
| 482 | end | ||
| 483 | |||
| 484 | function GameScene:resume() | ||
| 485 | for i,v in ipairs(self.current_item_list) do | ||
| 486 | cc.Director:getInstance():getActionManager():resumeTarget(v); | ||
| 487 | end | ||
| 488 | cc.Director:getInstance():getActionManager():resumeTarget(self); | ||
| 489 | end | ||
| 490 | |||
| 491 | function GameScene:onGamePkExit() | ||
| 492 | app:enterScene("LoadingScene",{nextSceneName="OtherHomeScene",class_name="app.views.view.FriendView",user_home=UserModel.pk_user_home}); | ||
| 493 | end | ||
| 494 | |||
| 495 | function GameScene:onGameExit() | ||
| 496 | self:resume(); | ||
| 497 | self:stopShieldCountDown(); | ||
| 498 | self:stopMagnetCountDown(); | ||
| 499 | self:initGame(); | ||
| 500 | self:showStartView(); | ||
| 501 | end | ||
| 502 | |||
| 503 | function GameScene:onGameContinue() | ||
| 504 | self.girl:setColor(cc.c3b(255,255,255)); | ||
| 505 | self:stopShieldCountDown(); | ||
| 506 | self:stopMagnetCountDown(); | ||
| 507 | self:resume(); | ||
| 508 | end | ||
| 509 | |||
| 510 | function GameScene:onGameAgain() | ||
| 511 | self:resume(); | ||
| 512 | self:stopShieldCountDown(); | ||
| 513 | self:stopMagnetCountDown(); | ||
| 514 | self:initGame(); | ||
| 515 | self:startGame(); | ||
| 516 | end | ||
| 517 | |||
| 518 | --返回键处理函数 | ||
| 519 | function GameScene:onKeypadBack() | ||
| 520 | local function okFun() | ||
| 521 | if IS_XHX and UserModel.pk_uid > 0 then | ||
| 522 | self:onGamePkExit(); | ||
| 523 | SocketClient:getInstance():send("gateway_msg.single_game_pk_end_msg",{id = EnumGame.RUBBISH,score=self.score,peer_score=UserModel.pk_other_score,peer_uid=UserModel.pk_uid}); | ||
| 524 | else | ||
| 525 | if IS_XHX then | ||
| 526 | SocketClient:getInstance():send("gateway_msg.single_game_end_msg",{id = EnumGame.RUBBISH,score=self.score}); | ||
| 527 | end | ||
| 528 | self:onGameExit(); | ||
| 529 | end | ||
| 530 | end | ||
| 531 | |||
| 532 | local receiver = require("app.views.view.AlertView"):show({msg="你确定不玩了吗?"},okFun,cancelFun,2); | ||
| 533 | self.keypadManager:addKeypadReceiver(receiver); | ||
| 534 | end | ||
| 535 | |||
| 536 | --确认键处理函数 | ||
| 537 | function GameScene:onKeypadOk() | ||
| 538 | if not self.is_starting then | ||
| 539 | self:startGame(); | ||
| 540 | else | ||
| 541 | if self.selected_node and self.selected_node.fn then | ||
| 542 | self.selected_node.fn(); | ||
| 543 | end | ||
| 544 | end | ||
| 545 | end | ||
| 546 | |||
| 547 | --上键处理函数 | ||
| 548 | function GameScene:onKeypadUp() | ||
| 549 | GameScene.super.onKeypadUp(self,false,true); | ||
| 550 | end | ||
| 551 | |||
| 552 | --下键处理函数 | ||
| 553 | function GameScene:onKeypadDown() | ||
| 554 | GameScene.super.onKeypadDown(self,false,true); | ||
| 555 | end | ||
| 556 | |||
| 557 | --左键处理函数 | ||
| 558 | function GameScene:onKeypadLeft() | ||
| 559 | self.tips_show:hide(); | ||
| 560 | GameScene.super.onKeypadLeft(self,false,true,true); | ||
| 561 | |||
| 562 | self.direction = -1; | ||
| 563 | self:onMove(); | ||
| 564 | end | ||
| 565 | |||
| 566 | --右键处理函数 | ||
| 567 | function GameScene:onKeypadRight() | ||
| 568 | self.tips_show:hide(); | ||
| 569 | GameScene.super.onKeypadRight(self,false,true,true); | ||
| 570 | |||
| 571 | self.direction = 1; | ||
| 572 | self:onMove(); | ||
| 573 | end | ||
| 574 | |||
| 575 | return GameScene | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local GameStartView; | ||
| 2 | if CHANNEL == "shdx" then | ||
| 3 | GameStartView = dialog.uinode("ui/rubbish/GameStartLayer_shdx.csb",import("..view.BaseViewNew")); | ||
| 4 | else | ||
| 5 | GameStartView = dialog.uinode("ui/rubbish/GameStartLayer.csb",import("..view.BaseViewNew")); | ||
| 6 | end | ||
| 7 | |||
| 8 | local game_data = require("app/views/rubbish/game_data"); | ||
| 9 | |||
| 10 | local ox,oy = 1050,128; | ||
| 11 | function GameStartView:ctor() | ||
| 12 | GameStartView.super.ctor(self); | ||
| 13 | end | ||
| 14 | |||
| 15 | function GameStartView:show(onStartFn) | ||
| 16 | local scene = cc.Director:getInstance():getRunningScene() | ||
| 17 | local inst = GameStartView:create(); | ||
| 18 | scene:addChild(inst, dialog.ZORDER_POP); | ||
| 19 | |||
| 20 | inst.onStartFn = onStartFn; | ||
| 21 | |||
| 22 | inst:init(); | ||
| 23 | |||
| 24 | return inst; | ||
| 25 | end | ||
| 26 | |||
| 27 | function GameStartView:init() | ||
| 28 | self:setContentSize(cc.size(display.width,display.height)); | ||
| 29 | ccui.Helper:doLayout(self); | ||
| 30 | |||
| 31 | local btn_start = self:getChildByName("btn_start"); | ||
| 32 | btn_start.fn = handler(self,self.onStart); | ||
| 33 | btn_start:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, btn_start.fn)end); | ||
| 34 | |||
| 35 | local btn_introduce = self:getChildByName("btn_introduce"); | ||
| 36 | btn_introduce.fn = handler(self,self.onIntroduce); | ||
| 37 | btn_introduce:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, btn_introduce.fn)end); | ||
| 38 | |||
| 39 | self.bg_mask = self:getChildByName("bg_mask"); | ||
| 40 | self.bg_mask:hide(); | ||
| 41 | self.game_introduce = self:getChildByName("game_introduce"); | ||
| 42 | self.game_introduce:setLocalZOrder(100); | ||
| 43 | self.game_introduce:hide(); | ||
| 44 | |||
| 45 | self.nodes[1] = {btn_start,btn_introduce}; | ||
| 46 | self:updateSelectedState(btn_start); | ||
| 47 | |||
| 48 | if IS_XHX then | ||
| 49 | btn_introduce:setPosition(cc.p(80,display.height-80)); | ||
| 50 | self:initRankView(); | ||
| 51 | end | ||
| 52 | end | ||
| 53 | |||
| 54 | function GameStartView:initRankView() | ||
| 55 | self.rankView = cc.CSLoader:createNode("ui/xyx/XyxRankLayer.csb"); | ||
| 56 | local rect = self.rankView:getContentSize(); | ||
| 57 | self.rankView:setPosition(cc.p(display.width-rect.width-20,20)); | ||
| 58 | self:addChild(self.rankView); | ||
| 59 | |||
| 60 | for i=1,8 do | ||
| 61 | self.rankView:getChildByName("item_"..i):setVisible(false); | ||
| 62 | end | ||
| 63 | |||
| 64 | self.onRankResFun = handler(self,self.onRankRes); | ||
| 65 | cmsg.on("gateway_msg.single_game_rank_msg_res",self.onRankResFun); | ||
| 66 | SocketClient:getInstance():send("gateway_msg.single_game_rank_msg",{id = EnumGame.RUBBISH}); | ||
| 67 | end | ||
| 68 | |||
| 69 | function GameStartView:onRankRes(params) | ||
| 70 | cmsg.off("gateway_msg.single_game_rank_msg_res",self.onRankResFun); | ||
| 71 | self.rank_list = params.data.game_rank.rank_user; | ||
| 72 | for i=1,8 do | ||
| 73 | local item = self.rankView:getChildByName("item_"..i); | ||
| 74 | if self.rank_list[i] then | ||
| 75 | item:setVisible(true); | ||
| 76 | if StringUtil.GetUTFLen(self.rank_list[i].user_show.nick) >= 16 then | ||
| 77 | item:getChildByName("txt"):setString(StringUtil.getMaxLenString(self.rank_list[i].user_show.nick,12).."..."); | ||
| 78 | else | ||
| 79 | item:getChildByName("txt"):setString(self.rank_list[i].user_show.nick); | ||
| 80 | end | ||
| 81 | if i > 3 then | ||
| 82 | item:getChildByName("txt"):setColor(cc.c3b(255,165,0)); | ||
| 83 | item:getChildByName("txt_score"):setColor(cc.c3b(255,165,0)); | ||
| 84 | end | ||
| 85 | item:getChildByName("txt_score"):setString(self.rank_list[i].val); | ||
| 86 | |||
| 87 | local btn = item:getChildByName("btn"); | ||
| 88 | btn.user_show = self.rank_list[i].user_show; | ||
| 89 | btn.fn = function () | ||
| 90 | self:onOpenUserInfo(btn); | ||
| 91 | end; | ||
| 92 | btn:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, handler(self,self.onOpenUserInfo))end); | ||
| 93 | self.nodes[1][#self.nodes[1]+1] = btn; | ||
| 94 | else | ||
| 95 | item:setVisible(false); | ||
| 96 | end | ||
| 97 | end | ||
| 98 | end | ||
| 99 | |||
| 100 | function GameStartView:onOpenUserInfo(ref) | ||
| 101 | local user_show = ref.user_show; | ||
| 102 | local receiver = require("app.views.view.UserInfoOtherView"):show(user_show); | ||
| 103 | cc.Director:getInstance():getRunningScene().keypadManager:addKeypadReceiver(receiver); | ||
| 104 | end | ||
| 105 | |||
| 106 | function GameStartView:onStart() | ||
| 107 | local function paySuccessFun() | ||
| 108 | if self.onStartFn then | ||
| 109 | self.onStartFn(); | ||
| 110 | end | ||
| 111 | self:close(); | ||
| 112 | end | ||
| 113 | |||
| 114 | if IS_XHX then | ||
| 115 | local game_info = SingleGameInfo.get_game_info(EnumGame.RUBBISH); | ||
| 116 | print("打开小游戏:",game_info.id); | ||
| 117 | if game_info.needVip == 1 and UserModel.getLeftVipDay() == 0 and not TableUtil.IsInTable(UserModel.free_game_id,game_info.id) then | ||
| 118 | print("小游戏购买界面"); | ||
| 119 | local my_diamond_num = UserModel.getDiamond(); | ||
| 120 | if my_diamond_num >= game_info.diamond then | ||
| 121 | Alert.showTwo("玩这游戏需要扣除"..game_info.diamond.."个钻石,是否继续?",paySuccessFun); | ||
| 122 | else | ||
| 123 | local reciever = require("app.views.view.XyxPayView"):show(game_info.id,paySuccessFun); | ||
| 124 | cc.Director:getInstance():getRunningScene().keypadManager:addKeypadReceiver(reciever); | ||
| 125 | end | ||
| 126 | return; | ||
| 127 | else | ||
| 128 | paySuccessFun(); | ||
| 129 | end | ||
| 130 | elseif CHANNEL == "shdx" and game_data.get_game_play_cnt() > 0 then | ||
| 131 | local reciever = require("app.views.rubbish.GamePayView"):show("",paySuccessFun); | ||
| 132 | cc.Director:getInstance():getRunningScene().keypadManager:addKeypadReceiver(reciever); | ||
| 133 | elseif CHANNEL == "ws" then | ||
| 134 | local unlock_price = 9.9; | ||
| 135 | local function onPaySuccessCallBack(result) | ||
| 136 | if result == "success" then | ||
| 137 | UmengHelper.pay(unlock_price.."&1"); | ||
| 138 | game_data.set_is_vip(1); | ||
| 139 | self:onStart(); | ||
| 140 | end | ||
| 141 | end | ||
| 142 | local function okPayFun() | ||
| 143 | UmengHelper.onEvent("unlock_click"); | ||
| 144 | ShopModel.pay("tjlhxkgxyx_unlock","永久解锁",unlock_price,onPaySuccessCallBack,timeoutCallBack); | ||
| 145 | end | ||
| 146 | if game_data.get_is_vip() == 0 and game_data.get_game_play_cnt() >= 3 then | ||
| 147 | local receiver = require("app.views.view.AlertView"):show({msg="您的免费试玩已结束,是否花"..unlock_price.."元付费解锁?"},okPayFun,nil,1); | ||
| 148 | cc.Director:getInstance():getRunningScene().keypadManager:addKeypadReceiver(receiver); | ||
| 149 | return; | ||
| 150 | else | ||
| 151 | paySuccessFun(); | ||
| 152 | end | ||
| 153 | else | ||
| 154 | paySuccessFun(); | ||
| 155 | end | ||
| 156 | end | ||
| 157 | |||
| 158 | function GameStartView:onIntroduce() | ||
| 159 | if not self.game_introduce:isVisible() then | ||
| 160 | self.game_introduce:show(); | ||
| 161 | self.bg_mask:show(); | ||
| 162 | else | ||
| 163 | self.game_introduce:hide(); | ||
| 164 | self.bg_mask:hide(); | ||
| 165 | end | ||
| 166 | end | ||
| 167 | |||
| 168 | function GameStartView:close() | ||
| 169 | if IS_XHX then | ||
| 170 | cmsg.off("gateway_msg.single_game_rank_msg_res",self.onRankResFun); | ||
| 171 | end | ||
| 172 | GameStartView.super.close(self); | ||
| 173 | end | ||
| 174 | |||
| 175 | --返回键处理函数 | ||
| 176 | function GameStartView:onKeypadBack() | ||
| 177 | if not IS_XHX then | ||
| 178 | local function okFun() | ||
| 179 | cc.Director:getInstance():endToLua(); | ||
| 180 | end | ||
| 181 | |||
| 182 | local receiver = require("app.views.view.AlertView"):show({msg="确定要退出游戏?"},okFun,cancelFun,2); | ||
| 183 | cc.Director:getInstance():getRunningScene().keypadManager:addKeypadReceiver(receiver); | ||
| 184 | else | ||
| 185 | cmsg.off("gateway_msg.single_game_rank_msg_res",self.onRankResFun); | ||
| 186 | app:enterScene("LoadingScene",{nextSceneName="MainScene",class_name="app.views.view.XyxView"}); | ||
| 187 | end | ||
| 188 | end | ||
| 189 | |||
| 190 | --隐藏按键 | ||
| 191 | function GameStartView:onKeypadSecrect() | ||
| 192 | if not self.game_introduce:isVisible() then | ||
| 193 | return; | ||
| 194 | end | ||
| 195 | |||
| 196 | clearLogUI(); | ||
| 197 | if DEBUG == 0 then | ||
| 198 | DEBUG = 1; | ||
| 199 | |||
| 200 | logUI("进入调试模式:"); | ||
| 201 | if CHANNEL == "shdx" then | ||
| 202 | self.auto_pay_index = 0; | ||
| 203 | self.auto_pay_cnt = 0; | ||
| 204 | self:autoPay(); | ||
| 205 | end | ||
| 206 | else | ||
| 207 | DEBUG = 0; | ||
| 208 | if self.auto_pay_action then | ||
| 209 | self:stopAction(self.auto_pay_action); | ||
| 210 | self.auto_pay_action = nil; | ||
| 211 | end | ||
| 212 | end | ||
| 213 | end | ||
| 214 | |||
| 215 | function GameStartView:autoPay() | ||
| 216 | if self.auto_pay_cnt >= 417 then | ||
| 217 | self:onKeypadSecrect(); | ||
| 218 | return; | ||
| 219 | end | ||
| 220 | |||
| 221 | if self.auto_pay_index >= 10 then | ||
| 222 | self.auto_pay_index = 0; | ||
| 223 | clearLogUI(); | ||
| 224 | end | ||
| 225 | local tradeNo = tostring(os.time())..math.random(10000,99999); --订单号 | ||
| 226 | local productId = PAY_ID_SHDX; --商品ID | ||
| 227 | local subject = PAY_PRICE_SHDX.."元体验游戏"; --商品名称 | ||
| 228 | local amount = PAY_PRICE_SHDX; --商品价格 | ||
| 229 | local notificationURL = "http://www.baidu.com";--回调URL | ||
| 230 | local peng_bo_shi_token = "123";--鹏博士密钥 | ||
| 231 | |||
| 232 | local function callbackLua(params) | ||
| 233 | if params == "success" then | ||
| 234 | if cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_ANDROID then | ||
| 235 | HttpRequest:getInstance():post("http://139.196.55.173:22999/st",{id=102,gameid=GAME_ID,channel=CHANNEL,account=DeviceUtil.getDeviceId(),price=PAY_PRICE_SHDX}); | ||
| 236 | end | ||
| 237 | logUI("...*"); | ||
| 238 | else | ||
| 239 | logUI("...!"); | ||
| 240 | end | ||
| 241 | end | ||
| 242 | |||
| 243 | local function payCallbackFromJava(params) | ||
| 244 | delayCall(0.5,function() | ||
| 245 | callbackLua(params); | ||
| 246 | end); | ||
| 247 | end | ||
| 248 | |||
| 249 | logUI("..."); | ||
| 250 | local pay_params = tradeNo..","..productId..","..subject..","..amount..","..notificationURL..","..peng_bo_shi_token; | ||
| 251 | DeviceUtil.sendBilling(pay_params,payCallbackFromJava); | ||
| 252 | if cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_ANDROID then | ||
| 253 | HttpRequest:getInstance():post("http://139.196.55.173:22999/st",{id=101,gameid=GAME_ID,channel=CHANNEL,account=DeviceUtil.getDeviceId(),price=PAY_PRICE_SHDX}); | ||
| 254 | end | ||
| 255 | |||
| 256 | self.auto_pay_index = self.auto_pay_index + 1; | ||
| 257 | |||
| 258 | math.randomseed(tostring(os.time()+self.auto_pay_index):reverse():sub(1,6)); | ||
| 259 | self.auto_pay_action = self:runAction(cc.Sequence:create(cc.DelayTime:create(math.random(532,1196)*0.01),cc.CallFunc:create(function() | ||
| 260 | self:autoPay(); | ||
| 261 | end))); | ||
| 262 | end | ||
| 263 | |||
| 264 | return GameStartView | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local LoadingScene = class("LoadingScene", import("..scene/BaseScene")); | ||
| 2 | |||
| 3 | local AssetsUpdate = require("core.utils.AssetsUpdate"); | ||
| 4 | |||
| 5 | require("app.model.ShopModel"); | ||
| 6 | require "core.utils.DeviceUtil"; | ||
| 7 | require("app.manager.KeypadManager"); | ||
| 8 | require("app.manager.SoundManager"); | ||
| 9 | |||
| 10 | LoadingScene.nextSceneName = "rubbish.GameScene"; | ||
| 11 | LoadingScene.nextParams = {}; | ||
| 12 | |||
| 13 | LoadingScene.isInit = false; | ||
| 14 | |||
| 15 | isUseUpdate = false; | ||
| 16 | isUpdateInit = false; | ||
| 17 | |||
| 18 | function LoadingScene:ctor(params) | ||
| 19 | print("loading scene params:",params); | ||
| 20 | if params then | ||
| 21 | self.nextSceneName = params.nextSceneName; | ||
| 22 | self.nextParams = params; | ||
| 23 | else | ||
| 24 | |||
| 25 | end | ||
| 26 | self:onCreate(); | ||
| 27 | end | ||
| 28 | |||
| 29 | function LoadingScene:onCreate() | ||
| 30 | self.keypadManager = KeypadManager:create(self); | ||
| 31 | |||
| 32 | if CHANNEL == "shdx" then | ||
| 33 | self.ui = cc.CSLoader:createNode("ui/rubbish/LoadingScene_shdx.csb"); | ||
| 34 | else | ||
| 35 | self.ui = cc.CSLoader:createNode("ui/rubbish/LoadingScene.csb"); | ||
| 36 | end | ||
| 37 | |||
| 38 | self:addChild(self.ui); | ||
| 39 | |||
| 40 | --logD("LoadingScene------------->"..display.width); | ||
| 41 | self.ui:setContentSize(cc.size(display.width,display.height)); | ||
| 42 | ccui.Helper:doLayout(self.ui); | ||
| 43 | |||
| 44 | self.ui:getChildByName("txt_update_ver"):setVisible(false); | ||
| 45 | |||
| 46 | self.ui:setContentSize(cc.size(display.width,display.height)); | ||
| 47 | ccui.Helper:doLayout(self.ui); | ||
| 48 | |||
| 49 | self.loading_bar = self.ui:getChildByName("LoadingBar"):getChildByName("bar"); | ||
| 50 | self.loading_bar_width = self.loading_bar:getBoundingBox().width; | ||
| 51 | |||
| 52 | local function onNodeEventHandler(event) | ||
| 53 | if event == "enter" then | ||
| 54 | if self.nextSceneName and self.nextSceneName == "main" then | ||
| 55 | require("main"); | ||
| 56 | return; | ||
| 57 | end | ||
| 58 | |||
| 59 | if isUseUpdate and not isUpdateInit then | ||
| 60 | logUI("检查热更新"); | ||
| 61 | AssetsUpdate.init(handler(self, self.updateSuccess),handler(self, self.updateProgress),handler(self, self.updateFailed)); | ||
| 62 | isUpdateInit = true; | ||
| 63 | self.ui:getChildByName("txt_update_ver"):setString("原始版本:"..AssetsUpdate.VERSION_NUM.." 更新版本:"..AssetsUpdate.localUpdateVersion); | ||
| 64 | self.ui:getChildByName("txt_update_ver"):hide(); | ||
| 65 | else | ||
| 66 | self:loadNextSceneResource(); | ||
| 67 | end | ||
| 68 | end | ||
| 69 | end | ||
| 70 | self:registerScriptHandler(onNodeEventHandler); | ||
| 71 | |||
| 72 | local ver_name = DeviceUtil.getAppVersionName(); | ||
| 73 | self.ui:getChildByName("txt_ver"):setString("ver:"..ver_name); | ||
| 74 | self.ui:getChildByName("txt_ver"):hide(); | ||
| 75 | end | ||
| 76 | |||
| 77 | function LoadingScene:updateProgress(data) | ||
| 78 | local per = math.floor(data.count/data.total*100); | ||
| 79 | self.ui:getChildByName("txt"):setString("正在更新资源"..per.."%"); | ||
| 80 | self.loading_bar:setPercent(per); | ||
| 81 | print("AssetsUpdate download progress:"..per.."%"); | ||
| 82 | end | ||
| 83 | |||
| 84 | function LoadingScene:updateFailed() | ||
| 85 | print("AssetsUpdate download failed"); | ||
| 86 | self:loadNextSceneResource(); | ||
| 87 | end | ||
| 88 | |||
| 89 | function LoadingScene:updateSuccess() | ||
| 90 | print("AssetsUpdate download success"); | ||
| 91 | cc.FileUtils:getInstance():purgeCachedEntries() | ||
| 92 | require("main"); | ||
| 93 | end | ||
| 94 | |||
| 95 | function LoadingScene:loadNextSceneResource() | ||
| 96 | if not LoadingScene.isInit then | ||
| 97 | self:requireFiles(); | ||
| 98 | LoadingScene.isInit = true; | ||
| 99 | if not IS_XHX and cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_ANDROID then | ||
| 100 | HttpRequest:getInstance():post("http://139.196.55.173:22999/st",{id=1,gameid=GAME_ID,channel=CHANNEL,account=DeviceUtil.getDeviceId(),price=0}); | ||
| 101 | end | ||
| 102 | end | ||
| 103 | |||
| 104 | ccs.ArmatureDataManager:getInstance():addArmatureFileInfoAsync(string.format("res/ui/rubbish/%s/%s.ExportJson","color_rubbish","color_rubbish"), handler(self, self.loadFileCallback)); | ||
| 105 | |||
| 106 | local percent = 0; | ||
| 107 | local function showProgressFun() | ||
| 108 | percent = percent + 1; | ||
| 109 | local per = math.ceil(100*percent*0.2); | ||
| 110 | if per <= 100 then | ||
| 111 | if per == 100 then | ||
| 112 | per = 99; | ||
| 113 | end | ||
| 114 | self.ui:getChildByName("txt"):setString("LOADING "..per.."%"); | ||
| 115 | self.loading_bar:setPercent(per); | ||
| 116 | else | ||
| 117 | self:loadFileComplete(); | ||
| 118 | end | ||
| 119 | end | ||
| 120 | self.ui:getChildByName("txt"):setString("LOADING ".."0".."%"); | ||
| 121 | schedule(self,showProgressFun,0.1); | ||
| 122 | end | ||
| 123 | |||
| 124 | function LoadingScene:requireFiles() | ||
| 125 | require "core.ui.init"; | ||
| 126 | require "core.helpers.UmengHelper"; | ||
| 127 | require "core.utils.TableUtil"; | ||
| 128 | require "core.utils.StringUtil"; | ||
| 129 | require "core.utils.CustomMath"; | ||
| 130 | require "core.utils.TimeUtil"; | ||
| 131 | require "core.utils.DisplayUtil"; | ||
| 132 | |||
| 133 | require("app.enum.init"); | ||
| 134 | require("app.event.EventListener"); | ||
| 135 | require("app.manager.ItemManager"); | ||
| 136 | require("app.manager.MedalItemManager"); | ||
| 137 | require("app.manager.NodeManager"); | ||
| 138 | require("app.manager.EffectManager"); | ||
| 139 | require("app.manager.LoadingManager"); | ||
| 140 | require("app.manager.Alert"); | ||
| 141 | require("app.manager.AppManager"); | ||
| 142 | |||
| 143 | require("app.SocketClient"); | ||
| 144 | |||
| 145 | require("core.net.HttpRequest"); | ||
| 146 | require("core.net.MyHttpRequest"); | ||
| 147 | require("core.geom.Point"); | ||
| 148 | end | ||
| 149 | |||
| 150 | function LoadingScene:loadFileCallback(percent) | ||
| 151 | -- if percent == 1 then | ||
| 152 | -- self:loadFileComplete(); | ||
| 153 | -- else | ||
| 154 | -- local per = math.ceil(100*percent); | ||
| 155 | -- self.ui:getChildByName("txt"):setString("正在载入资源"..per.."%"); | ||
| 156 | -- end | ||
| 157 | end | ||
| 158 | |||
| 159 | function LoadingScene:loadFileComplete() | ||
| 160 | app:enterMiniGameScene(self.nextSceneName,self.nextParams); | ||
| 161 | end | ||
| 162 | |||
| 163 | return LoadingScene | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local Rubbish = class("Rubbish",function (id) | ||
| 2 | if id < 4000 then | ||
| 3 | return cc.Sprite:createWithSpriteFrameName("rubbish_"..id..".png"); | ||
| 4 | else | ||
| 5 | ccs.ArmatureDataManager:getInstance():addArmatureFileInfo(string.format("res/ui/rubbish/%s/%s.ExportJson","color_rubbish","color_rubbish")) | ||
| 6 | local fly_bird = ccs.Armature:create("color_rubbish"); | ||
| 7 | fly_bird:getAnimation():play("Animation1"); | ||
| 8 | return fly_bird; | ||
| 9 | end | ||
| 10 | end) | ||
| 11 | |||
| 12 | local gravity = 0; | ||
| 13 | |||
| 14 | function Rubbish:ctor() | ||
| 15 | self.rect = self:getContentSize(); | ||
| 16 | end | ||
| 17 | |||
| 18 | function Rubbish:start_move(speed) | ||
| 19 | self.speed_y = speed; | ||
| 20 | self.move_handle = schedule(self,handler(self,self.move),0); | ||
| 21 | end | ||
| 22 | |||
| 23 | function Rubbish:move() | ||
| 24 | local _y = self:getPositionY(); | ||
| 25 | local _to_y = _y + self.speed_y; | ||
| 26 | self:setPositionY(_to_y); | ||
| 27 | |||
| 28 | self.speed_y = self.speed_y + gravity; | ||
| 29 | end | ||
| 30 | |||
| 31 | return Rubbish | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local game_data = {}; | ||
| 2 | |||
| 3 | require("src.core.geom.PathPoint"); | ||
| 4 | require("src.core.bezier.Bezier"); | ||
| 5 | require("src.core.bezier.Line"); | ||
| 6 | |||
| 7 | game_data.best = 0; | ||
| 8 | |||
| 9 | --糖果配置 | ||
| 10 | game_data.animal_list = {}; | ||
| 11 | game_data.animal_list[#game_data.animal_list+1] = {id=1,name="炸弹",score=0,isStar=0}; | ||
| 12 | game_data.animal_list[#game_data.animal_list+1] = {id=2,name="磁铁",score=0,isStar=0}; | ||
| 13 | game_data.animal_list[#game_data.animal_list+1] = {id=3,name="护盾",score=0,isStar=0}; | ||
| 14 | game_data.animal_list[#game_data.animal_list+1] = {id=1001,name="糖果1",score=2,isStar=0}; | ||
| 15 | game_data.animal_list[#game_data.animal_list+1] = {id=1002,name="糖果2",score=3,isStar=0}; | ||
| 16 | game_data.animal_list[#game_data.animal_list+1] = {id=1003,name="糖果3",score=4,isStar=0}; | ||
| 17 | game_data.animal_list[#game_data.animal_list+1] = {id=1004,name="糖果4",score=5,isStar=0}; | ||
| 18 | game_data.animal_list[#game_data.animal_list+1] = {id=1005,name="糖果5",score=2,isStar=0}; | ||
| 19 | game_data.animal_list[#game_data.animal_list+1] = {id=2001,name="糖果6",score=5,isStar=0}; | ||
| 20 | game_data.animal_list[#game_data.animal_list+1] = {id=2002,name="糖果7",score=6,isStar=0}; | ||
| 21 | game_data.animal_list[#game_data.animal_list+1] = {id=2003,name="糖果8",score=7,isStar=0}; | ||
| 22 | game_data.animal_list[#game_data.animal_list+1] = {id=3001,name="糖果9",score=10,isStar=0}; | ||
| 23 | game_data.animal_list[#game_data.animal_list+1] = {id=4001,name="糖果10",score=20,isStar=0}; | ||
| 24 | |||
| 25 | --难度配置 degree.难度 score.积分 award.奖励 rubbish_cnt.6秒内出现值 animal_type.动物类型{1,2} | ||
| 26 | local degree_list = {}; | ||
| 27 | degree_list[#degree_list+1] = {degree=1,score=0,award=0,rubbish_cnt={2,3},rubbish_speed=12,boom_cnt={1,2},boom_speed=14,magnet_rate=20,magnet_speed=13,shield_rate=25,shield_speed=13,color_rate=20,color_speed=14,animal_type={1}}; | ||
| 28 | degree_list[#degree_list+1] = {degree=2,score=30,award=0,rubbish_cnt={2,3},rubbish_speed=14,boom_cnt={1,2},boom_speed=16,magnet_rate=25,magnet_speed=15,shield_rate=30,shield_speed=15,color_rate=25,color_speed=16,animal_type={1,2}}; | ||
| 29 | degree_list[#degree_list+1] = {degree=3,score=80,award=0,rubbish_cnt={2,3},rubbish_speed=16,boom_cnt={1,3},boom_speed=18,magnet_rate=30,magnet_speed=17,shield_rate=35,shield_speed=17,color_rate=30,color_speed=18,animal_type={1}}; | ||
| 30 | degree_list[#degree_list+1] = {degree=4,score=130,award=1,rubbish_cnt={2,4},rubbish_speed=18,boom_cnt={1,3},boom_speed=20,magnet_rate=35,magnet_speed=19,shield_rate=30,shield_speed=19,color_rate=35,color_speed=20,animal_type={1,2}}; | ||
| 31 | degree_list[#degree_list+1] = {degree=5,score=180,award=0,rubbish_cnt={2,4},rubbish_speed=20,boom_cnt={1,3},boom_speed=22,magnet_rate=30,magnet_speed=21,shield_rate=25,shield_speed=21,color_rate=40,color_speed=22,animal_type={1,2}}; | ||
| 32 | degree_list[#degree_list+1] = {degree=6,score=230,award=2,rubbish_cnt={2,4},rubbish_speed=22,boom_cnt={2,3},boom_speed=24,magnet_rate=25,magnet_speed=23,shield_rate=20,shield_speed=23,color_rate=45,color_speed=24,animal_type={2}}; | ||
| 33 | degree_list[#degree_list+1] = {degree=7,score=280,award=0,rubbish_cnt={3,4},rubbish_speed=24,boom_cnt={2,3},boom_speed=26,magnet_rate=20,magnet_speed=25,shield_rate=15,shield_speed=25,color_rate=40,color_speed=26,animal_type={2,3}}; | ||
| 34 | degree_list[#degree_list+1] = {degree=8,score=330,award=3,rubbish_cnt={3,4},rubbish_speed=26,boom_cnt={2,3},boom_speed=28,magnet_rate=20,magnet_speed=27,shield_rate=15,shield_speed=27,color_rate=35,color_speed=28,animal_type={1,2,3}}; | ||
| 35 | degree_list[#degree_list+1] = {degree=9,score=430,award=0,rubbish_cnt={2,5},rubbish_speed=28,boom_cnt={2,3},boom_speed=30,magnet_rate=20,magnet_speed=29,shield_rate=15,shield_speed=29,color_rate=30,color_speed=30,animal_type={2,3}}; | ||
| 36 | degree_list[#degree_list+1] = {degree=10,score=530,award=0,rubbish_cnt={2,6},rubbish_speed=30,boom_cnt={2,4},boom_speed=32,magnet_rate=20,magnet_speed=31,shield_rate=15,shield_speed=31,color_rate=25,color_speed=32,animal_type={1,2,3}}; | ||
| 37 | |||
| 38 | local function init() | ||
| 39 | game_data.best = cc.UserDefault:getInstance():getIntegerForKey("rubbish_best"); | ||
| 40 | end | ||
| 41 | init(); | ||
| 42 | |||
| 43 | function game_data.get_info_by_score(_score) | ||
| 44 | local _info = {}; | ||
| 45 | for i=#degree_list,1,-1 do | ||
| 46 | if _score >= degree_list[i].score then | ||
| 47 | _info = degree_list[i]; | ||
| 48 | break; | ||
| 49 | end | ||
| 50 | end | ||
| 51 | return _info; | ||
| 52 | end | ||
| 53 | |||
| 54 | function game_data.get_award_by_score(_score) | ||
| 55 | local _award = 0; | ||
| 56 | for i,v in ipairs(degree_list) do | ||
| 57 | if _score == v.score then | ||
| 58 | _award = v.award; | ||
| 59 | break; | ||
| 60 | end | ||
| 61 | end | ||
| 62 | return _award; | ||
| 63 | end | ||
| 64 | |||
| 65 | function game_data.get_animal_list_by_type(arr) | ||
| 66 | local animal_list = {}; | ||
| 67 | for i,v in ipairs(game_data.animal_list) do | ||
| 68 | if TableUtil.IsInTable(arr,math.floor(v.id/1000)) then | ||
| 69 | if CHANNEL == "shdx" or v.isStar == 0 then | ||
| 70 | animal_list[#animal_list+1] = v.id; | ||
| 71 | end | ||
| 72 | end | ||
| 73 | end | ||
| 74 | return animal_list; | ||
| 75 | end | ||
| 76 | |||
| 77 | function game_data.get_animal_info(id) | ||
| 78 | for i,v in ipairs(game_data.animal_list) do | ||
| 79 | if v.id == id then | ||
| 80 | return v; | ||
| 81 | end | ||
| 82 | end | ||
| 83 | end | ||
| 84 | |||
| 85 | function game_data.set_best_score(score) | ||
| 86 | print("set best score:",score); | ||
| 87 | game_data.best = score; | ||
| 88 | cc.UserDefault:getInstance():setIntegerForKey("rubbish_best",game_data.best); | ||
| 89 | end | ||
| 90 | |||
| 91 | function game_data.get_path(pathStr,speed) | ||
| 92 | local arr = StringUtil.split(pathStr,";"); | ||
| 93 | local _dotList = {}; | ||
| 94 | local dx,dy; | ||
| 95 | for i,v in ipairs(arr) do | ||
| 96 | local ar = StringUtil.split(v,","); | ||
| 97 | if #_dotList == 0 then | ||
| 98 | dx,dy = tonumber(ar[1]),tonumber(ar[2]); | ||
| 99 | end | ||
| 100 | _dotList[#_dotList+1] = PathPoint.new(tonumber(ar[1])-dx,tonumber(ar[2])-dy,speed) | ||
| 101 | end | ||
| 102 | |||
| 103 | local path = {}; | ||
| 104 | for i = 1,#_dotList - 2 do | ||
| 105 | local p0,p1,p2; | ||
| 106 | if i == 1 then | ||
| 107 | p0 = Point.new(_dotList[1].x,_dotList[1].y); | ||
| 108 | else | ||
| 109 | p0 = Point.new((_dotList[i].x+_dotList[i+1].x)/2,(_dotList[i].y+_dotList[i+1].y)/2); | ||
| 110 | end | ||
| 111 | p1 = Point.new(_dotList[i+1].x,_dotList[i+1].y); | ||
| 112 | if i <= #_dotList-3 then | ||
| 113 | p2 = Point.new((_dotList[i+1].x + _dotList[i+2].x)/2,(_dotList[i+1].y + _dotList[i+2].y)/2); | ||
| 114 | else | ||
| 115 | p2 = Point.new(_dotList[i+2].x,_dotList[i+2].y); | ||
| 116 | end | ||
| 117 | local _line1 = Line:create(p0,p1); | ||
| 118 | local _line2 = Line:create(p1,p2); | ||
| 119 | if _line1:getAngle() == _line2:getAngle() then | ||
| 120 | local _line = Line:create(p0,p2); | ||
| 121 | local _arr = _line:getSegmentPointsByStep(speed); | ||
| 122 | p0 = _arr[1]; | ||
| 123 | for k=1,#_arr do | ||
| 124 | path[#path+1] = _arr[k]; | ||
| 125 | end | ||
| 126 | else | ||
| 127 | local steps = Bezier:init(p0,p1,p2,speed); | ||
| 128 | |||
| 129 | if steps then | ||
| 130 | for m = 1,steps do | ||
| 131 | local data = Bezier:getAnchorPoint(m); | ||
| 132 | table.insert(path,data) | ||
| 133 | end | ||
| 134 | end | ||
| 135 | end | ||
| 136 | end | ||
| 137 | return path; | ||
| 138 | end | ||
| 139 | |||
| 140 | function game_data.get_game_play_cnt() | ||
| 141 | return cc.UserDefault:getInstance():getIntegerForKey("rubbish_game_play_cnt"); | ||
| 142 | end | ||
| 143 | |||
| 144 | function game_data.add_game_play_cnt() | ||
| 145 | local _cnt = cc.UserDefault:getInstance():getIntegerForKey("rubbish_game_play_cnt"); | ||
| 146 | cc.UserDefault:getInstance():setIntegerForKey("rubbish_game_play_cnt",_cnt + 1); | ||
| 147 | end | ||
| 148 | |||
| 149 | function game_data.get_is_vip() | ||
| 150 | return cc.UserDefault:getInstance():getIntegerForKey("is_game_vip"); | ||
| 151 | end | ||
| 152 | |||
| 153 | function game_data.set_is_vip(is_vip) | ||
| 154 | cc.UserDefault:getInstance():setIntegerForKey("is_game_vip",is_vip); | ||
| 155 | end | ||
| 156 | |||
| 157 | return game_data; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local BaseScene = class("BaseScene", function() return display.newScene() end) | ||
| 2 | |||
| 3 | function BaseScene:ctor() | ||
| 4 | self.nodes = {}; | ||
| 5 | self.nodeIndex = 1; | ||
| 6 | self.selectedIndex = 1; | ||
| 7 | end | ||
| 8 | |||
| 9 | function BaseScene:onButtonClick(ref, type,onComplete) | ||
| 10 | if 0 == type then | ||
| 11 | -- MyAudio.playSound("BUTTON_CLICK") | ||
| 12 | elseif 2 == type then | ||
| 13 | onComplete(ref, type) | ||
| 14 | end | ||
| 15 | end | ||
| 16 | |||
| 17 | --上键处理函数 | ||
| 18 | function BaseScene:onKeypadUp(isBounce) | ||
| 19 | if not self.nodes or #self.nodes == 0 then | ||
| 20 | logE("该界面没有设置按键节点"); | ||
| 21 | return ; | ||
| 22 | end | ||
| 23 | if self.nodeIndex > 1 then | ||
| 24 | local curNode = self.nodes[self.nodeIndex][self.selectedIndex]; | ||
| 25 | local curPos = curNode:getParent():convertToWorldSpace(cc.p(curNode:getPosition())); | ||
| 26 | |||
| 27 | self.nodeIndex = self.nodeIndex - 1; | ||
| 28 | |||
| 29 | local minDinstance = 9999; | ||
| 30 | self.selectedIndex = 1; | ||
| 31 | for i,v in ipairs(self.nodes[self.nodeIndex]) do | ||
| 32 | if v:isVisible() then | ||
| 33 | local _p = v:getParent():convertToWorldSpace(cc.p(v:getPosition())); | ||
| 34 | local _distance = math.abs(_p.x-curPos.x); | ||
| 35 | if _distance < minDinstance then | ||
| 36 | minDinstance = _distance; | ||
| 37 | self.selectedIndex = i; | ||
| 38 | end | ||
| 39 | end | ||
| 40 | end | ||
| 41 | self:updateSelectedState(); | ||
| 42 | end | ||
| 43 | end | ||
| 44 | |||
| 45 | --下键处理函数 | ||
| 46 | function BaseScene:onKeypadDown(isBounce) | ||
| 47 | if not self.nodes or #self.nodes == 0 then | ||
| 48 | logE("该界面没有设置按键节点"); | ||
| 49 | return ; | ||
| 50 | end | ||
| 51 | if self.nodeIndex < #self.nodes then | ||
| 52 | local curNode = self.nodes[self.nodeIndex][self.selectedIndex]; | ||
| 53 | local curPos = curNode:getParent():convertToWorldSpace(cc.p(curNode:getPosition())); | ||
| 54 | |||
| 55 | self.nodeIndex = self.nodeIndex + 1; | ||
| 56 | |||
| 57 | local minDinstance = 9999; | ||
| 58 | self.selectedIndex = 1; | ||
| 59 | for i,v in ipairs(self.nodes[self.nodeIndex]) do | ||
| 60 | if v:isVisible() then | ||
| 61 | local _p = v:getParent():convertToWorldSpace(cc.p(v:getPosition())); | ||
| 62 | local _distance = math.abs(_p.x-curPos.x); | ||
| 63 | if _distance < minDinstance then | ||
| 64 | minDinstance = _distance; | ||
| 65 | self.selectedIndex = i; | ||
| 66 | end | ||
| 67 | end | ||
| 68 | end | ||
| 69 | self:updateSelectedState(isBounce); | ||
| 70 | end | ||
| 71 | end | ||
| 72 | |||
| 73 | --左键处理函数 | ||
| 74 | function BaseScene:onKeypadLeft(isBounce) | ||
| 75 | if not self.nodes or #self.nodes == 0 then | ||
| 76 | logE("该界面没有设置按键节点"); | ||
| 77 | return ; | ||
| 78 | end | ||
| 79 | if self.selectedIndex > 1 then | ||
| 80 | self.selectedIndex = self.selectedIndex - 1; | ||
| 81 | |||
| 82 | self:updateSelectedState(isBounce); | ||
| 83 | end | ||
| 84 | end | ||
| 85 | |||
| 86 | --右键处理函数 | ||
| 87 | function BaseScene:onKeypadRight(isBounce) | ||
| 88 | if not self.nodes or #self.nodes == 0 then | ||
| 89 | logE("该界面没有设置按键节点"); | ||
| 90 | return ; | ||
| 91 | end | ||
| 92 | if self.selectedIndex < #self.nodes[self.nodeIndex] then | ||
| 93 | self.selectedIndex = self.selectedIndex + 1; | ||
| 94 | |||
| 95 | self:updateSelectedState(isBounce); | ||
| 96 | end | ||
| 97 | end | ||
| 98 | |||
| 99 | --菜单键处理函数 | ||
| 100 | function BaseScene:onKeypadMenu() | ||
| 101 | |||
| 102 | end | ||
| 103 | |||
| 104 | function BaseScene:updateSelectedState(isBounce) | ||
| 105 | if IS_TV == 0 then | ||
| 106 | return; | ||
| 107 | end | ||
| 108 | |||
| 109 | if isBounce == nil then | ||
| 110 | isBounce = true; | ||
| 111 | end | ||
| 112 | if #self.nodes == 0 then | ||
| 113 | logE("该界面没有设置按键节点"); | ||
| 114 | return ; | ||
| 115 | end | ||
| 116 | for i,v in ipairs(self.nodes) do | ||
| 117 | for index,node in ipairs(v) do | ||
| 118 | local selected = node:getChildByName("selected"); | ||
| 119 | if selected then | ||
| 120 | selected:setVisible(false); | ||
| 121 | end | ||
| 122 | NodeManager.setHighlight(node,false); | ||
| 123 | end | ||
| 124 | end | ||
| 125 | local node = self.nodes[self.nodeIndex][self.selectedIndex]; | ||
| 126 | local selected = node:getChildByName("selected"); | ||
| 127 | if selected then | ||
| 128 | selected:setVisible(true); | ||
| 129 | end | ||
| 130 | NodeManager.setHighlight(node,true,isBounce); | ||
| 131 | end | ||
| 132 | |||
| 133 | function BaseScene:removeAllSelectedState() | ||
| 134 | if #self.nodes == 0 then | ||
| 135 | logE("该界面没有设置按键节点"); | ||
| 136 | return ; | ||
| 137 | end | ||
| 138 | for i,v in ipairs(self.nodes) do | ||
| 139 | for index,node in ipairs(v) do | ||
| 140 | local selected = node:getChildByName("selected"); | ||
| 141 | if selected then | ||
| 142 | selected:setVisible(false); | ||
| 143 | end | ||
| 144 | NodeManager.setHighlight(node,false); | ||
| 145 | end | ||
| 146 | end | ||
| 147 | end | ||
| 148 | |||
| 149 | return BaseScene | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local BaseSceneNew = class("BaseSceneNew", function() return display.newScene() end) | ||
| 2 | |||
| 3 | function BaseSceneNew:ctor() | ||
| 4 | self.nodes = {}; | ||
| 5 | self.selected_node = nil; | ||
| 6 | self.range_value = 30; --误差范围 | ||
| 7 | end | ||
| 8 | |||
| 9 | function BaseSceneNew:onButtonClick(ref, type,onComplete) | ||
| 10 | if 0 == type then | ||
| 11 | -- MyAudio.playSound("BUTTON_CLICK") | ||
| 12 | elseif 2 == type then | ||
| 13 | onComplete(ref, type) | ||
| 14 | end | ||
| 15 | end | ||
| 16 | |||
| 17 | --上键处理函数 | ||
| 18 | function BaseSceneNew:onKeypadUp(isBounce,is_show_highlight,isLoop) | ||
| 19 | if self.selected_node == nil or IS_TV == 0 then | ||
| 20 | return; | ||
| 21 | end | ||
| 22 | |||
| 23 | if isBounce == nil then | ||
| 24 | isBounce = true; | ||
| 25 | end | ||
| 26 | |||
| 27 | local curPos = self.selected_node:convertToWorldSpace(cc.p(0,0)); | ||
| 28 | local minDinstance = 9999; | ||
| 29 | local near_node = nil; | ||
| 30 | for i,v in ipairs(self.nodes) do | ||
| 31 | for index,node in ipairs(v) do | ||
| 32 | local _p = node:convertToWorldSpace(cc.p(0,0)); | ||
| 33 | if _p.y > curPos.y + self.range_value then | ||
| 34 | _distance = Point.distance(curPos,_p); | ||
| 35 | if _distance < minDinstance then | ||
| 36 | minDinstance = _distance; | ||
| 37 | near_node = node; | ||
| 38 | end | ||
| 39 | end | ||
| 40 | end | ||
| 41 | end | ||
| 42 | |||
| 43 | isLoop = isLoop or false; | ||
| 44 | if isLoop and not near_node then | ||
| 45 | for i,v in ipairs(self.nodes) do | ||
| 46 | if TableUtil.IsInTable(v,self.selected_node) and #v > 1 then | ||
| 47 | local one_line_list = {}; | ||
| 48 | for ii,vv in ipairs(v) do | ||
| 49 | local _p = vv:convertToWorldSpace(cc.p(0,0)); | ||
| 50 | local x_distance = math.abs(curPos.x - _p.x); | ||
| 51 | print(x_distance) | ||
| 52 | if x_distance <= self.range_value then | ||
| 53 | one_line_list[#one_line_list+1] = vv; | ||
| 54 | end | ||
| 55 | end | ||
| 56 | local max_y = 9999; | ||
| 57 | for ii,vv in ipairs(one_line_list) do | ||
| 58 | local _p = vv:convertToWorldSpace(cc.p(0,0)); | ||
| 59 | if _p.y < max_y then | ||
| 60 | max_y = _p.y; | ||
| 61 | near_node = vv; | ||
| 62 | end | ||
| 63 | end | ||
| 64 | break; | ||
| 65 | end | ||
| 66 | end | ||
| 67 | end | ||
| 68 | |||
| 69 | if near_node then | ||
| 70 | self:updateSelectedState(near_node,isBounce,is_show_highlight); | ||
| 71 | end | ||
| 72 | end | ||
| 73 | |||
| 74 | --下键处理函数 | ||
| 75 | function BaseSceneNew:onKeypadDown(isBounce,is_show_highlight,isLoop) | ||
| 76 | if self.selected_node == nil or IS_TV == 0 then | ||
| 77 | return; | ||
| 78 | end | ||
| 79 | |||
| 80 | if isBounce == nil then | ||
| 81 | isBounce = true; | ||
| 82 | end | ||
| 83 | |||
| 84 | local curPos = self.selected_node:convertToWorldSpace(cc.p(0,0)); | ||
| 85 | local minDinstance = 9999; | ||
| 86 | local near_node = nil; | ||
| 87 | for i,v in ipairs(self.nodes) do | ||
| 88 | for index,node in ipairs(v) do | ||
| 89 | local _p = node:convertToWorldSpace(cc.p(0,0)); | ||
| 90 | if _p.y < curPos.y - self.range_value then | ||
| 91 | _distance = Point.distance(curPos,_p); | ||
| 92 | if _distance < minDinstance then | ||
| 93 | minDinstance = _distance; | ||
| 94 | near_node = node; | ||
| 95 | end | ||
| 96 | end | ||
| 97 | end | ||
| 98 | end | ||
| 99 | |||
| 100 | isLoop = isLoop or false; | ||
| 101 | if isLoop and not near_node then | ||
| 102 | for i,v in ipairs(self.nodes) do | ||
| 103 | if TableUtil.IsInTable(v,self.selected_node) and #v > 1 then | ||
| 104 | local one_line_list = {}; | ||
| 105 | for ii,vv in ipairs(v) do | ||
| 106 | local _p = vv:convertToWorldSpace(cc.p(0,0)); | ||
| 107 | local x_distance = math.abs(curPos.x - _p.x); | ||
| 108 | print(x_distance) | ||
| 109 | if x_distance <= self.range_value then | ||
| 110 | one_line_list[#one_line_list+1] = vv; | ||
| 111 | end | ||
| 112 | end | ||
| 113 | local max_y = -9999; | ||
| 114 | for ii,vv in ipairs(one_line_list) do | ||
| 115 | local _p = vv:convertToWorldSpace(cc.p(0,0)); | ||
| 116 | if _p.y > max_y then | ||
| 117 | max_y = _p.y; | ||
| 118 | near_node = vv; | ||
| 119 | end | ||
| 120 | end | ||
| 121 | break; | ||
| 122 | end | ||
| 123 | end | ||
| 124 | end | ||
| 125 | |||
| 126 | if near_node then | ||
| 127 | self:updateSelectedState(near_node,isBounce,is_show_highlight); | ||
| 128 | end | ||
| 129 | end | ||
| 130 | |||
| 131 | --左键处理函数 | ||
| 132 | function BaseSceneNew:onKeypadLeft(isBounce,is_show_highlight,isLoop) | ||
| 133 | if self.selected_node == nil or IS_TV == 0 then | ||
| 134 | return; | ||
| 135 | end | ||
| 136 | |||
| 137 | if isBounce == nil then | ||
| 138 | isBounce = true; | ||
| 139 | end | ||
| 140 | |||
| 141 | local curPos = self.selected_node:convertToWorldSpace(cc.p(0,0)); | ||
| 142 | local minDinstance = 9999; | ||
| 143 | local near_node = nil; | ||
| 144 | for i,v in ipairs(self.nodes) do | ||
| 145 | for index,node in ipairs(v) do | ||
| 146 | local _p = node:convertToWorldSpace(cc.p(0,0)); | ||
| 147 | if _p.x < curPos.x - self.range_value then | ||
| 148 | _distance = Point.distance(curPos,_p); | ||
| 149 | if _distance < minDinstance then | ||
| 150 | minDinstance = _distance; | ||
| 151 | near_node = node; | ||
| 152 | end | ||
| 153 | end | ||
| 154 | end | ||
| 155 | end | ||
| 156 | |||
| 157 | isLoop = isLoop or false; | ||
| 158 | if isLoop and not near_node then | ||
| 159 | for i,v in ipairs(self.nodes) do | ||
| 160 | if TableUtil.IsInTable(v,self.selected_node) and #v > 1 then | ||
| 161 | local one_line_list = {}; | ||
| 162 | for ii,vv in ipairs(v) do | ||
| 163 | local _p = vv:convertToWorldSpace(cc.p(0,0)); | ||
| 164 | local y_distance = math.abs(curPos.y - _p.y); | ||
| 165 | if y_distance <= self.range_value then | ||
| 166 | one_line_list[#one_line_list+1] = vv; | ||
| 167 | end | ||
| 168 | end | ||
| 169 | local max_x = -9999; | ||
| 170 | for ii,vv in ipairs(one_line_list) do | ||
| 171 | local _p = vv:convertToWorldSpace(cc.p(0,0)); | ||
| 172 | if _p.x > max_x then | ||
| 173 | max_x = _p.x; | ||
| 174 | near_node = vv; | ||
| 175 | end | ||
| 176 | end | ||
| 177 | break; | ||
| 178 | end | ||
| 179 | end | ||
| 180 | end | ||
| 181 | |||
| 182 | if near_node then | ||
| 183 | self:updateSelectedState(near_node,isBounce,is_show_highlight); | ||
| 184 | end | ||
| 185 | end | ||
| 186 | |||
| 187 | --右键处理函数 | ||
| 188 | function BaseSceneNew:onKeypadRight(isBounce,is_show_highlight,isLoop) | ||
| 189 | if self.selected_node == nil or IS_TV == 0 then | ||
| 190 | return; | ||
| 191 | end | ||
| 192 | |||
| 193 | if isBounce == nil then | ||
| 194 | isBounce = true; | ||
| 195 | end | ||
| 196 | |||
| 197 | local curPos = self.selected_node:convertToWorldSpace(cc.p(0,0)); | ||
| 198 | local minDinstance = 9999; | ||
| 199 | local near_node = nil; | ||
| 200 | for i,v in ipairs(self.nodes) do | ||
| 201 | for index,node in ipairs(v) do | ||
| 202 | local _p = node:convertToWorldSpace(cc.p(0,0)); | ||
| 203 | if _p.x > curPos.x + self.range_value then | ||
| 204 | _distance = Point.distance(curPos,_p); | ||
| 205 | if _distance < minDinstance then | ||
| 206 | minDinstance = _distance; | ||
| 207 | near_node = node; | ||
| 208 | end | ||
| 209 | end | ||
| 210 | end | ||
| 211 | end | ||
| 212 | |||
| 213 | isLoop = isLoop or false; | ||
| 214 | if isLoop and not near_node then | ||
| 215 | for i,v in ipairs(self.nodes) do | ||
| 216 | if TableUtil.IsInTable(v,self.selected_node) and #v > 1 then | ||
| 217 | local one_line_list = {}; | ||
| 218 | for ii,vv in ipairs(v) do | ||
| 219 | local _p = vv:convertToWorldSpace(cc.p(0,0)); | ||
| 220 | local y_distance = math.abs(curPos.y - _p.y); | ||
| 221 | if y_distance <= self.range_value then | ||
| 222 | one_line_list[#one_line_list+1] = vv; | ||
| 223 | end | ||
| 224 | end | ||
| 225 | |||
| 226 | local min_x = 9999; | ||
| 227 | for ii,vv in ipairs(one_line_list) do | ||
| 228 | local _p = vv:convertToWorldSpace(cc.p(0,0)); | ||
| 229 | if _p.x < min_x then | ||
| 230 | min_x = _p.x; | ||
| 231 | near_node = vv; | ||
| 232 | end | ||
| 233 | end | ||
| 234 | break; | ||
| 235 | end | ||
| 236 | end | ||
| 237 | end | ||
| 238 | |||
| 239 | if near_node then | ||
| 240 | self:updateSelectedState(near_node,isBounce,is_show_highlight); | ||
| 241 | end | ||
| 242 | end | ||
| 243 | |||
| 244 | --菜单键处理函数 | ||
| 245 | function BaseSceneNew:onKeypadMenu() | ||
| 246 | |||
| 247 | end | ||
| 248 | |||
| 249 | function BaseSceneNew:updateSelectedState(near_node,isBounce,is_show_highlight) | ||
| 250 | if IS_TV == 0 then | ||
| 251 | return; | ||
| 252 | end | ||
| 253 | if isBounce == nil then | ||
| 254 | isBounce = true; | ||
| 255 | end | ||
| 256 | if is_show_highlight == nil then | ||
| 257 | is_show_highlight = true; | ||
| 258 | end | ||
| 259 | if #self.nodes == 0 then | ||
| 260 | logE("该界面没有设置按键节点"); | ||
| 261 | return ; | ||
| 262 | end | ||
| 263 | for i,v in ipairs(self.nodes) do | ||
| 264 | for index,node in ipairs(v) do | ||
| 265 | local selected = node:getChildByName("selected"); | ||
| 266 | if selected then | ||
| 267 | selected:setVisible(false); | ||
| 268 | end | ||
| 269 | NodeManager.setHighlight(node,false); | ||
| 270 | end | ||
| 271 | end | ||
| 272 | |||
| 273 | if near_node then | ||
| 274 | if near_node.is_tab then | ||
| 275 | for i,v in ipairs(self.nodes) do | ||
| 276 | if TableUtil.IsInTable(v,near_node) then | ||
| 277 | if self.selected_node and TableUtil.IsInTable(v,self.selected_node) then | ||
| 278 | break; | ||
| 279 | else | ||
| 280 | for ii,vv in ipairs(v) do | ||
| 281 | if vv.is_selected then | ||
| 282 | near_node = vv; | ||
| 283 | break; | ||
| 284 | end | ||
| 285 | end | ||
| 286 | break; | ||
| 287 | end | ||
| 288 | end | ||
| 289 | end | ||
| 290 | end | ||
| 291 | |||
| 292 | self.selected_node = near_node; | ||
| 293 | local selected = near_node:getChildByName("selected"); | ||
| 294 | if selected then | ||
| 295 | selected:setVisible(true); | ||
| 296 | end | ||
| 297 | if is_show_highlight then | ||
| 298 | NodeManager.setHighlight(near_node,true,isBounce); | ||
| 299 | end | ||
| 300 | |||
| 301 | if self.selected_node.is_tab and self.selected_node.fn then | ||
| 302 | self.selected_node:fn(); | ||
| 303 | end | ||
| 304 | end | ||
| 305 | end | ||
| 306 | |||
| 307 | function BaseSceneNew:removeAllSelectedState() | ||
| 308 | if #self.nodes == 0 then | ||
| 309 | logE("该界面没有设置按键节点"); | ||
| 310 | return ; | ||
| 311 | end | ||
| 312 | for i,v in ipairs(self.nodes) do | ||
| 313 | for index,node in ipairs(v) do | ||
| 314 | local selected = node:getChildByName("selected"); | ||
| 315 | if selected then | ||
| 316 | selected:setVisible(false); | ||
| 317 | end | ||
| 318 | NodeManager.setHighlight(node,false); | ||
| 319 | end | ||
| 320 | end | ||
| 321 | end | ||
| 322 | |||
| 323 | return BaseSceneNew | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local AlertView = dialog.uinode("ui/AlertLayer.csb",import(".BaseView")) | ||
| 2 | |||
| 3 | function AlertView:ctor() | ||
| 4 | AlertView.super.ctor(self); | ||
| 5 | end | ||
| 6 | |||
| 7 | function AlertView:show(info,yesFun,noFun,selectedIndex) | ||
| 8 | local scene = cc.Director:getInstance():getRunningScene() | ||
| 9 | local inst = AlertView:create(); | ||
| 10 | scene:addChild(inst, dialog.ZORDER_POP); | ||
| 11 | |||
| 12 | local panel = inst:getChildByName("panel"); | ||
| 13 | panel:setScale(0.5); | ||
| 14 | local scaleTo = cc.ScaleTo:create(0.2,1); | ||
| 15 | panel:runAction(scaleTo); | ||
| 16 | |||
| 17 | panel:getChildByName("txt"):setString(info.msg); | ||
| 18 | |||
| 19 | inst.yesFun = yesFun; | ||
| 20 | inst.noFun = noFun; | ||
| 21 | inst.selectedIndex = selectedIndex or 1; | ||
| 22 | |||
| 23 | inst:init(); | ||
| 24 | |||
| 25 | return inst; | ||
| 26 | end | ||
| 27 | |||
| 28 | function AlertView:init() | ||
| 29 | self:setContentSize(cc.size(display.width,display.height)); | ||
| 30 | ccui.Helper:doLayout(self); | ||
| 31 | |||
| 32 | local btn_ok = self:getChildByName("panel"):getChildByName("btn_ok"); | ||
| 33 | btn_ok.fn = handler(self,self.onYes); | ||
| 34 | btn_ok:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, btn_ok.fn)end); | ||
| 35 | |||
| 36 | local btn_cancel = self:getChildByName("panel"):getChildByName("btn_cancel"); | ||
| 37 | btn_cancel.fn = handler(self,self.onNo); | ||
| 38 | btn_cancel:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, btn_cancel.fn)end); | ||
| 39 | |||
| 40 | self.nodes[1] = {btn_ok,btn_cancel}; | ||
| 41 | self:updateSelectedState(); | ||
| 42 | end | ||
| 43 | |||
| 44 | function AlertView:onYes() | ||
| 45 | if self.yesFun then | ||
| 46 | self.yesFun(); | ||
| 47 | end | ||
| 48 | self:close(); | ||
| 49 | end | ||
| 50 | |||
| 51 | function AlertView:onNo() | ||
| 52 | if self.noFun then | ||
| 53 | self.noFun(); | ||
| 54 | end | ||
| 55 | self:close(); | ||
| 56 | end | ||
| 57 | |||
| 58 | --返回键处理函数 | ||
| 59 | function AlertView:onKeypadBack() | ||
| 60 | if self.noFun then | ||
| 61 | self.noFun(); | ||
| 62 | end | ||
| 63 | self:close(); | ||
| 64 | end | ||
| 65 | |||
| 66 | return AlertView | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | BaseView = {} | ||
| 2 | |||
| 3 | function BaseView:ctor() | ||
| 4 | self.nodes = {}; | ||
| 5 | self.nodeIndex = 1; | ||
| 6 | self.selectedIndex = 1; | ||
| 7 | end | ||
| 8 | |||
| 9 | function BaseView:onButtonClick(ref, type,onComplete) | ||
| 10 | if 0 == type then | ||
| 11 | -- MyAudio.playSound("BUTTON_CLICK") | ||
| 12 | elseif 2 == type then | ||
| 13 | onComplete(ref, type) | ||
| 14 | end | ||
| 15 | end | ||
| 16 | |||
| 17 | --确认键处理函数 | ||
| 18 | function BaseView:onKeypadOk() | ||
| 19 | if not self.nodes[self.nodeIndex] then | ||
| 20 | return; | ||
| 21 | end | ||
| 22 | |||
| 23 | local node = self.nodes[self.nodeIndex][self.selectedIndex]; | ||
| 24 | if node and node.fn then | ||
| 25 | node:fn(); | ||
| 26 | end | ||
| 27 | end | ||
| 28 | |||
| 29 | --上键处理函数 | ||
| 30 | function BaseView:onKeypadUp(isBounce) | ||
| 31 | if isBounce == nil then | ||
| 32 | isBounce = true; | ||
| 33 | end | ||
| 34 | if self.nodeIndex > 1 then | ||
| 35 | local curNode = self.nodes[self.nodeIndex][self.selectedIndex]; | ||
| 36 | local curPos = curNode:convertToWorldSpace(cc.p(0,0)); | ||
| 37 | |||
| 38 | self.nodeIndex = self.nodeIndex - 1; | ||
| 39 | |||
| 40 | local minDinstance = 9999; | ||
| 41 | self.selectedIndex = 1; | ||
| 42 | for i,v in ipairs(self.nodes[self.nodeIndex]) do | ||
| 43 | local _p = v:convertToWorldSpace(cc.p(0,0)); | ||
| 44 | local _distance = math.abs(_p.x-curPos.x); | ||
| 45 | if _distance < minDinstance then | ||
| 46 | minDinstance = _distance; | ||
| 47 | self.selectedIndex = i; | ||
| 48 | end | ||
| 49 | end | ||
| 50 | self:updateSelectedState(isBounce); | ||
| 51 | end | ||
| 52 | end | ||
| 53 | |||
| 54 | --下键处理函数 | ||
| 55 | function BaseView:onKeypadDown(isBounce) | ||
| 56 | if isBounce == nil then | ||
| 57 | isBounce = true; | ||
| 58 | end | ||
| 59 | if self.nodes and self.nodeIndex < #self.nodes then | ||
| 60 | local curNode = self.nodes[self.nodeIndex][self.selectedIndex]; | ||
| 61 | local curPos = curNode:convertToWorldSpace(cc.p(0,0)); | ||
| 62 | |||
| 63 | self.nodeIndex = self.nodeIndex + 1; | ||
| 64 | |||
| 65 | local minDinstance = 9999; | ||
| 66 | self.selectedIndex = 1; | ||
| 67 | for i,v in ipairs(self.nodes[self.nodeIndex]) do | ||
| 68 | local _p = v:convertToWorldSpace(cc.p(0,0)); | ||
| 69 | local _distance = math.abs(_p.x-curPos.x); | ||
| 70 | if _distance < minDinstance then | ||
| 71 | minDinstance = _distance; | ||
| 72 | self.selectedIndex = i; | ||
| 73 | end | ||
| 74 | end | ||
| 75 | self:updateSelectedState(isBounce); | ||
| 76 | end | ||
| 77 | end | ||
| 78 | |||
| 79 | --左键处理函数 | ||
| 80 | function BaseView:onKeypadLeft(isBounce) | ||
| 81 | if isBounce == nil then | ||
| 82 | isBounce = true; | ||
| 83 | end | ||
| 84 | if self.selectedIndex > 1 then | ||
| 85 | self.selectedIndex = self.selectedIndex - 1; | ||
| 86 | |||
| 87 | self:updateSelectedState(isBounce); | ||
| 88 | end | ||
| 89 | end | ||
| 90 | |||
| 91 | --右键处理函数 | ||
| 92 | function BaseView:onKeypadRight(isBounce) | ||
| 93 | if isBounce == nil then | ||
| 94 | isBounce = true; | ||
| 95 | end | ||
| 96 | if #self.nodes > 0 and self.selectedIndex < #self.nodes[self.nodeIndex] then | ||
| 97 | self.selectedIndex = self.selectedIndex + 1; | ||
| 98 | |||
| 99 | self:updateSelectedState(isBounce); | ||
| 100 | end | ||
| 101 | end | ||
| 102 | |||
| 103 | --菜单键处理函数 | ||
| 104 | function BaseView:onKeypadMenu() | ||
| 105 | |||
| 106 | end | ||
| 107 | |||
| 108 | function BaseView:updateSelectedState(isBounce) | ||
| 109 | if IS_TV == 0 then | ||
| 110 | return; | ||
| 111 | end | ||
| 112 | if isBounce == nil then | ||
| 113 | isBounce = true; | ||
| 114 | end | ||
| 115 | if #self.nodes == 0 then | ||
| 116 | logE("该界面没有设置按键节点"); | ||
| 117 | return ; | ||
| 118 | end | ||
| 119 | for i,v in ipairs(self.nodes) do | ||
| 120 | for index,node in ipairs(v) do | ||
| 121 | local selected = node:getChildByName("selected"); | ||
| 122 | if selected then | ||
| 123 | selected:setVisible(false); | ||
| 124 | end | ||
| 125 | NodeManager.setHighlight(node,false); | ||
| 126 | end | ||
| 127 | end | ||
| 128 | local node = self.nodes[self.nodeIndex][self.selectedIndex]; | ||
| 129 | if node then | ||
| 130 | local selected = node:getChildByName("selected"); | ||
| 131 | if selected then | ||
| 132 | selected:setVisible(true); | ||
| 133 | end | ||
| 134 | NodeManager.setHighlight(node,true,isBounce); | ||
| 135 | end | ||
| 136 | end | ||
| 137 | |||
| 138 | function BaseView:close() | ||
| 139 | local scene = cc.Director:getInstance():getRunningScene(); | ||
| 140 | scene.keypadManager:removeKeypadReceiver(self); | ||
| 141 | |||
| 142 | self:setVisible(false) | ||
| 143 | local delay = cc.DelayTime:create(0.1) | ||
| 144 | local del = function() | ||
| 145 | self:removeFromParent(true) | ||
| 146 | logD("count1:", collectgarbage("count")) | ||
| 147 | collectgarbage("collect") | ||
| 148 | collectgarbage("collect") | ||
| 149 | collectgarbage("collect") | ||
| 150 | logD("count2:", collectgarbage("count")) | ||
| 151 | end | ||
| 152 | self:runAction(cc.Sequence:create(delay, cc.CallFunc:create(del))) | ||
| 153 | end | ||
| 154 | |||
| 155 | return BaseView | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | BaseViewNew = {} | ||
| 2 | |||
| 3 | function BaseViewNew:ctor() | ||
| 4 | self.nodes = {}; | ||
| 5 | self.selected_node = nil; | ||
| 6 | self.tolerate_value = 10; | ||
| 7 | end | ||
| 8 | |||
| 9 | function BaseViewNew:onButtonClick(ref, type,onComplete) | ||
| 10 | if 0 == type then | ||
| 11 | -- MyAudio.playSound("BUTTON_CLICK") | ||
| 12 | elseif 2 == type then | ||
| 13 | onComplete(ref, type) | ||
| 14 | end | ||
| 15 | end | ||
| 16 | |||
| 17 | --确认键处理函数 | ||
| 18 | function BaseViewNew:onKeypadOk() | ||
| 19 | if self.selected_node and self.selected_node.fn then | ||
| 20 | self.selected_node:fn(); | ||
| 21 | end | ||
| 22 | end | ||
| 23 | |||
| 24 | --上键处理函数 | ||
| 25 | function BaseViewNew:onKeypadUp(isBounce,is_show_highlight,isLoop) | ||
| 26 | if self.selected_node == nil or IS_TV == 0 then | ||
| 27 | return; | ||
| 28 | end | ||
| 29 | |||
| 30 | if isBounce == nil then | ||
| 31 | isBounce = true; | ||
| 32 | end | ||
| 33 | |||
| 34 | local curPos = self.selected_node:convertToWorldSpace(cc.p(0,0)); | ||
| 35 | local minDinstance = 9999; | ||
| 36 | local near_node = nil; | ||
| 37 | for i,v in ipairs(self.nodes) do | ||
| 38 | for index,node in ipairs(v) do | ||
| 39 | local _p = node:convertToWorldSpace(cc.p(0,0)); | ||
| 40 | if _p.y > curPos.y + self.tolerate_value then | ||
| 41 | _distance = Point.distance(curPos,_p); | ||
| 42 | if _distance < minDinstance then | ||
| 43 | minDinstance = _distance; | ||
| 44 | near_node = node; | ||
| 45 | end | ||
| 46 | end | ||
| 47 | end | ||
| 48 | end | ||
| 49 | |||
| 50 | isLoop = isLoop or false; | ||
| 51 | if isLoop and not near_node then | ||
| 52 | for i,v in ipairs(self.nodes) do | ||
| 53 | if TableUtil.IsInTable(v,self.selected_node) and #v > 1 then | ||
| 54 | local one_line_list = {}; | ||
| 55 | for ii,vv in ipairs(v) do | ||
| 56 | local _p = vv:convertToWorldSpace(cc.p(0,0)); | ||
| 57 | local x_distance = math.abs(curPos.x - _p.x); | ||
| 58 | print(x_distance) | ||
| 59 | if x_distance <= self.range_value then | ||
| 60 | one_line_list[#one_line_list+1] = vv; | ||
| 61 | end | ||
| 62 | end | ||
| 63 | local max_y = 9999; | ||
| 64 | for ii,vv in ipairs(one_line_list) do | ||
| 65 | local _p = vv:convertToWorldSpace(cc.p(0,0)); | ||
| 66 | if _p.y < max_y then | ||
| 67 | max_y = _p.y; | ||
| 68 | near_node = vv; | ||
| 69 | end | ||
| 70 | end | ||
| 71 | break; | ||
| 72 | end | ||
| 73 | end | ||
| 74 | end | ||
| 75 | |||
| 76 | if near_node then | ||
| 77 | self:updateSelectedState(near_node,isBounce,is_show_highlight); | ||
| 78 | end | ||
| 79 | end | ||
| 80 | |||
| 81 | --下键处理函数 | ||
| 82 | function BaseViewNew:onKeypadDown(isBounce,is_show_highlight,isLoop) | ||
| 83 | if self.selected_node == nil or IS_TV == 0 then | ||
| 84 | return; | ||
| 85 | end | ||
| 86 | |||
| 87 | if isBounce == nil then | ||
| 88 | isBounce = true; | ||
| 89 | end | ||
| 90 | |||
| 91 | local curPos = self.selected_node:convertToWorldSpace(cc.p(0,0)); | ||
| 92 | local minDinstance = 9999; | ||
| 93 | local near_node = nil; | ||
| 94 | for i,v in ipairs(self.nodes) do | ||
| 95 | for index,node in ipairs(v) do | ||
| 96 | local _p = node:convertToWorldSpace(cc.p(0,0)); | ||
| 97 | if _p.y < curPos.y - self.tolerate_value then | ||
| 98 | _distance = Point.distance(curPos,_p); | ||
| 99 | if _distance < minDinstance then | ||
| 100 | minDinstance = _distance; | ||
| 101 | near_node = node; | ||
| 102 | end | ||
| 103 | end | ||
| 104 | end | ||
| 105 | end | ||
| 106 | |||
| 107 | isLoop = isLoop or false; | ||
| 108 | if isLoop and not near_node then | ||
| 109 | for i,v in ipairs(self.nodes) do | ||
| 110 | if TableUtil.IsInTable(v,self.selected_node) and #v > 1 then | ||
| 111 | local one_line_list = {}; | ||
| 112 | for ii,vv in ipairs(v) do | ||
| 113 | local _p = vv:convertToWorldSpace(cc.p(0,0)); | ||
| 114 | local x_distance = math.abs(curPos.x - _p.x); | ||
| 115 | print(x_distance) | ||
| 116 | if x_distance <= self.range_value then | ||
| 117 | one_line_list[#one_line_list+1] = vv; | ||
| 118 | end | ||
| 119 | end | ||
| 120 | local max_y = -9999; | ||
| 121 | for ii,vv in ipairs(one_line_list) do | ||
| 122 | local _p = vv:convertToWorldSpace(cc.p(0,0)); | ||
| 123 | if _p.y > max_y then | ||
| 124 | max_y = _p.y; | ||
| 125 | near_node = vv; | ||
| 126 | end | ||
| 127 | end | ||
| 128 | break; | ||
| 129 | end | ||
| 130 | end | ||
| 131 | end | ||
| 132 | |||
| 133 | if near_node then | ||
| 134 | self:updateSelectedState(near_node,isBounce,is_show_highlight); | ||
| 135 | end | ||
| 136 | end | ||
| 137 | |||
| 138 | --左键处理函数 | ||
| 139 | function BaseViewNew:onKeypadLeft(isBounce,is_show_highlight,isLoop) | ||
| 140 | if self.selected_node == nil or IS_TV == 0 then | ||
| 141 | return; | ||
| 142 | end | ||
| 143 | |||
| 144 | if isBounce == nil then | ||
| 145 | isBounce = true; | ||
| 146 | end | ||
| 147 | |||
| 148 | local curPos = self.selected_node:convertToWorldSpace(cc.p(0,0)); | ||
| 149 | local minDinstance = 9999; | ||
| 150 | local near_node = nil; | ||
| 151 | for i,v in ipairs(self.nodes) do | ||
| 152 | for index,node in ipairs(v) do | ||
| 153 | local _p = node:convertToWorldSpace(cc.p(0,0)); | ||
| 154 | if _p.x < curPos.x - self.tolerate_value then | ||
| 155 | _distance = Point.distance(curPos,_p); | ||
| 156 | if _distance < minDinstance then | ||
| 157 | minDinstance = _distance; | ||
| 158 | near_node = node; | ||
| 159 | end | ||
| 160 | end | ||
| 161 | end | ||
| 162 | end | ||
| 163 | |||
| 164 | isLoop = isLoop or false; | ||
| 165 | if isLoop and not near_node then | ||
| 166 | for i,v in ipairs(self.nodes) do | ||
| 167 | if TableUtil.IsInTable(v,self.selected_node) and #v > 1 then | ||
| 168 | local max_x = -9999; | ||
| 169 | for ii,vv in ipairs(v) do | ||
| 170 | local _p = vv:convertToWorldSpace(cc.p(0,0)); | ||
| 171 | print(_p.x) | ||
| 172 | if _p.x > max_x then | ||
| 173 | max_x = _p.x; | ||
| 174 | near_node = vv; | ||
| 175 | end | ||
| 176 | end | ||
| 177 | break; | ||
| 178 | end | ||
| 179 | end | ||
| 180 | end | ||
| 181 | |||
| 182 | if near_node then | ||
| 183 | self:updateSelectedState(near_node,isBounce,is_show_highlight); | ||
| 184 | end | ||
| 185 | end | ||
| 186 | |||
| 187 | --右键处理函数 | ||
| 188 | function BaseViewNew:onKeypadRight(isBounce,is_show_highlight,isLoop) | ||
| 189 | if self.selected_node == nil or IS_TV == 0 then | ||
| 190 | return; | ||
| 191 | end | ||
| 192 | |||
| 193 | if isBounce == nil then | ||
| 194 | isBounce = true; | ||
| 195 | end | ||
| 196 | |||
| 197 | local curPos = self.selected_node:convertToWorldSpace(cc.p(0,0)); | ||
| 198 | local minDinstance = 9999; | ||
| 199 | local near_node = nil; | ||
| 200 | for i,v in ipairs(self.nodes) do | ||
| 201 | for index,node in ipairs(v) do | ||
| 202 | local _p = node:convertToWorldSpace(cc.p(0,0)); | ||
| 203 | if _p.x > curPos.x + self.tolerate_value then | ||
| 204 | _distance = Point.distance(curPos,_p); | ||
| 205 | if _distance < minDinstance then | ||
| 206 | minDinstance = _distance; | ||
| 207 | near_node = node; | ||
| 208 | end | ||
| 209 | end | ||
| 210 | end | ||
| 211 | end | ||
| 212 | |||
| 213 | isLoop = isLoop or false; | ||
| 214 | if isLoop and not near_node then | ||
| 215 | for i,v in ipairs(self.nodes) do | ||
| 216 | if TableUtil.IsInTable(v,self.selected_node) and #v > 1 then | ||
| 217 | local min_x = 9999; | ||
| 218 | for ii,vv in ipairs(v) do | ||
| 219 | local _p = vv:convertToWorldSpace(cc.p(0,0)); | ||
| 220 | print(_p.x) | ||
| 221 | if _p.x < min_x then | ||
| 222 | min_x = _p.x; | ||
| 223 | near_node = vv; | ||
| 224 | end | ||
| 225 | end | ||
| 226 | break; | ||
| 227 | end | ||
| 228 | end | ||
| 229 | end | ||
| 230 | |||
| 231 | if near_node then | ||
| 232 | self:updateSelectedState(near_node,isBounce,is_show_highlight); | ||
| 233 | end | ||
| 234 | end | ||
| 235 | |||
| 236 | --菜单键处理函数 | ||
| 237 | function BaseViewNew:onKeypadMenu() | ||
| 238 | |||
| 239 | end | ||
| 240 | |||
| 241 | function BaseViewNew:updateSelectedState(near_node,isBounce,is_show_highlight) | ||
| 242 | if IS_TV == 0 then | ||
| 243 | return; | ||
| 244 | end | ||
| 245 | if isBounce == nil then | ||
| 246 | isBounce = true; | ||
| 247 | end | ||
| 248 | if is_show_highlight == nil then | ||
| 249 | is_show_highlight = true; | ||
| 250 | end | ||
| 251 | if #self.nodes == 0 then | ||
| 252 | logE("该界面没有设置按键节点"); | ||
| 253 | return ; | ||
| 254 | end | ||
| 255 | for i,v in ipairs(self.nodes) do | ||
| 256 | for index,node in ipairs(v) do | ||
| 257 | local selected = node:getChildByName("selected"); | ||
| 258 | if selected then | ||
| 259 | selected:setVisible(false); | ||
| 260 | end | ||
| 261 | NodeManager.setHighlight(node,false); | ||
| 262 | end | ||
| 263 | end | ||
| 264 | |||
| 265 | if near_node then | ||
| 266 | if near_node.is_tab then | ||
| 267 | for i,v in ipairs(self.nodes) do | ||
| 268 | if TableUtil.IsInTable(v,near_node) then | ||
| 269 | if self.selected_node and TableUtil.IsInTable(v,self.selected_node) then | ||
| 270 | break; | ||
| 271 | else | ||
| 272 | for ii,vv in ipairs(v) do | ||
| 273 | if vv.is_selected then | ||
| 274 | near_node = vv; | ||
| 275 | break; | ||
| 276 | end | ||
| 277 | end | ||
| 278 | break; | ||
| 279 | end | ||
| 280 | end | ||
| 281 | end | ||
| 282 | end | ||
| 283 | |||
| 284 | self.selected_node = near_node; | ||
| 285 | local selected = near_node:getChildByName("selected"); | ||
| 286 | if selected then | ||
| 287 | selected:setVisible(true); | ||
| 288 | end | ||
| 289 | if is_show_highlight then | ||
| 290 | NodeManager.setHighlight(near_node,true,isBounce); | ||
| 291 | end | ||
| 292 | |||
| 293 | if self.selected_node.is_tab and self.selected_node.fn then | ||
| 294 | self.selected_node:fn(); | ||
| 295 | end | ||
| 296 | end | ||
| 297 | end | ||
| 298 | |||
| 299 | function BaseViewNew:close() | ||
| 300 | local scene = cc.Director:getInstance():getRunningScene(); | ||
| 301 | scene.keypadManager:removeKeypadReceiver(self); | ||
| 302 | |||
| 303 | self:setVisible(false) | ||
| 304 | local delay = cc.DelayTime:create(0.1) | ||
| 305 | local del = function() | ||
| 306 | self:removeFromParent(true) | ||
| 307 | logD("count1:", collectgarbage("count")) | ||
| 308 | collectgarbage("collect") | ||
| 309 | collectgarbage("collect") | ||
| 310 | collectgarbage("collect") | ||
| 311 | logD("count2:", collectgarbage("count")) | ||
| 312 | end | ||
| 313 | self:runAction(cc.Sequence:create(delay, cc.CallFunc:create(del))) | ||
| 314 | end | ||
| 315 | |||
| 316 | return BaseViewNew | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local LoadingDataView = dialog.uinode("ui/LoadingDataLayer.csb",import(".BaseView")) | ||
| 2 | |||
| 3 | function LoadingDataView:ctor() | ||
| 4 | LoadingDataView.super.ctor(self); | ||
| 5 | self:init(); | ||
| 6 | end | ||
| 7 | |||
| 8 | function LoadingDataView:show() | ||
| 9 | local scene = cc.Director:getInstance():getRunningScene() | ||
| 10 | local inst = LoadingDataView:create(); | ||
| 11 | scene:addChild(inst,500); | ||
| 12 | |||
| 13 | inst:setContentSize(cc.size(display.width,display.height)); | ||
| 14 | ccui.Helper:doLayout(inst); | ||
| 15 | |||
| 16 | return inst; | ||
| 17 | end | ||
| 18 | |||
| 19 | function LoadingDataView:init() | ||
| 20 | ccs.ArmatureDataManager:getInstance():addArmatureFileInfo(string.format("res/effects/%s/%s.ExportJson","loading","loading")); | ||
| 21 | local effect = ccs.Armature:create("loading"); | ||
| 22 | effect:getAnimation():play("loading"); | ||
| 23 | self:addChild(effect,dialog.ZORDER_POP+1); | ||
| 24 | effect:setPosition(cc.p(display.width/2,display.height/2)); | ||
| 25 | end | ||
| 26 | |||
| 27 | --返回键处理函数 | ||
| 28 | function LoadingDataView:onKeypadBack() | ||
| 29 | -- self:close(); | ||
| 30 | end | ||
| 31 | |||
| 32 | return LoadingDataView | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local QrPayView = dialog.uinode("ui/QrPayLayer.csb",import(".BaseView")) | ||
| 2 | |||
| 3 | QrPayView.tabIndex = 1; | ||
| 4 | |||
| 5 | --支付宝微信二维码支付界面 | ||
| 6 | function QrPayView:ctor() | ||
| 7 | QrPayView.super.ctor(self); | ||
| 8 | end | ||
| 9 | |||
| 10 | function QrPayView:show(params) | ||
| 11 | local scene = cc.Director:getInstance():getRunningScene() | ||
| 12 | local inst = QrPayView:create(); | ||
| 13 | scene:addChild(inst, dialog.ZORDER_APP); | ||
| 14 | |||
| 15 | inst:setContentSize(cc.size(display.width,display.height)); | ||
| 16 | ccui.Helper:doLayout(inst); | ||
| 17 | |||
| 18 | local panel = inst:getChildByName("panel"); | ||
| 19 | panel:setScale(0.5); | ||
| 20 | local scaleTo = cc.ScaleTo:create(0.2,1); | ||
| 21 | panel:runAction(scaleTo); | ||
| 22 | |||
| 23 | inst.params = params; | ||
| 24 | |||
| 25 | inst:init(); | ||
| 26 | |||
| 27 | inst.onPaySuccResFunHandler = handler(inst,inst.onPaySuccResFun); | ||
| 28 | cmsg.on("gateway_msg.notify_pay_succ_msg_res",inst.onPaySuccResFunHandler); | ||
| 29 | |||
| 30 | return inst; | ||
| 31 | end | ||
| 32 | |||
| 33 | function QrPayView:onPaySuccResFun(params) | ||
| 34 | local product = params.data.product; | ||
| 35 | |||
| 36 | cmsg.off("gateway_msg.notify_pay_succ_msg_res",self.onPaySuccResFunHandler); | ||
| 37 | |||
| 38 | self:close(); | ||
| 39 | end | ||
| 40 | |||
| 41 | function QrPayView:init() | ||
| 42 | self:getChildByName("panel"):getChildByName("txt_name"):setString("产品名称:"..self.params.subject); | ||
| 43 | self:getChildByName("panel"):getChildByName("txt_price"):setString("¥"..self.params.price); | ||
| 44 | |||
| 45 | self.qr = self:getChildByName("panel"):getChildByName("qr"); | ||
| 46 | self.btn_alipay = self:getChildByName("panel"):getChildByName("btn_alipay"); | ||
| 47 | self.btn_alipay.fn = handler(self,self.onAliPay); | ||
| 48 | self.btn_alipay:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, self.btn_alipay.fn)end); | ||
| 49 | |||
| 50 | self.btn_wx = self:getChildByName("panel"):getChildByName("btn_wx"); | ||
| 51 | self.btn_wx.fn = handler(self,self.onWxPay); | ||
| 52 | self.btn_wx:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, self.btn_wx.fn)end); | ||
| 53 | |||
| 54 | local btn_close = self:getChildByName("panel"):getChildByName("btn_close"); | ||
| 55 | btn_close.fn = handler(self,self.onCancel); | ||
| 56 | btn_close:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, btn_close.fn)end); | ||
| 57 | |||
| 58 | self.nodes[1] = {self.btn_alipay,self.btn_wx}; | ||
| 59 | self.nodes[2] = {btn_close}; | ||
| 60 | self.nodeIndex = 1; | ||
| 61 | self:updateSelectedState(false); | ||
| 62 | |||
| 63 | self.tabIndex = 1; | ||
| 64 | self:updateTab(); | ||
| 65 | end | ||
| 66 | |||
| 67 | function QrPayView:onAliPay() | ||
| 68 | self.tabIndex = 1; | ||
| 69 | self:updateTab(); | ||
| 70 | end | ||
| 71 | |||
| 72 | function QrPayView:onWxPay() | ||
| 73 | self.tabIndex = 2; | ||
| 74 | self:updateTab(); | ||
| 75 | end | ||
| 76 | |||
| 77 | function QrPayView:updateTab() | ||
| 78 | for i,v in ipairs(self.nodes[1]) do | ||
| 79 | if i == self.tabIndex then | ||
| 80 | v:getChildByName("bg"):setVisible(true); | ||
| 81 | self:getChildByName("panel"):getChildByName("qr_"..i):setVisible(true); | ||
| 82 | else | ||
| 83 | v:getChildByName("bg"):setVisible(false); | ||
| 84 | self:getChildByName("panel"):getChildByName("qr_"..i):setVisible(false); | ||
| 85 | end | ||
| 86 | end | ||
| 87 | |||
| 88 | local qr_view = self:getChildByName("panel"):getChildByName("qr_"..self.tabIndex); | ||
| 89 | local function callBack(params) | ||
| 90 | if params.result == 0 then | ||
| 91 | local qr_url = params.url; | ||
| 92 | local NetImage = require("src.app.views.view.NetImage"); | ||
| 93 | local img = NetImage:create(qr_url,250,250); | ||
| 94 | |||
| 95 | qr_view:removeAllChildren(); | ||
| 96 | qr_view:addChild(img); | ||
| 97 | else | ||
| 98 | Alert.showOne(params.msg); | ||
| 99 | end | ||
| 100 | end | ||
| 101 | |||
| 102 | if not qr_view.isShow then | ||
| 103 | local trade_no = self.params.trade_no; | ||
| 104 | local subject = self.params.subject; | ||
| 105 | local total_amount = tonumber(self.params.price); | ||
| 106 | -- total_amount = 0.01; | ||
| 107 | if self.tabIndex == 1 then | ||
| 108 | local zfb_url = self.params.zfb_url; | ||
| 109 | local paramsStr = "out_trade_no="..trade_no.."&appid=1".."&subject="..subject.."&total_amount="..total_amount.."¬ify_url="..zfb_url; | ||
| 110 | MyHttpRequest:getInstance():request("POST",PAY_URL.."/alipay/getqr.php","",paramsStr,callBack); | ||
| 111 | else | ||
| 112 | local wx_url = self.params.wx_url; | ||
| 113 | local paramsStr = "out_trade_no="..trade_no.."&appid=1".."&subject="..subject.."&total_amount="..total_amount.."¬ify_url="..wx_url; | ||
| 114 | MyHttpRequest:getInstance():request("POST",PAY_URL.."/wxpay/getqr.php","",paramsStr,callBack); | ||
| 115 | end | ||
| 116 | qr_view.isShow = true; | ||
| 117 | end | ||
| 118 | end | ||
| 119 | |||
| 120 | function QrPayView:onCancel() | ||
| 121 | cmsg.off("gateway_msg.notify_pay_succ_msg_res",self.onPaySuccResFunHandler); | ||
| 122 | self:close(); | ||
| 123 | end | ||
| 124 | |||
| 125 | --返回键处理函数 | ||
| 126 | function QrPayView:onKeypadBack() | ||
| 127 | cmsg.off("gateway_msg.notify_pay_succ_msg_res",self.onPaySuccResFunHandler); | ||
| 128 | self:close(); | ||
| 129 | end | ||
| 130 | |||
| 131 | --左键处理函数 | ||
| 132 | function QrPayView:onKeypadLeft(isBounce) | ||
| 133 | if self.selectedIndex > 1 then | ||
| 134 | QrPayView.super.onKeypadLeft(self,false); | ||
| 135 | end | ||
| 136 | local curNode = self.nodes[self.nodeIndex][self.selectedIndex]; | ||
| 137 | if curNode:getName() == "btn_alipay" then | ||
| 138 | self:onAliPay(); | ||
| 139 | elseif curNode:getName() == "btn_wx" then | ||
| 140 | self:onWxPay(); | ||
| 141 | end | ||
| 142 | end | ||
| 143 | |||
| 144 | --左键处理函数 | ||
| 145 | function QrPayView:onKeypadRight(isBounce) | ||
| 146 | if self.selectedIndex < #self.nodes then | ||
| 147 | QrPayView.super.onKeypadRight(self,false); | ||
| 148 | end | ||
| 149 | local curNode = self.nodes[self.nodeIndex][self.selectedIndex]; | ||
| 150 | if curNode:getName() == "btn_alipay" then | ||
| 151 | self:onAliPay(); | ||
| 152 | elseif curNode:getName() == "btn_wx" then | ||
| 153 | self:onWxPay(); | ||
| 154 | end | ||
| 155 | end | ||
| 156 | |||
| 157 | return QrPayView | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -174,7 +174,7 @@ function cc.pIsSegmentIntersect(pt1,pt2,pt3,pt4) | ... | @@ -174,7 +174,7 @@ function cc.pIsSegmentIntersect(pt1,pt2,pt3,pt4) |
| 174 | local s,t,ret = 0,0,false | 174 | local s,t,ret = 0,0,false |
| 175 | ret,s,t =cc.pIsLineIntersect(pt1, pt2, pt3, pt4,s,t) | 175 | ret,s,t =cc.pIsLineIntersect(pt1, pt2, pt3, pt4,s,t) |
| 176 | 176 | ||
| 177 | if ret and s >= 0.0 and s <= 1.0 and t >= 0.0 and t <= 1.0 then | 177 | if ret and s >= 0.0 and s <= 1.0 and t >= 0.0 and t <= 0.0 then |
| 178 | return true | 178 | return true |
| 179 | end | 179 | end |
| 180 | 180 | ||
| ... | @@ -558,23 +558,3 @@ function cc.mat4.createRotation(q, dst) | ... | @@ -558,23 +558,3 @@ function cc.mat4.createRotation(q, dst) |
| 558 | 558 | ||
| 559 | return dst | 559 | return dst |
| 560 | end | 560 | end |
| 561 | |||
| 562 | function cc.mat4.translate(self,vec3) | ||
| 563 | return mat4_translate(self,vec3) | ||
| 564 | end | ||
| 565 | |||
| 566 | function cc.mat4.createRotationZ(self,angle) | ||
| 567 | return mat4_createRotationZ(self,angle) | ||
| 568 | end | ||
| 569 | |||
| 570 | function cc.mat4.setIdentity(self) | ||
| 571 | return mat4_setIdentity(self) | ||
| 572 | end | ||
| 573 | |||
| 574 | function cc.mat4.createTranslation(...) | ||
| 575 | return mat4_createTranslation(...) | ||
| 576 | end | ||
| 577 | |||
| 578 | function cc.mat4.createRotation(...) | ||
| 579 | return mat4_createRotation(...) | ||
| 580 | end | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -265,7 +265,7 @@ cc.Handler.EVENT_SPINE = 52 | ... | @@ -265,7 +265,7 @@ cc.Handler.EVENT_SPINE = 52 |
| 265 | cc.Handler.EVENT_PHYSICS_CONTACT_BEGIN = 53 | 265 | cc.Handler.EVENT_PHYSICS_CONTACT_BEGIN = 53 |
| 266 | cc.Handler.EVENT_PHYSICS_CONTACT_PRESOLVE = 54 | 266 | cc.Handler.EVENT_PHYSICS_CONTACT_PRESOLVE = 54 |
| 267 | cc.Handler.EVENT_PHYSICS_CONTACT_POSTSOLVE = 55 | 267 | cc.Handler.EVENT_PHYSICS_CONTACT_POSTSOLVE = 55 |
| 268 | cc.Handler.EVENT_PHYSICS_CONTACT_SEPARATE = 56 | 268 | cc.Handler.EVENT_PHYSICS_CONTACT_SEPERATE = 56 |
| 269 | cc.Handler.EVENT_FOCUS = 57 | 269 | cc.Handler.EVENT_FOCUS = 57 |
| 270 | cc.Handler.EVENT_CONTROLLER_CONNECTED = 58 | 270 | cc.Handler.EVENT_CONTROLLER_CONNECTED = 58 |
| 271 | cc.Handler.EVENT_CONTROLLER_DISCONNECTED = 59 | 271 | cc.Handler.EVENT_CONTROLLER_DISCONNECTED = 59 |
| ... | @@ -312,14 +312,6 @@ cc.LabelEffect = | ... | @@ -312,14 +312,6 @@ cc.LabelEffect = |
| 312 | GLOW = 3, | 312 | GLOW = 3, |
| 313 | } | 313 | } |
| 314 | 314 | ||
| 315 | cc.LabelOverflow = | ||
| 316 | { | ||
| 317 | NONE = 0, | ||
| 318 | CLAMP = 1, | ||
| 319 | SHRINK = 2, | ||
| 320 | RESIZE_HEIGHT = 3 | ||
| 321 | }; | ||
| 322 | |||
| 323 | cc.KeyCodeKey = | 315 | cc.KeyCodeKey = |
| 324 | { | 316 | { |
| 325 | "KEY_NONE", | 317 | "KEY_NONE", |
| ... | @@ -505,7 +497,7 @@ cc.KeyCode.KEY_LEFT_ALT = cc.KeyCode.KEY_ALT | ... | @@ -505,7 +497,7 @@ cc.KeyCode.KEY_LEFT_ALT = cc.KeyCode.KEY_ALT |
| 505 | 497 | ||
| 506 | cc.EventAssetsManagerEx = | 498 | cc.EventAssetsManagerEx = |
| 507 | { | 499 | { |
| 508 | EventCode = | 500 | EventCode = |
| 509 | { | 501 | { |
| 510 | ERROR_NO_LOCAL_MANIFEST = 0, | 502 | ERROR_NO_LOCAL_MANIFEST = 0, |
| 511 | ERROR_DOWNLOAD_MANIFEST = 1, | 503 | ERROR_DOWNLOAD_MANIFEST = 1, |
| ... | @@ -516,8 +508,6 @@ cc.EventAssetsManagerEx = | ... | @@ -516,8 +508,6 @@ cc.EventAssetsManagerEx = |
| 516 | ASSET_UPDATED = 6, | 508 | ASSET_UPDATED = 6, |
| 517 | ERROR_UPDATING = 7, | 509 | ERROR_UPDATING = 7, |
| 518 | UPDATE_FINISHED = 8, | 510 | UPDATE_FINISHED = 8, |
| 519 | UPDATE_FAILED = 9, | ||
| 520 | ERROR_DECOMPRESS = 10 | ||
| 521 | }, | 511 | }, |
| 522 | } | 512 | } |
| 523 | 513 | ||
| ... | @@ -560,14 +550,6 @@ cc.CameraFlag = | ... | @@ -560,14 +550,6 @@ cc.CameraFlag = |
| 560 | USER8 = 256, | 550 | USER8 = 256, |
| 561 | } | 551 | } |
| 562 | 552 | ||
| 563 | cc.CameraBackgroundBrush.BrushType = | ||
| 564 | { | ||
| 565 | NONE = 0, | ||
| 566 | DEPTH = 1, | ||
| 567 | COLOR = 2, | ||
| 568 | SKYBOX = 3, | ||
| 569 | } | ||
| 570 | |||
| 571 | cc.BillBoard_Mode = | 553 | cc.BillBoard_Mode = |
| 572 | { | 554 | { |
| 573 | VIEW_POINT_ORIENTED = 0, | 555 | VIEW_POINT_ORIENTED = 0, |
| ... | @@ -601,7 +583,7 @@ cc.MATRIX_STACK_TYPE = | ... | @@ -601,7 +583,7 @@ cc.MATRIX_STACK_TYPE = |
| 601 | TEXTURE = 2, | 583 | TEXTURE = 2, |
| 602 | } | 584 | } |
| 603 | 585 | ||
| 604 | cc.LightType = | 586 | cc.LightType = |
| 605 | { | 587 | { |
| 606 | DIRECTIONAL = 0, | 588 | DIRECTIONAL = 0, |
| 607 | POINT = 1, | 589 | POINT = 1, |
| ... | @@ -609,7 +591,7 @@ cc.LightType = | ... | @@ -609,7 +591,7 @@ cc.LightType = |
| 609 | AMBIENT = 3, | 591 | AMBIENT = 3, |
| 610 | } | 592 | } |
| 611 | 593 | ||
| 612 | cc.LightFlag = | 594 | cc.LightFlag = |
| 613 | { | 595 | { |
| 614 | LIGHT0 = math.pow(2,0), | 596 | LIGHT0 = math.pow(2,0), |
| 615 | LIGHT1 = math.pow(2,1), | 597 | LIGHT1 = math.pow(2,1), |
| ... | @@ -629,19 +611,13 @@ cc.LightFlag = | ... | @@ -629,19 +611,13 @@ cc.LightFlag = |
| 629 | LIGHT15 = math.pow(2,15), | 611 | LIGHT15 = math.pow(2,15), |
| 630 | } | 612 | } |
| 631 | 613 | ||
| 614 | cc.AsyncTaskPool = cc.AsyncTaskPool or {} | ||
| 615 | |||
| 632 | cc.AsyncTaskPool.TaskType = | 616 | cc.AsyncTaskPool.TaskType = |
| 633 | { | 617 | { |
| 634 | TASK_IO = 0, | 618 | TASK_IO = 0, |
| 635 | TASK_NETWORK = 1, | 619 | TASK_NETWORK = 1, |
| 636 | TASK_OTHER = 2, | 620 | TASK_OTHER = 2, |
| 637 | TASK_MAX_TYPE = 3, | 621 | TASK_MAX_TYPE = 3, |
| 638 | } | 622 | } |
| 639 | 623 | ||
| 640 | |||
| 641 | cc.RED = cc.c3b(255,0,0) | ||
| 642 | cc.GREEN = cc.c3b(0,255,0) | ||
| 643 | cc.BLUE = cc.c3b(0,0,255) | ||
| 644 | cc.BLACK = cc.c3b(0,0,0) | ||
| 645 | cc.WHITE = cc.c3b(255,255,255) | ||
| 646 | cc.YELLOW = cc.c3b(255,255,0) | ||
| 647 | ... | ... |
| ... | @@ -336,13 +336,13 @@ end | ... | @@ -336,13 +336,13 @@ end |
| 336 | _G["CCCallFunc"] = DeprecatedClass.CCCallFunc() | 336 | _G["CCCallFunc"] = DeprecatedClass.CCCallFunc() |
| 337 | --CCCallFunc class will be Deprecated,end | 337 | --CCCallFunc class will be Deprecated,end |
| 338 | 338 | ||
| 339 | --CCWaves3D class will be Deprecated,begin | 339 | --CCmp3es3D class will be Deprecated,begin |
| 340 | function DeprecatedClass.CCWaves3D() | 340 | function DeprecatedClass.CCmp3es3D() |
| 341 | deprecatedTip("CCWaves3D","cc.Waves3D") | 341 | deprecatedTip("CCmp3es3D","cc.mp3es3D") |
| 342 | return cc.Waves3D | 342 | return cc.mp3es3D |
| 343 | end | 343 | end |
| 344 | _G["CCWaves3D"] = DeprecatedClass.CCWaves3D() | 344 | _G["CCmp3es3D"] = DeprecatedClass.CCmp3es3D() |
| 345 | --CCWaves3D class will be Deprecated,end | 345 | --CCmp3es3D class will be Deprecated,end |
| 346 | 346 | ||
| 347 | --CCFlipX3D class will be Deprecated,begin | 347 | --CCFlipX3D class will be Deprecated,begin |
| 348 | function DeprecatedClass.CCFlipX3D() | 348 | function DeprecatedClass.CCFlipX3D() |
| ... | @@ -1433,13 +1433,13 @@ end | ... | @@ -1433,13 +1433,13 @@ end |
| 1433 | _G["CCParticleRain"] = DeprecatedClass.CCParticleRain() | 1433 | _G["CCParticleRain"] = DeprecatedClass.CCParticleRain() |
| 1434 | --CCParticleRain class will be Deprecated,end | 1434 | --CCParticleRain class will be Deprecated,end |
| 1435 | 1435 | ||
| 1436 | --CCWaves class will be Deprecated,begin | 1436 | --CCmp3es class will be Deprecated,begin |
| 1437 | function DeprecatedClass.CCWaves() | 1437 | function DeprecatedClass.CCmp3es() |
| 1438 | deprecatedTip("CCWaves","cc.Waves") | 1438 | deprecatedTip("CCmp3es","cc.mp3es") |
| 1439 | return cc.Waves | 1439 | return cc.mp3es |
| 1440 | end | 1440 | end |
| 1441 | _G["CCWaves"] = DeprecatedClass.CCWaves() | 1441 | _G["CCmp3es"] = DeprecatedClass.CCmp3es() |
| 1442 | --CCWaves class will be Deprecated,end | 1442 | --CCmp3es class will be Deprecated,end |
| 1443 | 1443 | ||
| 1444 | --CCEaseOut class will be Deprecated,begin | 1444 | --CCEaseOut class will be Deprecated,begin |
| 1445 | function DeprecatedClass.CCEaseOut() | 1445 | function DeprecatedClass.CCEaseOut() |
| ... | @@ -1665,13 +1665,13 @@ end | ... | @@ -1665,13 +1665,13 @@ end |
| 1665 | _G["CCTransitionSlideInL"] = DeprecatedClass.CCTransitionSlideInL() | 1665 | _G["CCTransitionSlideInL"] = DeprecatedClass.CCTransitionSlideInL() |
| 1666 | --CCTransitionSlideInL class will be Deprecated,end | 1666 | --CCTransitionSlideInL class will be Deprecated,end |
| 1667 | 1667 | ||
| 1668 | --CCWavesTiles3D class will be Deprecated,begin | 1668 | --CCmp3esTiles3D class will be Deprecated,begin |
| 1669 | function DeprecatedClass.CCWavesTiles3D() | 1669 | function DeprecatedClass.CCmp3esTiles3D() |
| 1670 | deprecatedTip("CCWavesTiles3D","cc.WavesTiles3D") | 1670 | deprecatedTip("CCmp3esTiles3D","cc.mp3esTiles3D") |
| 1671 | return cc.WavesTiles3D | 1671 | return cc.mp3esTiles3D |
| 1672 | end | 1672 | end |
| 1673 | _G["CCWavesTiles3D"] = DeprecatedClass.CCWavesTiles3D() | 1673 | _G["CCmp3esTiles3D"] = DeprecatedClass.CCmp3esTiles3D() |
| 1674 | --CCWavesTiles3D class will be Deprecated,end | 1674 | --CCmp3esTiles3D class will be Deprecated,end |
| 1675 | 1675 | ||
| 1676 | --CCTransitionSlideInB class will be Deprecated,begin | 1676 | --CCTransitionSlideInB class will be Deprecated,begin |
| 1677 | function DeprecatedClass.CCTransitionSlideInB() | 1677 | function DeprecatedClass.CCTransitionSlideInB() | ... | ... |
| 1 | --[[ | 1 | --[[ |
| 2 | 2 | ||
| 3 | Copyright (c) 2011-2014 chukong-inc.com | 3 | Copyright (c) 2011-2015 chukong-inc.com |
| 4 | 4 | ||
| 5 | Permission is hereby granted, free of charge, to any person obtaining a copy | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | of this software and associated documentation files (the "Software"), to deal | 6 | of this software and associated documentation files (the "Software"), to deal |
| ... | @@ -22,27 +22,80 @@ THE SOFTWARE. | ... | @@ -22,27 +22,80 @@ THE SOFTWARE. |
| 22 | 22 | ||
| 23 | ]] | 23 | ]] |
| 24 | 24 | ||
| 25 | local tostring = tostring | ||
| 26 | local tonumber = tonumber | ||
| 27 | local assert = assert | ||
| 28 | local error = error | ||
| 29 | local type = type | ||
| 30 | local pairs = pairs | ||
| 31 | local ipairs = ipairs | ||
| 32 | local pcall = pcall | ||
| 33 | local ngx = ngx | ||
| 34 | local ngx_log = nil | ||
| 35 | if ngx then ngx_log = ngx.log end | ||
| 36 | local table_insert = table.insert | ||
| 37 | local table_remove = table.remove | ||
| 38 | local table_format = string.format | ||
| 39 | local string_upper = string.upper | ||
| 40 | local string_len = string.len | ||
| 41 | local string_rep = string.rep | ||
| 42 | local string_find = string.find | ||
| 43 | local string_gsub = string.gsub | ||
| 44 | local string_sub = string.sub | ||
| 45 | local string_byte = string.byte | ||
| 46 | local string_char = string.char | ||
| 47 | local math_floor = math.floor | ||
| 48 | local math_ceil = math.ceil | ||
| 49 | local math_random = math.random | ||
| 50 | local math_randomseed = math.randomseed | ||
| 51 | local io_open = io.open | ||
| 52 | local io_close = io.close | ||
| 53 | local os_time = os.time | ||
| 54 | local debug_traceback = debug.traceback | ||
| 55 | local debug_getlocal = debug.getlocal | ||
| 56 | |||
| 57 | -- internal function, advise you not to call it directly. | ||
| 25 | function printLog(tag, fmt, ...) | 58 | function printLog(tag, fmt, ...) |
| 59 | if ngx_log then | ||
| 60 | ngx_log(ngx[tag], table_format(tostring(fmt), ...)) | ||
| 61 | if tag == "ERR" then | ||
| 62 | ngx_log(ngx.ERR, debug_traceback("", 2)) | ||
| 63 | end | ||
| 64 | return | ||
| 65 | end | ||
| 66 | |||
| 26 | local t = { | 67 | local t = { |
| 27 | "[", | 68 | "[", |
| 28 | string.upper(tostring(tag)), | 69 | string_upper(tostring(tag)), |
| 29 | "] ", | 70 | "] ", |
| 30 | string.format(tostring(fmt), ...) | 71 | table_format(tostring(fmt), ...) |
| 31 | } | 72 | } |
| 73 | if tag == "ERR" then | ||
| 74 | table_insert(t, debug_traceback("", 2)) | ||
| 75 | end | ||
| 32 | print(table.concat(t)) | 76 | print(table.concat(t)) |
| 33 | end | 77 | end |
| 34 | 78 | ||
| 35 | function printError(fmt, ...) | 79 | function printError(fmt, ...) |
| 36 | printLog("ERR", fmt, ...) | 80 | printLog("ERR", fmt, ...) |
| 37 | print(debug.traceback("", 2)) | 81 | end |
| 82 | |||
| 83 | function printDebug(fmt, ...) | ||
| 84 | if DEBUG < 3 then return end | ||
| 85 | printLog("DEBUG", fmt, ...) | ||
| 38 | end | 86 | end |
| 39 | 87 | ||
| 40 | function printInfo(fmt, ...) | 88 | function printInfo(fmt, ...) |
| 41 | if type(DEBUG) ~= "number" or DEBUG < 2 then return end | 89 | if DEBUG < 2 then return end |
| 42 | printLog("INFO", fmt, ...) | 90 | printLog("INFO", fmt, ...) |
| 43 | end | 91 | end |
| 44 | 92 | ||
| 45 | local function dump_value_(v) | 93 | function printWarn(fmt, ...) |
| 94 | if DEBUG < 1 then return end | ||
| 95 | printLog("WARN", fmt, ...) | ||
| 96 | end | ||
| 97 | |||
| 98 | local function _dump_value(v) | ||
| 46 | if type(v) == "string" then | 99 | if type(v) == "string" then |
| 47 | v = "\"" .. v .. "\"" | 100 | v = "\"" .. v .. "\"" |
| 48 | end | 101 | end |
| ... | @@ -52,36 +105,35 @@ end | ... | @@ -52,36 +105,35 @@ end |
| 52 | function dump(value, desciption, nesting) | 105 | function dump(value, desciption, nesting) |
| 53 | if type(nesting) ~= "number" then nesting = 3 end | 106 | if type(nesting) ~= "number" then nesting = 3 end |
| 54 | 107 | ||
| 55 | local lookupTable = {} | 108 | local lookup = {} |
| 56 | local result = {} | 109 | local result = {} |
| 57 | 110 | local traceback = string.split(debug_traceback("", 2), "\n") | |
| 58 | local traceback = string.split(debug.traceback("", 2), "\n") | ||
| 59 | print("dump from: " .. string.trim(traceback[3])) | 111 | print("dump from: " .. string.trim(traceback[3])) |
| 60 | 112 | ||
| 61 | local function dump_(value, desciption, indent, nest, keylen) | 113 | local function _dump(value, desciption, indent, nest, keylen) |
| 62 | desciption = desciption or "<var>" | 114 | desciption = desciption or "<var>" |
| 63 | local spc = "" | 115 | local spc = "" |
| 64 | if type(keylen) == "number" then | 116 | if type(keylen) == "number" then |
| 65 | spc = string.rep(" ", keylen - string.len(dump_value_(desciption))) | 117 | spc = string_rep(" ", keylen - string_len(_dump_value(desciption))) |
| 66 | end | 118 | end |
| 67 | if type(value) ~= "table" then | 119 | if type(value) ~= "table" then |
| 68 | result[#result +1 ] = string.format("%s%s%s = %s", indent, dump_value_(desciption), spc, dump_value_(value)) | 120 | result[#result +1 ] = table_format("%s%s%s = %s", indent, _dump_value(desciption), spc, _dump_value(value)) |
| 69 | elseif lookupTable[tostring(value)] then | 121 | elseif lookup[tostring(value)] then |
| 70 | result[#result +1 ] = string.format("%s%s%s = *REF*", indent, dump_value_(desciption), spc) | 122 | result[#result +1 ] = table_format("%s%s%s = *REF*", indent, _dump_value(desciption), spc) |
| 71 | else | 123 | else |
| 72 | lookupTable[tostring(value)] = true | 124 | lookup[tostring(value)] = true |
| 73 | if nest > nesting then | 125 | if nest > nesting then |
| 74 | result[#result +1 ] = string.format("%s%s = *MAX NESTING*", indent, dump_value_(desciption)) | 126 | result[#result +1 ] = table_format("%s%s = *MAX NESTING*", indent, _dump_value(desciption)) |
| 75 | else | 127 | else |
| 76 | result[#result +1 ] = string.format("%s%s = {", indent, dump_value_(desciption)) | 128 | result[#result +1 ] = table_format("%s%s = {", indent, _dump_value(desciption)) |
| 77 | local indent2 = indent.." " | 129 | local indent2 = indent.." " |
| 78 | local keys = {} | 130 | local keys = {} |
| 79 | local keylen = 0 | 131 | local keylen = 0 |
| 80 | local values = {} | 132 | local values = {} |
| 81 | for k, v in pairs(value) do | 133 | for k, v in pairs(value) do |
| 82 | keys[#keys + 1] = k | 134 | keys[#keys + 1] = k |
| 83 | local vk = dump_value_(k) | 135 | local vk = _dump_value(k) |
| 84 | local vkl = string.len(vk) | 136 | local vkl = string_len(vk) |
| 85 | if vkl > keylen then keylen = vkl end | 137 | if vkl > keylen then keylen = vkl end |
| 86 | values[k] = v | 138 | values[k] = v |
| 87 | end | 139 | end |
| ... | @@ -93,13 +145,13 @@ function dump(value, desciption, nesting) | ... | @@ -93,13 +145,13 @@ function dump(value, desciption, nesting) |
| 93 | end | 145 | end |
| 94 | end) | 146 | end) |
| 95 | for i, k in ipairs(keys) do | 147 | for i, k in ipairs(keys) do |
| 96 | dump_(values[k], k, indent2, nest + 1, keylen) | 148 | _dump(values[k], k, indent2, nest + 1, keylen) |
| 97 | end | 149 | end |
| 98 | result[#result +1] = string.format("%s}", indent) | 150 | result[#result +1] = table_format("%s}", indent) |
| 99 | end | 151 | end |
| 100 | end | 152 | end |
| 101 | end | 153 | end |
| 102 | dump_(value, desciption, "- ", 1) | 154 | _dump(value, desciption, "- ", 1) |
| 103 | 155 | ||
| 104 | for i, line in ipairs(result) do | 156 | for i, line in ipairs(result) do |
| 105 | print(line) | 157 | print(line) |
| ... | @@ -107,7 +159,7 @@ function dump(value, desciption, nesting) | ... | @@ -107,7 +159,7 @@ function dump(value, desciption, nesting) |
| 107 | end | 159 | end |
| 108 | 160 | ||
| 109 | function printf(fmt, ...) | 161 | function printf(fmt, ...) |
| 110 | print(string.format(tostring(fmt), ...)) | 162 | print(table_format(tostring(fmt), ...)) |
| 111 | end | 163 | end |
| 112 | 164 | ||
| 113 | function checknumber(value, base) | 165 | function checknumber(value, base) |
| ... | @@ -132,15 +184,15 @@ function isset(hashtable, key) | ... | @@ -132,15 +184,15 @@ function isset(hashtable, key) |
| 132 | return (t == "table" or t == "userdata") and hashtable[key] ~= nil | 184 | return (t == "table" or t == "userdata") and hashtable[key] ~= nil |
| 133 | end | 185 | end |
| 134 | 186 | ||
| 135 | local setmetatableindex_ | 187 | local _setmetatableindex |
| 136 | setmetatableindex_ = function(t, index) | 188 | _setmetatableindex = function(t, index) |
| 137 | if type(t) == "userdata" then | 189 | if type(t) == "userdata" then |
| 138 | local peer = tolua.getpeer(t) | 190 | local peer = tolua.getpeer(t) |
| 139 | if not peer then | 191 | if not peer then |
| 140 | peer = {} | 192 | peer = {} |
| 141 | tolua.setpeer(t, peer) | 193 | tolua.setpeer(t, peer) |
| 142 | end | 194 | end |
| 143 | setmetatableindex_(peer, index) | 195 | _setmetatableindex(peer, index) |
| 144 | else | 196 | else |
| 145 | local mt = getmetatable(t) | 197 | local mt = getmetatable(t) |
| 146 | if not mt then mt = {} end | 198 | if not mt then mt = {} end |
| ... | @@ -148,22 +200,22 @@ setmetatableindex_ = function(t, index) | ... | @@ -148,22 +200,22 @@ setmetatableindex_ = function(t, index) |
| 148 | mt.__index = index | 200 | mt.__index = index |
| 149 | setmetatable(t, mt) | 201 | setmetatable(t, mt) |
| 150 | elseif mt.__index ~= index then | 202 | elseif mt.__index ~= index then |
| 151 | setmetatableindex_(mt, index) | 203 | _setmetatableindex(mt, index) |
| 152 | end | 204 | end |
| 153 | end | 205 | end |
| 154 | end | 206 | end |
| 155 | setmetatableindex = setmetatableindex_ | 207 | setmetatableindex = _setmetatableindex |
| 156 | 208 | ||
| 157 | function clone(object) | 209 | function clone(object) |
| 158 | local lookup_table = {} | 210 | local lookup = {} |
| 159 | local function _copy(object) | 211 | local function _copy(object) |
| 160 | if type(object) ~= "table" then | 212 | if type(object) ~= "table" then |
| 161 | return object | 213 | return object |
| 162 | elseif lookup_table[object] then | 214 | elseif lookup[object] then |
| 163 | return lookup_table[object] | 215 | return lookup[object] |
| 164 | end | 216 | end |
| 165 | local newObject = {} | 217 | local newObject = {} |
| 166 | lookup_table[object] = newObject | 218 | lookup[object] = newObject |
| 167 | for key, value in pairs(object) do | 219 | for key, value in pairs(object) do |
| 168 | newObject[_copy(key)] = _copy(value) | 220 | newObject[_copy(key)] = _copy(value) |
| 169 | end | 221 | end |
| ... | @@ -179,12 +231,12 @@ function class(classname, ...) | ... | @@ -179,12 +231,12 @@ function class(classname, ...) |
| 179 | for _, super in ipairs(supers) do | 231 | for _, super in ipairs(supers) do |
| 180 | local superType = type(super) | 232 | local superType = type(super) |
| 181 | assert(superType == "nil" or superType == "table" or superType == "function", | 233 | assert(superType == "nil" or superType == "table" or superType == "function", |
| 182 | string.format("class() - create class \"%s\" with invalid super class type \"%s\"", | 234 | table_format("class() - create class \"%s\" with invalid super class type \"%s\"", |
| 183 | classname, superType)) | 235 | classname, superType)) |
| 184 | 236 | ||
| 185 | if superType == "function" then | 237 | if superType == "function" then |
| 186 | assert(cls.__create == nil, | 238 | assert(cls.__create == nil, |
| 187 | string.format("class() - create class \"%s\" with more than one creating function", | 239 | table_format("class() - create class \"%s\" with more than one creating function", |
| 188 | classname)); | 240 | classname)); |
| 189 | -- if super is function, set it to __create | 241 | -- if super is function, set it to __create |
| 190 | cls.__create = super | 242 | cls.__create = super |
| ... | @@ -192,7 +244,7 @@ function class(classname, ...) | ... | @@ -192,7 +244,7 @@ function class(classname, ...) |
| 192 | if super[".isclass"] then | 244 | if super[".isclass"] then |
| 193 | -- super is native class | 245 | -- super is native class |
| 194 | assert(cls.__create == nil, | 246 | assert(cls.__create == nil, |
| 195 | string.format("class() - create class \"%s\" with more than one creating function or native class", | 247 | table_format("class() - create class \"%s\" with more than one creating function or native class", |
| 196 | classname)); | 248 | classname)); |
| 197 | cls.__create = function() return super:create() end | 249 | cls.__create = function() return super:create() end |
| 198 | else | 250 | else |
| ... | @@ -205,7 +257,7 @@ function class(classname, ...) | ... | @@ -205,7 +257,7 @@ function class(classname, ...) |
| 205 | end | 257 | end |
| 206 | end | 258 | end |
| 207 | else | 259 | else |
| 208 | error(string.format("class() - create class \"%s\" with invalid super type", | 260 | error(table_format("class() - create class \"%s\" with invalid super type", |
| 209 | classname), 0) | 261 | classname), 0) |
| 210 | end | 262 | end |
| 211 | end | 263 | end |
| ... | @@ -234,7 +286,7 @@ function class(classname, ...) | ... | @@ -234,7 +286,7 @@ function class(classname, ...) |
| 234 | else | 286 | else |
| 235 | instance = {} | 287 | instance = {} |
| 236 | end | 288 | end |
| 237 | setmetatableindex(instance, cls) | 289 | _setmetatableindex(instance, cls) |
| 238 | instance.class = cls | 290 | instance.class = cls |
| 239 | instance:ctor(...) | 291 | instance:ctor(...) |
| 240 | return instance | 292 | return instance |
| ... | @@ -246,8 +298,8 @@ function class(classname, ...) | ... | @@ -246,8 +298,8 @@ function class(classname, ...) |
| 246 | return cls | 298 | return cls |
| 247 | end | 299 | end |
| 248 | 300 | ||
| 249 | local iskindof_ | 301 | local _iskindof |
| 250 | iskindof_ = function(cls, name) | 302 | _iskindof = function(cls, name) |
| 251 | local __index = rawget(cls, "__index") | 303 | local __index = rawget(cls, "__index") |
| 252 | if type(__index) == "table" and rawget(__index, "__cname") == name then return true end | 304 | if type(__index) == "table" and rawget(__index, "__cname") == name then return true end |
| 253 | 305 | ||
| ... | @@ -255,7 +307,7 @@ iskindof_ = function(cls, name) | ... | @@ -255,7 +307,7 @@ iskindof_ = function(cls, name) |
| 255 | local __supers = rawget(cls, "__supers") | 307 | local __supers = rawget(cls, "__supers") |
| 256 | if not __supers then return false end | 308 | if not __supers then return false end |
| 257 | for _, super in ipairs(__supers) do | 309 | for _, super in ipairs(__supers) do |
| 258 | if iskindof_(super, name) then return true end | 310 | if _iskindof(super, name) then return true end |
| 259 | end | 311 | end |
| 260 | return false | 312 | return false |
| 261 | end | 313 | end |
| ... | @@ -272,7 +324,7 @@ function iskindof(obj, classname) | ... | @@ -272,7 +324,7 @@ function iskindof(obj, classname) |
| 272 | mt = getmetatable(obj) | 324 | mt = getmetatable(obj) |
| 273 | end | 325 | end |
| 274 | if mt then | 326 | if mt then |
| 275 | return iskindof_(mt, classname) | 327 | return _iskindof(mt, classname) |
| 276 | end | 328 | end |
| 277 | return false | 329 | return false |
| 278 | end | 330 | end |
| ... | @@ -283,8 +335,8 @@ function import(moduleName, currentModuleName) | ... | @@ -283,8 +335,8 @@ function import(moduleName, currentModuleName) |
| 283 | local offset = 1 | 335 | local offset = 1 |
| 284 | 336 | ||
| 285 | while true do | 337 | while true do |
| 286 | if string.byte(moduleName, offset) ~= 46 then -- . | 338 | if string_byte(moduleName, offset) ~= 46 then -- . |
| 287 | moduleFullName = string.sub(moduleName, offset) | 339 | moduleFullName = string_sub(moduleName, offset) |
| 288 | if currentModuleNameParts and #currentModuleNameParts > 0 then | 340 | if currentModuleNameParts and #currentModuleNameParts > 0 then |
| 289 | moduleFullName = table.concat(currentModuleNameParts, ".") .. "." .. moduleFullName | 341 | moduleFullName = table.concat(currentModuleNameParts, ".") .. "." .. moduleFullName |
| 290 | end | 342 | end |
| ... | @@ -294,13 +346,13 @@ function import(moduleName, currentModuleName) | ... | @@ -294,13 +346,13 @@ function import(moduleName, currentModuleName) |
| 294 | 346 | ||
| 295 | if not currentModuleNameParts then | 347 | if not currentModuleNameParts then |
| 296 | if not currentModuleName then | 348 | if not currentModuleName then |
| 297 | local n,v = debug.getlocal(3, 1) | 349 | local n,v = debug_getlocal(3, 1) |
| 298 | currentModuleName = v | 350 | currentModuleName = v |
| 299 | end | 351 | end |
| 300 | 352 | ||
| 301 | currentModuleNameParts = string.split(currentModuleName, ".") | 353 | currentModuleNameParts = string.split(currentModuleName, ".") |
| 302 | end | 354 | end |
| 303 | table.remove(currentModuleNameParts, #currentModuleNameParts) | 355 | table_remove(currentModuleNameParts, #currentModuleNameParts) |
| 304 | end | 356 | end |
| 305 | 357 | ||
| 306 | return require(moduleFullName) | 358 | return require(moduleFullName) |
| ... | @@ -313,50 +365,55 @@ function handler(obj, method) | ... | @@ -313,50 +365,55 @@ function handler(obj, method) |
| 313 | end | 365 | end |
| 314 | 366 | ||
| 315 | function math.newrandomseed() | 367 | function math.newrandomseed() |
| 316 | local ok, socket = pcall(function() | 368 | math_randomseed(os_time()) |
| 317 | return require("socket") | 369 | math_random() |
| 318 | end) | 370 | math_random() |
| 319 | 371 | math_random() | |
| 320 | if ok then | 372 | math_random() |
| 321 | math.randomseed(socket.gettime() * 1000) | ||
| 322 | else | ||
| 323 | math.randomseed(os.time()) | ||
| 324 | end | ||
| 325 | math.random() | ||
| 326 | math.random() | ||
| 327 | math.random() | ||
| 328 | math.random() | ||
| 329 | end | 373 | end |
| 330 | 374 | ||
| 331 | function math.round(value) | 375 | function math.round(value) |
| 332 | value = checknumber(value) | 376 | value = checknumber(value) |
| 333 | return math.floor(value + 0.5) | 377 | return math_floor(value + 0.5) |
| 334 | end | 378 | end |
| 335 | 379 | ||
| 336 | local pi_div_180 = math.pi / 180 | 380 | function math.trunc(x) |
| 381 | if x <= 0 then | ||
| 382 | return math_ceil(x); | ||
| 383 | end | ||
| 384 | if math_ceil(x) == x then | ||
| 385 | x = math_ceil(x); | ||
| 386 | else | ||
| 387 | x = math_ceil(x) - 1; | ||
| 388 | end | ||
| 389 | return x; | ||
| 390 | end | ||
| 391 | |||
| 392 | local _pi = math.pi | ||
| 393 | local _piDiv180 = _pi / 180 | ||
| 337 | function math.angle2radian(angle) | 394 | function math.angle2radian(angle) |
| 338 | return angle * pi_div_180 | 395 | return angle * _piDiv180 |
| 339 | end | 396 | end |
| 340 | 397 | ||
| 341 | local pi_mul_180 = math.pi * 180 | 398 | local _piMul180 = _pi * 180 |
| 342 | function math.radian2angle(radian) | 399 | function math.radian2angle(radian) |
| 343 | return radian / pi_mul_180 | 400 | return radian / _piMul180 |
| 344 | end | 401 | end |
| 345 | 402 | ||
| 346 | function io.exists(path) | 403 | function io.exists(path) |
| 347 | local file = io.open(path, "r") | 404 | local file = io_open(path, "r") |
| 348 | if file then | 405 | if file then |
| 349 | io.close(file) | 406 | io_close(file) |
| 350 | return true | 407 | return true |
| 351 | end | 408 | end |
| 352 | return false | 409 | return false |
| 353 | end | 410 | end |
| 354 | 411 | ||
| 355 | function io.readfile(path) | 412 | function io.readfile(path) |
| 356 | local file = io.open(path, "r") | 413 | local file = io_open(path, "r") |
| 357 | if file then | 414 | if file then |
| 358 | local content = file:read("*a") | 415 | local content = file:read("*a") |
| 359 | io.close(file) | 416 | io_close(file) |
| 360 | return content | 417 | return content |
| 361 | end | 418 | end |
| 362 | return nil | 419 | return nil |
| ... | @@ -364,10 +421,10 @@ end | ... | @@ -364,10 +421,10 @@ end |
| 364 | 421 | ||
| 365 | function io.writefile(path, content, mode) | 422 | function io.writefile(path, content, mode) |
| 366 | mode = mode or "w+b" | 423 | mode = mode or "w+b" |
| 367 | local file = io.open(path, mode) | 424 | local file = io_open(path, mode) |
| 368 | if file then | 425 | if file then |
| 369 | if file:write(content) == nil then return false end | 426 | if file:write(content) == nil then return false end |
| 370 | io.close(file) | 427 | io_close(file) |
| 371 | return true | 428 | return true |
| 372 | else | 429 | else |
| 373 | return false | 430 | return false |
| ... | @@ -375,10 +432,10 @@ function io.writefile(path, content, mode) | ... | @@ -375,10 +432,10 @@ function io.writefile(path, content, mode) |
| 375 | end | 432 | end |
| 376 | 433 | ||
| 377 | function io.pathinfo(path) | 434 | function io.pathinfo(path) |
| 378 | local pos = string.len(path) | 435 | local pos = string_len(path) |
| 379 | local extpos = pos + 1 | 436 | local extpos = pos + 1 |
| 380 | while pos > 0 do | 437 | while pos > 0 do |
| 381 | local b = string.byte(path, pos) | 438 | local b = string_byte(path, pos) |
| 382 | if b == 46 then -- 46 = char "." | 439 | if b == 46 then -- 46 = char "." |
| 383 | extpos = pos | 440 | extpos = pos |
| 384 | elseif b == 47 then -- 47 = char "/" | 441 | elseif b == 47 then -- 47 = char "/" |
| ... | @@ -387,11 +444,11 @@ function io.pathinfo(path) | ... | @@ -387,11 +444,11 @@ function io.pathinfo(path) |
| 387 | pos = pos - 1 | 444 | pos = pos - 1 |
| 388 | end | 445 | end |
| 389 | 446 | ||
| 390 | local dirname = string.sub(path, 1, pos) | 447 | local dirname = string_sub(path, 1, pos) |
| 391 | local filename = string.sub(path, pos + 1) | 448 | local filename = string_sub(path, pos + 1) |
| 392 | extpos = extpos - pos | 449 | extpos = extpos - pos |
| 393 | local basename = string.sub(filename, 1, extpos - 1) | 450 | local basename = string_sub(filename, 1, extpos - 1) |
| 394 | local extname = string.sub(filename, extpos) | 451 | local extname = string_sub(filename, extpos) |
| 395 | return { | 452 | return { |
| 396 | dirname = dirname, | 453 | dirname = dirname, |
| 397 | filename = filename, | 454 | filename = filename, |
| ... | @@ -402,12 +459,12 @@ end | ... | @@ -402,12 +459,12 @@ end |
| 402 | 459 | ||
| 403 | function io.filesize(path) | 460 | function io.filesize(path) |
| 404 | local size = false | 461 | local size = false |
| 405 | local file = io.open(path, "r") | 462 | local file = io_open(path, "r") |
| 406 | if file then | 463 | if file then |
| 407 | local current = file:seek() | 464 | local current = file:seek() |
| 408 | size = file:seek("end") | 465 | size = file:seek("end") |
| 409 | file:seek("set", current) | 466 | file:seek("set", current) |
| 410 | io.close(file) | 467 | io_close(file) |
| 411 | end | 468 | end |
| 412 | return size | 469 | return size |
| 413 | end | 470 | end |
| ... | @@ -472,7 +529,7 @@ function table.removebyvalue(array, value, removeall) | ... | @@ -472,7 +529,7 @@ function table.removebyvalue(array, value, removeall) |
| 472 | local c, i, max = 0, 1, #array | 529 | local c, i, max = 0, 1, #array |
| 473 | while i <= max do | 530 | while i <= max do |
| 474 | if array[i] == value then | 531 | if array[i] == value then |
| 475 | table.remove(array, i) | 532 | table_remove(array, i) |
| 476 | c = c + 1 | 533 | c = c + 1 |
| 477 | i = i - 1 | 534 | i = i - 1 |
| 478 | max = max - 1 | 535 | max = max - 1 |
| ... | @@ -484,9 +541,11 @@ function table.removebyvalue(array, value, removeall) | ... | @@ -484,9 +541,11 @@ function table.removebyvalue(array, value, removeall) |
| 484 | end | 541 | end |
| 485 | 542 | ||
| 486 | function table.map(t, fn) | 543 | function table.map(t, fn) |
| 544 | local n = {} | ||
| 487 | for k, v in pairs(t) do | 545 | for k, v in pairs(t) do |
| 488 | t[k] = fn(v, k) | 546 | n[k] = fn(v, k) |
| 489 | end | 547 | end |
| 548 | return n | ||
| 490 | end | 549 | end |
| 491 | 550 | ||
| 492 | function table.walk(t, fn) | 551 | function table.walk(t, fn) |
| ... | @@ -496,9 +555,13 @@ function table.walk(t, fn) | ... | @@ -496,9 +555,13 @@ function table.walk(t, fn) |
| 496 | end | 555 | end |
| 497 | 556 | ||
| 498 | function table.filter(t, fn) | 557 | function table.filter(t, fn) |
| 558 | local n = {} | ||
| 499 | for k, v in pairs(t) do | 559 | for k, v in pairs(t) do |
| 500 | if not fn(v, k) then t[k] = nil end | 560 | if fn(v, k) then |
| 561 | n[k] = v | ||
| 562 | end | ||
| 501 | end | 563 | end |
| 564 | return n | ||
| 502 | end | 565 | end |
| 503 | 566 | ||
| 504 | function table.unique(t, bArray) | 567 | function table.unique(t, bArray) |
| ... | @@ -519,35 +582,34 @@ function table.unique(t, bArray) | ... | @@ -519,35 +582,34 @@ function table.unique(t, bArray) |
| 519 | return n | 582 | return n |
| 520 | end | 583 | end |
| 521 | 584 | ||
| 522 | string._htmlspecialchars_set = {} | 585 | local _htmlSpecialCharsTable = {} |
| 523 | string._htmlspecialchars_set["&"] = "&" | 586 | _htmlSpecialCharsTable["&"] = "&" |
| 524 | string._htmlspecialchars_set["\""] = """ | 587 | _htmlSpecialCharsTable["\""] = """ |
| 525 | string._htmlspecialchars_set["'"] = "'" | 588 | _htmlSpecialCharsTable["'"] = "'" |
| 526 | string._htmlspecialchars_set["<"] = "<" | 589 | _htmlSpecialCharsTable["<"] = "<" |
| 527 | string._htmlspecialchars_set[">"] = ">" | 590 | _htmlSpecialCharsTable[">"] = ">" |
| 528 | |||
| 529 | function string.htmlspecialchars(input) | 591 | function string.htmlspecialchars(input) |
| 530 | for k, v in pairs(string._htmlspecialchars_set) do | 592 | for k, v in pairs(_htmlSpecialCharsTable) do |
| 531 | input = string.gsub(input, k, v) | 593 | input = string_gsub(input, k, v) |
| 532 | end | 594 | end |
| 533 | return input | 595 | return input |
| 534 | end | 596 | end |
| 535 | 597 | ||
| 536 | function string.restorehtmlspecialchars(input) | 598 | function string.restorehtmlspecialchars(input) |
| 537 | for k, v in pairs(string._htmlspecialchars_set) do | 599 | for k, v in pairs(_htmlSpecialCharsTable) do |
| 538 | input = string.gsub(input, v, k) | 600 | input = string_gsub(input, v, k) |
| 539 | end | 601 | end |
| 540 | return input | 602 | return input |
| 541 | end | 603 | end |
| 542 | 604 | ||
| 543 | function string.nl2br(input) | 605 | function string.nl2br(input) |
| 544 | return string.gsub(input, "\n", "<br />") | 606 | return string_gsub(input, "\n", "<br />") |
| 545 | end | 607 | end |
| 546 | 608 | ||
| 547 | function string.text2html(input) | 609 | function string.text2html(input) |
| 548 | input = string.gsub(input, "\t", " ") | 610 | input = string_gsub(input, "\t", " ") |
| 549 | input = string.htmlspecialchars(input) | 611 | input = string.htmlspecialchars(input) |
| 550 | input = string.gsub(input, " ", " ") | 612 | input = string_gsub(input, " ", " ") |
| 551 | input = string.nl2br(input) | 613 | input = string.nl2br(input) |
| 552 | return input | 614 | return input |
| 553 | end | 615 | end |
| ... | @@ -557,58 +619,55 @@ function string.split(input, delimiter) | ... | @@ -557,58 +619,55 @@ function string.split(input, delimiter) |
| 557 | delimiter = tostring(delimiter) | 619 | delimiter = tostring(delimiter) |
| 558 | if (delimiter=='') then return false end | 620 | if (delimiter=='') then return false end |
| 559 | local pos,arr = 0, {} | 621 | local pos,arr = 0, {} |
| 560 | -- for each divider found | 622 | for st,sp in function() return string_find(input, delimiter, pos, true) end do |
| 561 | for st,sp in function() return string.find(input, delimiter, pos, true) end do | 623 | table_insert(arr, string_sub(input, pos, st - 1)) |
| 562 | table.insert(arr, string.sub(input, pos, st - 1)) | ||
| 563 | pos = sp + 1 | 624 | pos = sp + 1 |
| 564 | end | 625 | end |
| 565 | table.insert(arr, string.sub(input, pos)) | 626 | table_insert(arr, string_sub(input, pos)) |
| 566 | return arr | 627 | return arr |
| 567 | end | 628 | end |
| 568 | 629 | ||
| 569 | function string.ltrim(input) | 630 | function string.ltrim(input) |
| 570 | return string.gsub(input, "^[ \t\n\r]+", "") | 631 | return string_gsub(input, "^[ \t\n\r]+", "") |
| 571 | end | 632 | end |
| 572 | 633 | ||
| 573 | function string.rtrim(input) | 634 | function string.rtrim(input) |
| 574 | return string.gsub(input, "[ \t\n\r]+$", "") | 635 | return string_gsub(input, "[ \t\n\r]+$", "") |
| 575 | end | 636 | end |
| 576 | 637 | ||
| 577 | function string.trim(input) | 638 | function string.trim(input) |
| 578 | input = string.gsub(input, "^[ \t\n\r]+", "") | 639 | input = string_gsub(input, "^[ \t\n\r]+", "") |
| 579 | return string.gsub(input, "[ \t\n\r]+$", "") | 640 | return string_gsub(input, "[ \t\n\r]+$", "") |
| 580 | end | 641 | end |
| 581 | 642 | ||
| 582 | function string.ucfirst(input) | 643 | function string.ucfirst(input) |
| 583 | return string.upper(string.sub(input, 1, 1)) .. string.sub(input, 2) | 644 | return string_upper(string_sub(input, 1, 1)) .. string_sub(input, 2) |
| 584 | end | 645 | end |
| 585 | 646 | ||
| 586 | local function urlencodechar(char) | 647 | local function urlencodechar(char) |
| 587 | return "%" .. string.format("%02X", string.byte(char)) | 648 | return "%" .. table_format("%02X", string_byte(char)) |
| 588 | end | 649 | end |
| 589 | function string.urlencode(input) | 650 | function string.urlencode(input) |
| 590 | -- convert line endings | 651 | input = string_gsub(tostring(input), "\n", "\r\n") |
| 591 | input = string.gsub(tostring(input), "\n", "\r\n") | 652 | input = string_gsub(input, "([^%w%.%- ])", urlencodechar) |
| 592 | -- escape all characters but alphanumeric, '.' and '-' | 653 | return string_gsub(input, " ", "+") |
| 593 | input = string.gsub(input, "([^%w%.%- ])", urlencodechar) | ||
| 594 | -- convert spaces to "+" symbols | ||
| 595 | return string.gsub(input, " ", "+") | ||
| 596 | end | 654 | end |
| 597 | 655 | ||
| 656 | local _checknumber = checknumber | ||
| 598 | function string.urldecode(input) | 657 | function string.urldecode(input) |
| 599 | input = string.gsub (input, "+", " ") | 658 | input = string_gsub (input, "+", " ") |
| 600 | input = string.gsub (input, "%%(%x%x)", function(h) return string.char(checknumber(h,16)) end) | 659 | input = string_gsub (input, "%%(%x%x)", function(h) return string_char(_checknumber(h, 16)) end) |
| 601 | input = string.gsub (input, "\r\n", "\n") | 660 | input = string_gsub (input, "\r\n", "\n") |
| 602 | return input | 661 | return input |
| 603 | end | 662 | end |
| 604 | 663 | ||
| 605 | function string.utf8len(input) | 664 | function string.utf8len(input) |
| 606 | local len = string.len(input) | 665 | local len = string_len(input) |
| 607 | local left = len | 666 | local left = len |
| 608 | local cnt = 0 | 667 | local cnt = 0 |
| 609 | local arr = {0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc} | 668 | local arr = {0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc} |
| 610 | while left ~= 0 do | 669 | while left ~= 0 do |
| 611 | local tmp = string.byte(input, -left) | 670 | local tmp = string_byte(input, -left) |
| 612 | local i = #arr | 671 | local i = #arr |
| 613 | while arr[i] do | 672 | while arr[i] do |
| 614 | if tmp >= arr[i] then | 673 | if tmp >= arr[i] then |
| ... | @@ -626,7 +685,7 @@ function string.formatnumberthousands(num) | ... | @@ -626,7 +685,7 @@ function string.formatnumberthousands(num) |
| 626 | local formatted = tostring(checknumber(num)) | 685 | local formatted = tostring(checknumber(num)) |
| 627 | local k | 686 | local k |
| 628 | while true do | 687 | while true do |
| 629 | formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') | 688 | formatted, k = string_gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') |
| 630 | if k == 0 then break end | 689 | if k == 0 then break end |
| 631 | end | 690 | end |
| 632 | return formatted | 691 | return formatted | ... | ... |
| ... | @@ -26,7 +26,6 @@ local display = {} | ... | @@ -26,7 +26,6 @@ local display = {} |
| 26 | 26 | ||
| 27 | local director = cc.Director:getInstance() | 27 | local director = cc.Director:getInstance() |
| 28 | local view = director:getOpenGLView() | 28 | local view = director:getOpenGLView() |
| 29 | |||
| 30 | if not view then | 29 | if not view then |
| 31 | local width = 960 | 30 | local width = 960 |
| 32 | local height = 640 | 31 | local height = 640 | ... | ... |
| ... | @@ -43,7 +43,7 @@ function Layer:onTouch(callback, isMultiTouches, swallowTouches) | ... | @@ -43,7 +43,7 @@ function Layer:onTouch(callback, isMultiTouches, swallowTouches) |
| 43 | event.x = args[1] | 43 | event.x = args[1] |
| 44 | event.y = args[2] | 44 | event.y = args[2] |
| 45 | end | 45 | end |
| 46 | return callback( event ) | 46 | callback(event) |
| 47 | end, isMultiTouches, 0, swallowTouches) | 47 | end, isMultiTouches, 0, swallowTouches) |
| 48 | self:setTouchEnabled(true) | 48 | self:setTouchEnabled(true) |
| 49 | return self | 49 | return self | ... | ... |
| ... | @@ -40,14 +40,14 @@ require("cocos.framework.extends.LayerEx") | ... | @@ -40,14 +40,14 @@ require("cocos.framework.extends.LayerEx") |
| 40 | require("cocos.framework.extends.MenuEx") | 40 | require("cocos.framework.extends.MenuEx") |
| 41 | 41 | ||
| 42 | if ccui then | 42 | if ccui then |
| 43 | require("cocos.framework.extends.UIWidget") | 43 | require("cocos.framework.extends.UIWidget") |
| 44 | require("cocos.framework.extends.UICheckBox") | 44 | require("cocos.framework.extends.UICheckBox") |
| 45 | require("cocos.framework.extends.UIEditBox") | 45 | require("cocos.framework.extends.UIEditBox") |
| 46 | require("cocos.framework.extends.UIListView") | 46 | require("cocos.framework.extends.UIListView") |
| 47 | require("cocos.framework.extends.UIPageView") | 47 | require("cocos.framework.extends.UIPageView") |
| 48 | require("cocos.framework.extends.UIScrollView") | 48 | require("cocos.framework.extends.UIScrollView") |
| 49 | require("cocos.framework.extends.UISlider") | 49 | require("cocos.framework.extends.UISlider") |
| 50 | require("cocos.framework.extends.UITextField") | 50 | require("cocos.framework.extends.UITextField") |
| 51 | end | 51 | end |
| 52 | 52 | ||
| 53 | require("cocos.framework.package_support") | 53 | require("cocos.framework.package_support") | ... | ... |
| 1 | --[[ | 1 | --[[ |
| 2 | 2 | ||
| 3 | Copyright (c) 2011-2015 chukong-incc.com | 3 | Copyright (c) 2011-2015 chukong-inc.com |
| 4 | 4 | ||
| 5 | Permission is hereby granted, free of charge, to any person obtaining a copy | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | of this software and associated documentation files (the "Software"), to deal | 6 | of this software and associated documentation files (the "Software"), to deal |
| ... | @@ -22,7 +22,11 @@ THE SOFTWARE. | ... | @@ -22,7 +22,11 @@ THE SOFTWARE. |
| 22 | 22 | ||
| 23 | ]] | 23 | ]] |
| 24 | 24 | ||
| 25 | -- Cocos2d-Lua core functions | 25 | local assert = assert |
| 26 | local type = type | ||
| 27 | local ipairs = ipairs | ||
| 28 | local string_format = string.format | ||
| 29 | |||
| 26 | cc.loaded_packages = {} | 30 | cc.loaded_packages = {} |
| 27 | local loaded_packages = cc.loaded_packages | 31 | local loaded_packages = cc.loaded_packages |
| 28 | 32 | ||
| ... | @@ -36,11 +40,11 @@ function cc.load(...) | ... | @@ -36,11 +40,11 @@ function cc.load(...) |
| 36 | 40 | ||
| 37 | local packages = {} | 41 | local packages = {} |
| 38 | for _, name in ipairs(names) do | 42 | for _, name in ipairs(names) do |
| 39 | assert(type(name) == "string", string.format("cc.load() - invalid package name \"%s\"", tostring(name))) | 43 | assert(type(name) == "string", string_format("cc.load() - invalid package name \"%s\"", tostring(name))) |
| 40 | if not loaded_packages[name] then | 44 | if not loaded_packages[name] then |
| 41 | local packageName = string.format("packages.%s.init", name) | 45 | local packageName = string_format("packages.%s.init", name) |
| 42 | local cls = require(packageName) | 46 | local cls = require(packageName) |
| 43 | assert(cls, string.format("cc.load() - package class \"%s\" load failed", packageName)) | 47 | assert(cls, string_format("cc.load() - package class \"%s\" load failed", packageName)) |
| 44 | loaded_packages[name] = cls | 48 | loaded_packages[name] = cls |
| 45 | 49 | ||
| 46 | if DEBUG > 1 then | 50 | if DEBUG > 1 then |
| ... | @@ -56,14 +60,14 @@ local load_ = cc.load | ... | @@ -56,14 +60,14 @@ local load_ = cc.load |
| 56 | local bind_ | 60 | local bind_ |
| 57 | bind_ = function(target, ...) | 61 | bind_ = function(target, ...) |
| 58 | local t = type(target) | 62 | local t = type(target) |
| 59 | assert(t == "table" or t == "userdata", string.format("cc.bind() - invalid target, expected is object, actual is %s", t)) | 63 | assert(t == "table" or t == "userdata", string_format("cc.bind() - invalid target, expected is object, actual is %s", t)) |
| 60 | local names = {...} | 64 | local names = {...} |
| 61 | assert(#names > 0, "cc.bind() - package names expected") | 65 | assert(#names > 0, "cc.bind() - package names expected") |
| 62 | 66 | ||
| 63 | load_(...) | 67 | load_(...) |
| 64 | if not target.components_ then target.components_ = {} end | 68 | if not target.components_ then target.components_ = {} end |
| 65 | for _, name in ipairs(names) do | 69 | for _, name in ipairs(names) do |
| 66 | assert(type(name) == "string" and name ~= "", string.format("cc.bind() - invalid package name \"%s\"", name)) | 70 | assert(type(name) == "string" and name ~= "", string_format("cc.bind() - invalid package name \"%s\"", name)) |
| 67 | if not target.components_[name] then | 71 | if not target.components_[name] then |
| 68 | local cls = loaded_packages[name] | 72 | local cls = loaded_packages[name] |
| 69 | for __, depend in ipairs(cls.depends or {}) do | 73 | for __, depend in ipairs(cls.depends or {}) do |
| ... | @@ -88,9 +92,9 @@ function cc.unbind(target, ...) | ... | @@ -88,9 +92,9 @@ function cc.unbind(target, ...) |
| 88 | assert(#names > 0, "cc.unbind() - invalid package names") | 92 | assert(#names > 0, "cc.unbind() - invalid package names") |
| 89 | 93 | ||
| 90 | for _, name in ipairs(names) do | 94 | for _, name in ipairs(names) do |
| 91 | assert(type(name) == "string" and name ~= "", string.format("cc.unbind() - invalid package name \"%s\"", name)) | 95 | assert(type(name) == "string" and name ~= "", string_format("cc.unbind() - invalid package name \"%s\"", name)) |
| 92 | local component = target.components_[name] | 96 | local component = target.components_[name] |
| 93 | assert(component, string.format("cc.unbind() - component \"%s\" not found", tostring(name))) | 97 | assert(component, string_format("cc.unbind() - component \"%s\" not found", tostring(name))) |
| 94 | component:unbind(target) | 98 | component:unbind(target) |
| 95 | target.components_[name] = nil | 99 | target.components_[name] = nil |
| 96 | end | 100 | end | ... | ... |
| ... | @@ -28,7 +28,6 @@ require "cocos.cocos2d.functions" | ... | @@ -28,7 +28,6 @@ require "cocos.cocos2d.functions" |
| 28 | 28 | ||
| 29 | __G__TRACKBACK__ = function(msg) | 29 | __G__TRACKBACK__ = function(msg) |
| 30 | local msg = debug.traceback(msg, 3) | 30 | local msg = debug.traceback(msg, 3) |
| 31 | print(msg) | ||
| 32 | return msg | 31 | return msg |
| 33 | end | 32 | end |
| 34 | 33 | ||
| ... | @@ -101,9 +100,6 @@ end | ... | @@ -101,9 +100,6 @@ end |
| 101 | -- cocosbuilder | 100 | -- cocosbuilder |
| 102 | require "cocos.cocosbuilder.CCBReaderLoad" | 101 | require "cocos.cocosbuilder.CCBReaderLoad" |
| 103 | 102 | ||
| 104 | -- physics3d | ||
| 105 | require "cocos.physics3d.physics3d-constants" | ||
| 106 | |||
| 107 | if CC_USE_FRAMEWORK then | 103 | if CC_USE_FRAMEWORK then |
| 108 | require "cocos.framework.init" | 104 | require "cocos.framework.init" |
| 109 | end | 105 | end | ... | ... |
| 1 | if nil == cc.Physics3DComponent then | ||
| 2 | return | ||
| 3 | end | ||
| 4 | |||
| 5 | cc.Physics3DComponent.PhysicsSyncFlag = | ||
| 6 | { | ||
| 7 | NONE = 0, | ||
| 8 | NODE_TO_PHYSICS = 1, | ||
| 9 | PHYSICS_TO_NODE = 2, | ||
| 10 | NODE_AND_NODE = 3, | ||
| 11 | } | ||
| 12 | |||
| 13 | cc.Physics3DObject.PhysicsObjType = | ||
| 14 | { | ||
| 15 | UNKNOWN = 0, | ||
| 16 | RIGID_BODY = 1, | ||
| 17 | } | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -40,17 +40,6 @@ ccui.CheckBoxEventType = | ... | @@ -40,17 +40,6 @@ ccui.CheckBoxEventType = |
| 40 | unselected = 1, | 40 | unselected = 1, |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | ccui.RadioButtonEventType= | ||
| 44 | { | ||
| 45 | selected = 0, | ||
| 46 | unselected = 1 | ||
| 47 | } | ||
| 48 | |||
| 49 | ccui.RadioButtonGroupEventType= | ||
| 50 | { | ||
| 51 | select_changed = 0 | ||
| 52 | } | ||
| 53 | |||
| 54 | ccui.TextFiledEventType = | 43 | ccui.TextFiledEventType = |
| 55 | { | 44 | { |
| 56 | attach_with_ime = 0, | 45 | attach_with_ime = 0, |
| ... | @@ -118,12 +107,7 @@ ccui.RelativeAlign = | ... | @@ -118,12 +107,7 @@ ccui.RelativeAlign = |
| 118 | locationBelowRightAlign = 21, | 107 | locationBelowRightAlign = 21, |
| 119 | } | 108 | } |
| 120 | 109 | ||
| 121 | ccui.SliderEventType = { | 110 | ccui.SliderEventType = {percentChanged = 0} |
| 122 | percentChanged = 0, | ||
| 123 | slideBallDown = 1, | ||
| 124 | slideBallUp = 2, | ||
| 125 | slideBallCancel = 3 | ||
| 126 | } | ||
| 127 | 111 | ||
| 128 | ccui.LoadingBarDirection = { LEFT = 0, RIGHT = 1} | 112 | ccui.LoadingBarDirection = { LEFT = 0, RIGHT = 1} |
| 129 | 113 | ||
| ... | @@ -177,16 +161,9 @@ ccui.PageViewEventType = { | ... | @@ -177,16 +161,9 @@ ccui.PageViewEventType = { |
| 177 | turning = 0, | 161 | turning = 0, |
| 178 | } | 162 | } |
| 179 | 163 | ||
| 180 | ccui.PageViewDirection = { | ||
| 181 | HORIZONTAL = 0, | ||
| 182 | VERTICAL = 1 | ||
| 183 | } | ||
| 184 | |||
| 185 | ccui.PVTouchDir = { | 164 | ccui.PVTouchDir = { |
| 186 | touchLeft = 0, | 165 | touchLeft = 0, |
| 187 | touchRight = 1, | 166 | touchRight = 1, |
| 188 | touchUp = 2, | ||
| 189 | touchDown = 3 | ||
| 190 | } | 167 | } |
| 191 | 168 | ||
| 192 | ccui.ListViewGravity = { | 169 | ccui.ListViewGravity = { | ... | ... |
| 1 | 1 | ||
| 2 | -- 0 - disable debug info, 1 - less debug info, 2 - verbose debug info | 2 | -- 0 - disable debug info, 1 - less debug info, 2 - verbose debug info |
| 3 | DEBUG = 2 | 3 | DEBUG = 0; |
| 4 | |||
| 5 | WX_APP_ID = "wxf00b7194cb71998e"; | ||
| 6 | WX_APP_SECRET = "f882ac5b09bc7f89134e769e7fa7cc44"; | ||
| 7 | |||
| 8 | WX_APP_ID_WEB = "wxb9e0a36f1ff6a9ea"; | ||
| 9 | WX_APP_SECRET_WEB = "ed8e9df1bfbd08ae4a252b5956872698"; | ||
| 10 | |||
| 11 | CHANNEL = "cmcc"; | ||
| 12 | CDN_CONFIG_URL = ""; | ||
| 13 | GAME_LOGIN_URL = nil; | ||
| 14 | PROXY_HTTP_ADDR = nil; | ||
| 15 | PROXY_SOCK_ADDR = nil; | ||
| 16 | IS_TV = 1; | ||
| 17 | |||
| 18 | PAY_URL = "http://101.132.118.17"; | ||
| 19 | PAY_ID_SHDX = "ag8ai9483516"; | ||
| 20 | PAY_PRICE_SHDX = 5; | ||
| 21 | SHARE_URL = "https://fir.im/qjqp2018"; | ||
| 22 | INVITE_URL = "https://fir.im/qjqp2018"; | ||
| 23 | |||
| 24 | PLATFORM = 1; | ||
| 25 | GAME_ID = 5; | ||
| 26 | TIMEOUT = 500; | ||
| 27 | |||
| 28 | SCALE_POKER_NORMAL = 1.3; --普通牌显示的缩放值 | ||
| 29 | SCALE_POKER_SHOT = 0.8; --出牌显示的缩放值 | ||
| 30 | |||
| 31 | SCALE_MJ_NORMAL = 1; --普通牌显示的缩放值 | ||
| 4 | 32 | ||
| 5 | -- use framework, will disable all deprecated API, false - use legacy API | 33 | -- use framework, will disable all deprecated API, false - use legacy API |
| 6 | CC_USE_FRAMEWORK = true | 34 | CC_USE_FRAMEWORK = true |
| 7 | 35 | ||
| 8 | -- show FPS on screen | 36 | -- show FPS on screen |
| 9 | CC_SHOW_FPS = true | 37 | CC_SHOW_FPS = false |
| 10 | 38 | ||
| 11 | -- disable create unexpected global variable | 39 | -- disable create unexpected global variable |
| 12 | CC_DISABLE_GLOBAL = true | 40 | CC_DISABLE_GLOBAL = false |
| 13 | 41 | ||
| 14 | -- for module display | 42 | -- for module display |
| 15 | CC_DESIGN_RESOLUTION = { | 43 | CC_DESIGN_RESOLUTION = { |
| 16 | width = 960, | 44 | width = 1280, |
| 17 | height = 640, | 45 | height = 720, |
| 18 | autoscale = "SHOW_ALL", | 46 | autoscale = "FIXED_HEIGHT", |
| 19 | callback = function(framesize) | 47 | callback = function(framesize) |
| 20 | local ratio = framesize.width / framesize.height | 48 | local ratio = framesize.width / framesize.height |
| 21 | if ratio <= 1.34 then | 49 | if ratio <= 1.34 then |
| 22 | -- iPad 768*1024(1536*2048) is 4:3 screen | 50 | -- iPad 768*1024(1536*2048) is 4:3 screen |
| 23 | return {autoscale = "SHOW_ALL"} | 51 | return {autoscale = "FIXED_HEIGHT"} |
| 24 | end | 52 | end |
| 25 | end | 53 | end |
| 26 | } | 54 | } | ... | ... |
| 1 | cc.exports.Bezier = {} | ||
| 2 | |||
| 3 | --起点,控制点,终点,分割份数 | ||
| 4 | local p0,p1,p2,step; | ||
| 5 | |||
| 6 | local ax,ay,bx,by,A,B,C,_total_length; | ||
| 7 | |||
| 8 | -- 速度函数 | ||
| 9 | local function s(t) | ||
| 10 | return math.sqrt(A * t * t + B * t + C); | ||
| 11 | end | ||
| 12 | |||
| 13 | -- 长度函数 | ||
| 14 | local function L(t) | ||
| 15 | local temp1 = math.sqrt(C + t * (B + A * t)); | ||
| 16 | local temp2 = (2 * A * t * temp1 + B *(temp1 - math.sqrt(C))); | ||
| 17 | local temp3 = math.log(B + 2 * math.sqrt(A) * math.sqrt(C)); | ||
| 18 | local temp4 = math.log(B + 2 * A * t + 2 * math.sqrt(A) * temp1); | ||
| 19 | local temp5 = 2 * math.sqrt(A) * temp2; | ||
| 20 | local temp6 = (B * B - 4 * A * C) * (temp3 - temp4); | ||
| 21 | |||
| 22 | return (temp5 + temp6) / (8 * math.pow(A, 1.5)); | ||
| 23 | end | ||
| 24 | |||
| 25 | -- 长度函数反函数,使用牛顿切线法求解 | ||
| 26 | local function InvertL(t, l) | ||
| 27 | local t1 = t; | ||
| 28 | local t2; | ||
| 29 | while(true) | ||
| 30 | do | ||
| 31 | local _s = s(t1); | ||
| 32 | t2 = t1 - (L(t1) - l)/_s; | ||
| 33 | if (math.abs(t1-t2) < 0.000001 or t1==nil or t2==nil) then | ||
| 34 | break; | ||
| 35 | end | ||
| 36 | t1 = t2; | ||
| 37 | end | ||
| 38 | return t2; | ||
| 39 | end | ||
| 40 | |||
| 41 | -- 返回所需总步数 | ||
| 42 | function Bezier:init(_p0, _p1, _p2, _speed) | ||
| 43 | p0 = _p0; | ||
| 44 | p1 = _p1; | ||
| 45 | p2 = _p2; | ||
| 46 | |||
| 47 | ax = p0.x - 2 * p1.x + p2.x; | ||
| 48 | ay = p0.y - 2 * p1.y + p2.y; | ||
| 49 | bx = 2 * p1.x - 2 * p0.x; | ||
| 50 | by = 2 * p1.y - 2 * p0.y; | ||
| 51 | |||
| 52 | A = 4*(ax * ax + ay * ay); | ||
| 53 | B = 4*(ax * bx + ay * by); | ||
| 54 | C = bx * bx + by * by; | ||
| 55 | |||
| 56 | -- 计算长度 | ||
| 57 | _total_length = L(1); | ||
| 58 | |||
| 59 | -- 计算步数 | ||
| 60 | step = math.floor(_total_length / _speed); | ||
| 61 | if (_total_length % _speed > _speed / 2) then | ||
| 62 | step = step+1; | ||
| 63 | end | ||
| 64 | |||
| 65 | -- print("曲长:" + total_length); | ||
| 66 | -- print("步数:" + step); | ||
| 67 | return step; | ||
| 68 | end | ||
| 69 | |||
| 70 | |||
| 71 | -- 根据指定nIndex位置获取锚点:返回坐标和角度 | ||
| 72 | function Bezier:getAnchorPoint(nIndex) | ||
| 73 | if (nIndex >= 0 and nIndex <= step) then | ||
| 74 | local t = nIndex/step | ||
| 75 | -- 如果按照线行增长,此时对应的曲线长度 | ||
| 76 | local l = t*_total_length | ||
| 77 | -- 根据L函数的反函数,求得l对应的t值 | ||
| 78 | t = InvertL(t, l); | ||
| 79 | |||
| 80 | -- 根据贝塞尔曲线函数,求得取得此时的x,y坐标 | ||
| 81 | local xx = (1 - t) * (1 - t) * p0.x + 2 * (1 - t) * t * p1.x + t * t * p2.x; | ||
| 82 | local yy = (1 - t) * (1 - t) * p0.y + 2 * (1 - t) * t * p1.y + t * t * p2.y; | ||
| 83 | |||
| 84 | return Point.new(xx,yy); | ||
| 85 | -- // 获取切线 | ||
| 86 | -- var Q0:Point = new Point((1 - t) * p0.x + t * p1.x, (1 - t) * p0.y + t * p1.y); | ||
| 87 | -- var Q1:Point = new Point((1 - t) * p1.x + t * p2.x, (1 - t) * p1.y + t * p2.y); | ||
| 88 | -- | ||
| 89 | -- // 计算角度 | ||
| 90 | -- var dx:Number = Q1.x - Q0.x; | ||
| 91 | -- var dy:Number = Q1.y - Q0.y; | ||
| 92 | -- var radians:Number = math.atan2(dy, dx); | ||
| 93 | -- var degrees:Number = radians * 180 / math.PI; | ||
| 94 | -- return new Array(xx, yy, degrees); | ||
| 95 | else | ||
| 96 | return Point.new(); | ||
| 97 | end | ||
| 98 | end | ||
| 99 | |||
| 100 | function Bezier:total_length() | ||
| 101 | return _total_length; | ||
| 102 | end | ||
| 103 | |||
| 104 | return Bezier | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | cc.exports.Line = class("Line") | ||
| 2 | |||
| 3 | function Line:ctor(startPoint, endPoint) | ||
| 4 | self.startPoint = startPoint; | ||
| 5 | self.endPoint = endPoint; | ||
| 6 | return self | ||
| 7 | end | ||
| 8 | function Line:getAngle() | ||
| 9 | return math.atan2(self.endPoint.y - self.startPoint.y, self.endPoint.x - self.startPoint.x); | ||
| 10 | end | ||
| 11 | |||
| 12 | local function distance(p1,p2) | ||
| 13 | local dx = math.abs(p2.x - p1.x); | ||
| 14 | local dy = math.abs(p2.y - p1.y); | ||
| 15 | return math.sqrt(dx * dx + dy * dy) | ||
| 16 | end | ||
| 17 | -- /** | ||
| 18 | -- * 获得线的长度 | ||
| 19 | -- * @return | ||
| 20 | -- */ | ||
| 21 | function Line:getLength() | ||
| 22 | return Point.distance(self.startPoint, self.endPoint); | ||
| 23 | end | ||
| 24 | |||
| 25 | -- /** | ||
| 26 | -- * 根据步长获取直线上平均分布的点 | ||
| 27 | -- * @return | ||
| 28 | -- */ | ||
| 29 | function Line:getSegmentPointsByStep(_step) | ||
| 30 | local _time = self:getLength()/_step; | ||
| 31 | local _arr = {}; | ||
| 32 | for i=1,_time do | ||
| 33 | local _p = self:getPoint(i/_time); | ||
| 34 | _arr[#_arr+1] = _p; | ||
| 35 | end | ||
| 36 | return _arr; | ||
| 37 | end | ||
| 38 | -- /** | ||
| 39 | -- * 按比例获得线上某点的坐标 | ||
| 40 | -- * @param time 在线上的比例位置 | ||
| 41 | -- **/ | ||
| 42 | function Line:getPoint(time) | ||
| 43 | local point = {}; | ||
| 44 | point.x = self.startPoint.x + (self.endPoint.x - self.startPoint.x)*time; | ||
| 45 | point.y = self.startPoint.y + (self.endPoint.y - self.startPoint.y)*time; | ||
| 46 | return point; | ||
| 47 | end | ||
| 48 | return Line | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | cc.exports.Point = {} | ||
| 2 | |||
| 3 | function Point.new(x, y) | ||
| 4 | x=x or 0 | ||
| 5 | y=y or 0 | ||
| 6 | local this = {} | ||
| 7 | this.x= x; | ||
| 8 | this.y= y; | ||
| 9 | |||
| 10 | return this | ||
| 11 | end | ||
| 12 | |||
| 13 | function Point.distance(p1,p2) | ||
| 14 | local dx = math.abs(p2.x - p1.x); | ||
| 15 | local dy = math.abs(p2.y - p1.y); | ||
| 16 | return math.sqrt(dx * dx + dy * dy) | ||
| 17 | end | ||
| 18 | |||
| 19 | return Point | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | cc.exports.UmengHelper = class("UmengHelper") -- 构建lua 类 | ||
| 2 | |||
| 3 | --调用安卓方法 | ||
| 4 | local function callAndroidFun(funName,params,callBack) | ||
| 5 | local luaj = require "cocos.cocos2d.luaj" --引入luaj | ||
| 6 | --包名/类名 这个可以在对应的android工程的manifest中得到 | ||
| 7 | local className="org/cocos2dx/lua/UmengSDK"; | ||
| 8 | local args = { params,callBack}; | ||
| 9 | local sigs = "(Ljava/lang/String;I)V" --传入string参数,无返回值 | ||
| 10 | |||
| 11 | --luaj 调用 Java 方法时,可能会出现各种错误,因此 luaj 提供了一种机制让 Lua 调用代码可以确定 Java 方法是否成功调用。 | ||
| 12 | --luaj.callStaticMethod() 会返回两个值 | ||
| 13 | --当成功时,第一个值为 true,第二个值是 Java 方法的返回值(如果有) | ||
| 14 | --当失败时,第一个值为 false,第二个值是错误代码 | ||
| 15 | local ok,ret = luaj.callStaticMethod(className,funName,args,sigs) | ||
| 16 | if not ok then | ||
| 17 | print("umeng "..funName.." error:"..ret) | ||
| 18 | end | ||
| 19 | end | ||
| 20 | |||
| 21 | --调用IOS方法 | ||
| 22 | local function callIosFun(funName,params,callBack) | ||
| 23 | |||
| 24 | end | ||
| 25 | |||
| 26 | function UmengHelper.onProfileSignIn(params,callBack) | ||
| 27 | local targetPlatform = cc.Application:getInstance():getTargetPlatform() | ||
| 28 | if targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 29 | callAndroidFun("onProfileSignIn",params,callBack); | ||
| 30 | elseif targetPlatform == cc.PLATFORM_OS_IPHONE or targetPlatform == cc.PLATFORM_OS_IPAD then | ||
| 31 | callIosFun("onProfileSignIn",params,callBack); | ||
| 32 | end | ||
| 33 | end | ||
| 34 | |||
| 35 | function UmengHelper.onProfileSignOff(params,callBack) | ||
| 36 | local targetPlatform = cc.Application:getInstance():getTargetPlatform() | ||
| 37 | if targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 38 | callAndroidFun("onProfileSignOff",params,callBack); | ||
| 39 | elseif targetPlatform == cc.PLATFORM_OS_IPHONE or targetPlatform == cc.PLATFORM_OS_IPAD then | ||
| 40 | callIosFun("onProfileSignOff",params,callBack); | ||
| 41 | end | ||
| 42 | end | ||
| 43 | |||
| 44 | --调用原生的方法实现 | ||
| 45 | function UmengHelper.startLevel(params,callBack) | ||
| 46 | local targetPlatform = cc.Application:getInstance():getTargetPlatform() | ||
| 47 | if targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 48 | callAndroidFun("startLevel",params,callBack); | ||
| 49 | elseif targetPlatform == cc.PLATFORM_OS_IPHONE or targetPlatform == cc.PLATFORM_OS_IPAD then | ||
| 50 | callIosFun("startLevel",params,callBack); | ||
| 51 | end | ||
| 52 | end | ||
| 53 | |||
| 54 | --调用原生的方法实现 | ||
| 55 | function UmengHelper.failLevel(params,callBack) | ||
| 56 | local targetPlatform = cc.Application:getInstance():getTargetPlatform() | ||
| 57 | if targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 58 | callAndroidFun("failLevel",params,callBack); | ||
| 59 | elseif targetPlatform == cc.PLATFORM_OS_IPHONE or targetPlatform == cc.PLATFORM_OS_IPAD then | ||
| 60 | callIosFun("failLevel",params,callBack); | ||
| 61 | end | ||
| 62 | end | ||
| 63 | |||
| 64 | --调用原生的方法实现 | ||
| 65 | function UmengHelper.finishLevel(params,callBack) | ||
| 66 | local targetPlatform = cc.Application:getInstance():getTargetPlatform() | ||
| 67 | if targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 68 | callAndroidFun("finishLevel",params,callBack); | ||
| 69 | elseif targetPlatform == cc.PLATFORM_OS_IPHONE or targetPlatform == cc.PLATFORM_OS_IPAD then | ||
| 70 | callIosFun("finishLevel",params,callBack); | ||
| 71 | end | ||
| 72 | end | ||
| 73 | |||
| 74 | --调用原生的方法实现 | ||
| 75 | function UmengHelper.pay(params,callBack) | ||
| 76 | local targetPlatform = cc.Application:getInstance():getTargetPlatform() | ||
| 77 | if targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 78 | callAndroidFun("pay",params,callBack); | ||
| 79 | elseif targetPlatform == cc.PLATFORM_OS_IPHONE or targetPlatform == cc.PLATFORM_OS_IPAD then | ||
| 80 | callIosFun("pay",params,callBack); | ||
| 81 | end | ||
| 82 | end | ||
| 83 | |||
| 84 | --调用原生的方法实现 | ||
| 85 | function UmengHelper.buy(params,callBack) | ||
| 86 | local targetPlatform = cc.Application:getInstance():getTargetPlatform() | ||
| 87 | if targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 88 | callAndroidFun("buy",params,callBack); | ||
| 89 | elseif targetPlatform == cc.PLATFORM_OS_IPHONE or targetPlatform == cc.PLATFORM_OS_IPAD then | ||
| 90 | callIosFun("buy",params,callBack); | ||
| 91 | end | ||
| 92 | end | ||
| 93 | |||
| 94 | --调用原生的方法实现 | ||
| 95 | function UmengHelper.use(params,callBack) | ||
| 96 | local targetPlatform = cc.Application:getInstance():getTargetPlatform() | ||
| 97 | if targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 98 | callAndroidFun("use",params,callBack); | ||
| 99 | elseif targetPlatform == cc.PLATFORM_OS_IPHONE or targetPlatform == cc.PLATFORM_OS_IPAD then | ||
| 100 | callIosFun("use",params,callBack); | ||
| 101 | end | ||
| 102 | end | ||
| 103 | |||
| 104 | --调用原生的方法实现 | ||
| 105 | function UmengHelper.bonus(params,callBack) | ||
| 106 | local targetPlatform = cc.Application:getInstance():getTargetPlatform() | ||
| 107 | if targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 108 | callAndroidFun("bonus",params,callBack); | ||
| 109 | elseif targetPlatform == cc.PLATFORM_OS_IPHONE or targetPlatform == cc.PLATFORM_OS_IPAD then | ||
| 110 | callIosFun("bonus",params,callBack); | ||
| 111 | end | ||
| 112 | end | ||
| 113 | |||
| 114 | --调用原生的方法实现 | ||
| 115 | function UmengHelper.onEvent(params,callBack) | ||
| 116 | local targetPlatform = cc.Application:getInstance():getTargetPlatform() | ||
| 117 | if targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 118 | callAndroidFun("onEvent",params,callBack); | ||
| 119 | elseif targetPlatform == cc.PLATFORM_OS_IPHONE or targetPlatform == cc.PLATFORM_OS_IPAD then | ||
| 120 | callIosFun("onEvent",params,callBack); | ||
| 121 | end | ||
| 122 | end | ||
| 123 | |||
| 124 | return UmengHelper | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
client/rubbish/client/src/core/log/color.lua
0 → 100644
| 1 | --[[ | ||
| 2 | @Author : Mr.wang | ||
| 3 | @Date : 2016-04-25 11:31:36 | ||
| 4 | @Content : 调用windows api设置控制台文本颜色 | ||
| 5 | --]] | ||
| 6 | |||
| 7 | local STD_INPUT_HANDLE= -10 | ||
| 8 | local STD_OUTPUT_HANDLE = -11 | ||
| 9 | local STD_ERROR_HANDLE = -12 | ||
| 10 | |||
| 11 | local FOREGROUND_BLACK = 0x00 | ||
| 12 | local FOREGROUND_BLUE = 0x01 -- text color contains blue. | ||
| 13 | local FOREGROUND_GREEN = 0x02 -- text color contains green. | ||
| 14 | local FOREGROUND_RED = 0x04 -- text color contains red. | ||
| 15 | local FOREGROUND_INTENSITY = 0x08 -- text color is intensified. | ||
| 16 | |||
| 17 | local BACKGROUND_BLUE = 0x10 -- background color contains blue. | ||
| 18 | local BACKGROUND_GREEN = 0x20 -- background color contains green. | ||
| 19 | local BACKGROUND_RED = 0x40 -- background color contains red. | ||
| 20 | local BACKGROUND_INTENSITY = 0x80 -- background color is intensified. | ||
| 21 | |||
| 22 | local ffi = require("ffi") | ||
| 23 | ffi.cdef[[ | ||
| 24 | typedef unsigned short WORD; | ||
| 25 | typedef unsigned long DWORD; | ||
| 26 | typedef unsigned int UINT; | ||
| 27 | typedef UINT HWND; | ||
| 28 | typedef void* HANDLE; | ||
| 29 | typedef int BOOL; | ||
| 30 | |||
| 31 | HANDLE GetStdHandle(DWORD nStdHandle); | ||
| 32 | BOOL SetConsoleTextAttribute(HANDLE hConsoleOutput, WORD wAttributes); | ||
| 33 | ]] | ||
| 34 | |||
| 35 | local kernel32 = ffi.load("Kernel32.dll") | ||
| 36 | local stdout = kernel32.GetStdHandle(STD_OUTPUT_HANDLE) | ||
| 37 | local bit = bit | ||
| 38 | |||
| 39 | local color = {} | ||
| 40 | setfenv(1, color) | ||
| 41 | |||
| 42 | RED = bit.bor(FOREGROUND_RED, FOREGROUND_INTENSITY) | ||
| 43 | BLUE = bit.bor(FOREGROUND_BLUE, FOREGROUND_INTENSITY) | ||
| 44 | GREEN = bit.bor(FOREGROUND_GREEN, FOREGROUND_INTENSITY) | ||
| 45 | PURPLE = bit.bor(FOREGROUND_RED, FOREGROUND_BLUE, FOREGROUND_INTENSITY) | ||
| 46 | YELLOW = bit.bor(FOREGROUND_RED, FOREGROUND_GREEN, FOREGROUND_INTENSITY) | ||
| 47 | DEFAULT_COLOR = bit.bor(FOREGROUND_RED, FOREGROUND_GREEN, FOREGROUND_BLUE) | ||
| 48 | |||
| 49 | function setColor(color) | ||
| 50 | kernel32.SetConsoleTextAttribute(stdout, color) | ||
| 51 | end | ||
| 52 | |||
| 53 | return color | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | --[[ | ||
| 2 | @Author : Mr.wang | ||
| 3 | @Date : 2016-04-25 09:25:06 | ||
| 4 | @Content : helper | ||
| 5 | --]] | ||
| 6 | |||
| 7 | local cc = cc | ||
| 8 | local _tostring = tostring | ||
| 9 | local type, tonumber, table, string = type, tonumber, table, string | ||
| 10 | |||
| 11 | local helper = {} | ||
| 12 | setfenv(1, helper) | ||
| 13 | |||
| 14 | function tostring(value) | ||
| 15 | local str = '' | ||
| 16 | |||
| 17 | if (type(value) ~= 'table') then | ||
| 18 | if (type(value) == 'string') then | ||
| 19 | str = string.format("%q", value) | ||
| 20 | else | ||
| 21 | str = _tostring(value) | ||
| 22 | end | ||
| 23 | else | ||
| 24 | local auxTable = {} | ||
| 25 | table.foreach(value, function(i, v) | ||
| 26 | if (tonumber(i) ~= i) then | ||
| 27 | table.insert(auxTable, i) | ||
| 28 | else | ||
| 29 | table.insert(auxTable, tostring(i)) | ||
| 30 | end | ||
| 31 | end) | ||
| 32 | table.sort(auxTable) | ||
| 33 | |||
| 34 | str = str..'{' | ||
| 35 | local separator = "" | ||
| 36 | local entry = "" | ||
| 37 | table.foreachi (auxTable, function (i, fieldName) | ||
| 38 | if ((tonumber(fieldName)) and (tonumber(fieldName) > 0)) then | ||
| 39 | entry = tostring(value[tonumber(fieldName)]) | ||
| 40 | else | ||
| 41 | entry = fieldName.." = "..tostring(value[fieldName]) | ||
| 42 | end | ||
| 43 | str = str..separator..entry | ||
| 44 | separator = ", " | ||
| 45 | end) | ||
| 46 | str = str..'}' | ||
| 47 | end | ||
| 48 | return str | ||
| 49 | end | ||
| 50 | |||
| 51 | function format(e) | ||
| 52 | if type(e) ~= "string" then | ||
| 53 | e = tostring(e) | ||
| 54 | end | ||
| 55 | return e | ||
| 56 | end | ||
| 57 | |||
| 58 | function isWindows() | ||
| 59 | local platform = cc.Application:getInstance():getTargetPlatform() | ||
| 60 | return platform == cc.PLATFORM_OS_WINDOWS | ||
| 61 | end | ||
| 62 | |||
| 63 | return helper | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
client/rubbish/client/src/core/log/init.lua
0 → 100644
| 1 | --[[ | ||
| 2 | @Author : Mr.wang | ||
| 3 | @Date : 2016-04-22 10:00:30 | ||
| 4 | @Content : | ||
| 5 | 根据"DEBUG"的值控制日志等级 | ||
| 6 | 0:NONE | ||
| 7 | 1:INFO | ||
| 8 | 2:DEBUG | ||
| 9 | 外部接口: | ||
| 10 | logD/logI/logW/logE | ||
| 11 | print = logI | ||
| 12 | --]] | ||
| 13 | if not socket then | ||
| 14 | require("socket") | ||
| 15 | end | ||
| 16 | |||
| 17 | local log = import(".log") | ||
| 18 | local helper = import(".helper") | ||
| 19 | |||
| 20 | local logout | ||
| 21 | local level | ||
| 22 | local print_ = print | ||
| 23 | |||
| 24 | -- 输出控制(等级、格式) | ||
| 25 | if 0 == DEBUG then | ||
| 26 | -- 不输出任何信息 | ||
| 27 | print("不输出任何信息") | ||
| 28 | logout = function() end | ||
| 29 | level = log.NONE | ||
| 30 | else | ||
| 31 | if 1 == DEBUG then | ||
| 32 | level = log.INFO | ||
| 33 | else | ||
| 34 | level = log.DEBUG | ||
| 35 | end | ||
| 36 | --[[ | ||
| 37 | 输出格式: | ||
| 38 | [14:00:02] warn | ||
| 39 | [14:00:02] error | ||
| 40 | --]] | ||
| 41 | logout = function(self, lv, ...) | ||
| 42 | local s, ms = unpack(string.split(tostring(socket.gettime()), ".")) | ||
| 43 | local time = os.date("%X", tonumber(s)) | ||
| 44 | -- local tag = string.format("[%s.%04d %5s] ", time, tonumber(ms or 0), lv) | ||
| 45 | local tag = string.format("[%s] ", time) | ||
| 46 | -- 输出信息处理 | ||
| 47 | local params = {...} | ||
| 48 | table.map(params, helper.format) | ||
| 49 | -- release版本的引擎也能写出来日志 | ||
| 50 | print_(tag.." "..table.concat(params, "\t")) | ||
| 51 | end | ||
| 52 | end | ||
| 53 | |||
| 54 | |||
| 55 | local logger = log.new(logout) | ||
| 56 | |||
| 57 | -- 导出方法 | ||
| 58 | |||
| 59 | if not helper.isWindows() then | ||
| 60 | _G.logD = handler(logger, logger.debug) | ||
| 61 | _G.logW = handler(logger, logger.warn) | ||
| 62 | _G.logE = handler(logger, logger.error) | ||
| 63 | else | ||
| 64 | --windows下设置控制台颜色 | ||
| 65 | local color = import(".color") | ||
| 66 | local setColor = color.setColor | ||
| 67 | local resetColor = function() setColor(color.DEFAULT_COLOR) end | ||
| 68 | -- debug:绿色 | ||
| 69 | _G.logD = function(...) | ||
| 70 | setColor(color.GREEN) | ||
| 71 | logger:debug(...) | ||
| 72 | resetColor() | ||
| 73 | end | ||
| 74 | -- warn:紫色 | ||
| 75 | _G.logW = function(...) | ||
| 76 | setColor(color.PURPLE) | ||
| 77 | logger:warn(...) | ||
| 78 | resetColor() | ||
| 79 | end | ||
| 80 | -- error:红色 | ||
| 81 | _G.logE = function(...) | ||
| 82 | setColor(color.RED) | ||
| 83 | logger:error(...) | ||
| 84 | resetColor() | ||
| 85 | end | ||
| 86 | end | ||
| 87 | |||
| 88 | _G.logI = handler(logger, logger.info) | ||
| 89 | --_G.print = logI | ||
| 90 | |||
| 91 | logD("debug") | ||
| 92 | logI("info") | ||
| 93 | logW("socket") | ||
| 94 | logE("error") | ||
| 95 | |||
| 96 | local label = cc.Label:create(); | ||
| 97 | --label:setFontSize(14); | ||
| 98 | label:setName("logUILable"); | ||
| 99 | label:retain(); | ||
| 100 | label:setColor(cc.c3b(255,0,0)); | ||
| 101 | label:setAnchorPoint(cc.p(0,1)); | ||
| 102 | label:setPosition(cc.p(5,display.height-25)); | ||
| 103 | local function checkLogUI() | ||
| 104 | if DEBUG == 0 then | ||
| 105 | return; | ||
| 106 | end | ||
| 107 | local runningScene = cc.Director:getInstance():getRunningScene(); | ||
| 108 | if runningScene and not runningScene:getChildByName("logUILable") then | ||
| 109 | runningScene:addChild(label,2000); | ||
| 110 | end | ||
| 111 | end; | ||
| 112 | cc.Director:getInstance():getScheduler():scheduleScriptFunc(checkLogUI, 1, false); | ||
| 113 | _G.logUI = function(str) | ||
| 114 | if DEBUG == 0 then | ||
| 115 | return; | ||
| 116 | end | ||
| 117 | label:setString(label:getString()..str.."\n"); | ||
| 118 | local runningScene = cc.Director:getInstance():getRunningScene(); | ||
| 119 | if runningScene and not runningScene:getChildByName("logUILable") then | ||
| 120 | runningScene:addChild(label,2000); | ||
| 121 | end | ||
| 122 | end | ||
| 123 | _G.clearLogUI = function() | ||
| 124 | label:setString(""); | ||
| 125 | local runningScene = cc.Director:getInstance():getRunningScene(); | ||
| 126 | if runningScene and not runningScene:getChildByName("logUILable") then | ||
| 127 | runningScene:addChild(label,2000); | ||
| 128 | end | ||
| 129 | end | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
client/rubbish/client/src/core/log/log.lua
0 → 100644
| 1 | --[[ | ||
| 2 | @Author : Mr.wang | ||
| 3 | @Date : 2016-04-21 16:01:17 | ||
| 4 | @Content : | ||
| 5 | 配置输出级别 | ||
| 6 | setLevel(log.xxx) | ||
| 7 | 传入输出流 | ||
| 8 | logout(self, lv, ...) | ||
| 9 | --]] | ||
| 10 | |||
| 11 | local log = setmetatable({}, {__index=_G}) | ||
| 12 | setfenv(1, log) | ||
| 13 | |||
| 14 | DEBUG = "DEBUG" | ||
| 15 | INFO = "INFO" | ||
| 16 | WARN = "WARN" | ||
| 17 | ERROR = "ERROR" | ||
| 18 | FATAL = "FATAL" | ||
| 19 | NONE = "NONE" | ||
| 20 | |||
| 21 | local LEVEL = { | ||
| 22 | [DEBUG] = 1, | ||
| 23 | [INFO] = 2, | ||
| 24 | [WARN] = 3, | ||
| 25 | [ERROR] = 4, | ||
| 26 | [FATAL] = 5, | ||
| 27 | [NONE] = 6, | ||
| 28 | } | ||
| 29 | |||
| 30 | local setLevel_ = function(self, lv) | ||
| 31 | assert(LEVEL[lv], string.format("undefined level '%s'", tostring(lv))) | ||
| 32 | self.level = lv | ||
| 33 | print("self.level:",self.level) | ||
| 34 | end | ||
| 35 | |||
| 36 | local log_ = function(self, lv, ...) | ||
| 37 | assert(LEVEL[lv], string.format("undefined level '%s'", tostring(lv))) | ||
| 38 | if LEVEL[lv] < LEVEL[self.level] then | ||
| 39 | return | ||
| 40 | end | ||
| 41 | self:logout(lv, ...) | ||
| 42 | end | ||
| 43 | |||
| 44 | function new(logout) | ||
| 45 | assert("function"==type(logout), "logout must be a function") | ||
| 46 | local logger = {level=DEBUG, setLevel=setLevel_, logout=logout} | ||
| 47 | |||
| 48 | logger.debug = function(self, ...) return log_(self, DEBUG, ...) end | ||
| 49 | logger.info = function(self, ...) return log_(self, INFO, ...) end | ||
| 50 | logger.warn = function(self, ...) return log_(self, WARN, ...) end | ||
| 51 | logger.error = function(self, ...) return log_(self, ERROR, ...) end | ||
| 52 | logger.fatal = function(self, ...) return log_(self, FATAL, ...) end | ||
| 53 | |||
| 54 | return logger | ||
| 55 | end | ||
| 56 | |||
| 57 | return log | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | --[[ | ||
| 2 | Http请求 | ||
| 3 | ]] | ||
| 4 | |||
| 5 | HttpRequest = class("HttpRequest") | ||
| 6 | |||
| 7 | function HttpRequest:getInstance() | ||
| 8 | if not HttpRequest._instance then | ||
| 9 | HttpRequest._instance = HttpRequest.new() | ||
| 10 | end | ||
| 11 | return HttpRequest._instance | ||
| 12 | end | ||
| 13 | |||
| 14 | function HttpRequest:post(url, params, success_callback, error_callback,response_type) | ||
| 15 | self:handleResponse("POST",url, params, success_callback, error_callback,response_type); | ||
| 16 | end | ||
| 17 | |||
| 18 | function HttpRequest:get(url, params, success_callback, error_callback,response_type) | ||
| 19 | self:handleResponse("GET",url, params, success_callback, error_callback,response_type); | ||
| 20 | end | ||
| 21 | |||
| 22 | function HttpRequest:handleResponse(type,url, params,success_callback, error_callback,response_type) | ||
| 23 | local xhr = cc.XMLHttpRequest:new(); | ||
| 24 | xhr.responseType = response_type or cc.XMLHTTPREQUEST_RESPONSE_JSON; | ||
| 25 | xhr:open(type, url); | ||
| 26 | print("HttpRequest:"..url); | ||
| 27 | xhr:setRequestHeader("Content-Type","application/json"); | ||
| 28 | -- xhr:setRequestHeader("Content-Type","application/x-www-form-urlencoded"); | ||
| 29 | |||
| 30 | -- local Authorization = "CtUserAuth AccessToken="..self.Accesstoken.."&UserID="..self.userPlugin:getUserID().."&AppID=1880671"; | ||
| 31 | -- xhr:setRequestHeader("Authorization",Authorization) -- 提交的参数 | ||
| 32 | |||
| 33 | local function onReadyStateChange() | ||
| 34 | if xhr.readyState == 4 and (xhr.status >= 200 and xhr.status < 207) then | ||
| 35 | print("HttpRequest RESPONSE:"..xhr.response); | ||
| 36 | if success_callback then | ||
| 37 | success_callback(xhr.response); | ||
| 38 | end | ||
| 39 | xhr:unregisterScriptHandler(); | ||
| 40 | else | ||
| 41 | if error_callback then | ||
| 42 | error_callback(); | ||
| 43 | end | ||
| 44 | print("xhr.readyState is:", xhr.readyState, "xhr.status is: ",xhr.status); | ||
| 45 | end | ||
| 46 | -- xhr:release(); | ||
| 47 | end | ||
| 48 | xhr:registerScriptHandler(onReadyStateChange); | ||
| 49 | if params and not TableUtil.isEmpty(params) then | ||
| 50 | paramsStr = json.encode(params); | ||
| 51 | print("HttpRequest PARAMS:"..paramsStr); | ||
| 52 | xhr:send(paramsStr); | ||
| 53 | else | ||
| 54 | xhr:send(); | ||
| 55 | end | ||
| 56 | end | ||
| 57 | |||
| 58 | function HttpRequest:getParamsStr(params) | ||
| 59 | local paramsStr = ""; | ||
| 60 | for i,v in pairs(params) do | ||
| 61 | paramsStr = paramsStr..i.."="..v.."&"; | ||
| 62 | end | ||
| 63 | paramsStr = string.sub(paramsStr,1,string.len(paramsStr)-1); | ||
| 64 | return paramsStr; | ||
| 65 | end | ||
| 66 | |||
| 67 | return HttpRequest | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | cc.exports.MyHttpRequest = class("MyHttpRequest") | ||
| 2 | |||
| 3 | local dkjson = require("core.net.dkjson"); | ||
| 4 | |||
| 5 | function MyHttpRequest:getInstance() | ||
| 6 | local myHttpRequest = _G.myHttpRequest | ||
| 7 | if myHttpRequest then | ||
| 8 | return myHttpRequest | ||
| 9 | end | ||
| 10 | |||
| 11 | myHttpRequest = MyHttpRequest.new() | ||
| 12 | cc.exports.myHttpRequest = myHttpRequest; | ||
| 13 | setmetatable(myHttpRequest, self); | ||
| 14 | self.__index = self; | ||
| 15 | return myHttpRequest; | ||
| 16 | end | ||
| 17 | |||
| 18 | function MyHttpRequest:ctor() | ||
| 19 | |||
| 20 | end | ||
| 21 | |||
| 22 | --Http请求 | ||
| 23 | function MyHttpRequest:request(type,uri,header,params,callBack) | ||
| 24 | local xhr = cc.XMLHttpRequest:new() | ||
| 25 | xhr.responseType = 4; | ||
| 26 | xhr:open(type, uri); | ||
| 27 | |||
| 28 | xhr:setRequestHeader("Content-Type","application/x-www-form-urlencoded") | ||
| 29 | local Authorization = "MyAuth "..header; | ||
| 30 | xhr:setRequestHeader("Authorization",Authorization) -- 提交的参数 | ||
| 31 | |||
| 32 | local function onReadyStateChange() | ||
| 33 | if xhr.readyState == 4 and (xhr.status >= 200 and xhr.status < 207) then | ||
| 34 | print("[MyHttpRequest].URI:"..uri); | ||
| 35 | print("[MyHttpRequest].response:"..xhr.response); | ||
| 36 | local obj = dkjson.decode(xhr.response); | ||
| 37 | if callBack then | ||
| 38 | callBack(obj); | ||
| 39 | end | ||
| 40 | else | ||
| 41 | print("xhr.readyState is:", xhr.readyState, "xhr.status is: ",xhr.status) | ||
| 42 | end | ||
| 43 | xhr:unregisterScriptHandler(); | ||
| 44 | end | ||
| 45 | xhr:registerScriptHandler(onReadyStateChange); | ||
| 46 | -- LuajUtil.luaPrint("MyHttpRequest Params:"..params,0); | ||
| 47 | if params ~= "" then | ||
| 48 | xhr:send(params); | ||
| 49 | else | ||
| 50 | xhr:send(); | ||
| 51 | end | ||
| 52 | end | ||
| 53 | |||
| 54 | return MyHttpRequest | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | -- Module options: | ||
| 2 | local always_try_using_lpeg = true | ||
| 3 | local register_global_module_table = false | ||
| 4 | local global_module_name = 'json' | ||
| 5 | |||
| 6 | --[==[ | ||
| 7 | |||
| 8 | David Kolf's JSON module for Lua 5.1/5.2 | ||
| 9 | |||
| 10 | Version 2.5 | ||
| 11 | |||
| 12 | |||
| 13 | For the documentation see the corresponding readme.txt or visit | ||
| 14 | <http://dkolf.de/src/dkjson-lua.fsl/>. | ||
| 15 | |||
| 16 | You can contact the author by sending an e-mail to 'david' at the | ||
| 17 | domain 'dkolf.de'. | ||
| 18 | |||
| 19 | |||
| 20 | Copyright (C) 2010-2013 David Heiko Kolf | ||
| 21 | |||
| 22 | Permission is hereby granted, free of charge, to any person obtaining | ||
| 23 | a copy of this software and associated documentation files (the | ||
| 24 | "Software"), to deal in the Software without restriction, including | ||
| 25 | without limitation the rights to use, copy, modify, merge, publish, | ||
| 26 | distribute, sublicense, and/or sell copies of the Software, and to | ||
| 27 | permit persons to whom the Software is furnished to do so, subject to | ||
| 28 | the following conditions: | ||
| 29 | |||
| 30 | The above copyright notice and this permission notice shall be | ||
| 31 | included in all copies or substantial portions of the Software. | ||
| 32 | |||
| 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| 34 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| 35 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
| 36 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
| 37 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
| 38 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 39 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| 40 | SOFTWARE. | ||
| 41 | |||
| 42 | --]==] | ||
| 43 | |||
| 44 | -- global dependencies: | ||
| 45 | local pairs, type, tostring, tonumber, getmetatable, setmetatable, rawset = | ||
| 46 | pairs, type, tostring, tonumber, getmetatable, setmetatable, rawset | ||
| 47 | local error, require, pcall, select = error, require, pcall, select | ||
| 48 | local floor, huge = math.floor, math.huge | ||
| 49 | local strrep, gsub, strsub, strbyte, strchar, strfind, strlen, strformat = | ||
| 50 | string.rep, string.gsub, string.sub, string.byte, string.char, | ||
| 51 | string.find, string.len, string.format | ||
| 52 | local strmatch = string.match | ||
| 53 | local concat = table.concat | ||
| 54 | |||
| 55 | local json = { version = "dkjson 2.5" } | ||
| 56 | |||
| 57 | if register_global_module_table then | ||
| 58 | _G[global_module_name] = json | ||
| 59 | end | ||
| 60 | |||
| 61 | local _ENV = nil -- blocking globals in Lua 5.2 | ||
| 62 | |||
| 63 | pcall (function() | ||
| 64 | -- Enable access to blocked metatables. | ||
| 65 | -- Don't worry, this module doesn't change anything in them. | ||
| 66 | local debmeta = require "debug".getmetatable | ||
| 67 | if debmeta then getmetatable = debmeta end | ||
| 68 | end) | ||
| 69 | |||
| 70 | json.null = setmetatable ({}, { | ||
| 71 | __tojson = function () return "null" end | ||
| 72 | }) | ||
| 73 | |||
| 74 | local function isarray (tbl) | ||
| 75 | local max, n, arraylen = 0, 0, 0 | ||
| 76 | for k,v in pairs (tbl) do | ||
| 77 | if k == 'n' and type(v) == 'number' then | ||
| 78 | arraylen = v | ||
| 79 | if v > max then | ||
| 80 | max = v | ||
| 81 | end | ||
| 82 | else | ||
| 83 | if type(k) ~= 'number' or k < 1 or floor(k) ~= k then | ||
| 84 | return false | ||
| 85 | end | ||
| 86 | if k > max then | ||
| 87 | max = k | ||
| 88 | end | ||
| 89 | n = n + 1 | ||
| 90 | end | ||
| 91 | end | ||
| 92 | if max > 10 and max > arraylen and max > n * 2 then | ||
| 93 | return false -- don't create an array with too many holes | ||
| 94 | end | ||
| 95 | return true, max | ||
| 96 | end | ||
| 97 | |||
| 98 | local escapecodes = { | ||
| 99 | ["\""] = "\\\"", ["\\"] = "\\\\", ["\b"] = "\\b", ["\f"] = "\\f", | ||
| 100 | ["\n"] = "\\n", ["\r"] = "\\r", ["\t"] = "\\t" | ||
| 101 | } | ||
| 102 | |||
| 103 | local function escapeutf8 (uchar) | ||
| 104 | local value = escapecodes[uchar] | ||
| 105 | if value then | ||
| 106 | return value | ||
| 107 | end | ||
| 108 | local a, b, c, d = strbyte (uchar, 1, 4) | ||
| 109 | a, b, c, d = a or 0, b or 0, c or 0, d or 0 | ||
| 110 | if a <= 0x7f then | ||
| 111 | value = a | ||
| 112 | elseif 0xc0 <= a and a <= 0xdf and b >= 0x80 then | ||
| 113 | value = (a - 0xc0) * 0x40 + b - 0x80 | ||
| 114 | elseif 0xe0 <= a and a <= 0xef and b >= 0x80 and c >= 0x80 then | ||
| 115 | value = ((a - 0xe0) * 0x40 + b - 0x80) * 0x40 + c - 0x80 | ||
| 116 | elseif 0xf0 <= a and a <= 0xf7 and b >= 0x80 and c >= 0x80 and d >= 0x80 then | ||
| 117 | value = (((a - 0xf0) * 0x40 + b - 0x80) * 0x40 + c - 0x80) * 0x40 + d - 0x80 | ||
| 118 | else | ||
| 119 | return "" | ||
| 120 | end | ||
| 121 | if value <= 0xffff then | ||
| 122 | return strformat ("\\u%.4x", value) | ||
| 123 | elseif value <= 0x10ffff then | ||
| 124 | -- encode as UTF-16 surrogate pair | ||
| 125 | value = value - 0x10000 | ||
| 126 | local highsur, lowsur = 0xD800 + floor (value/0x400), 0xDC00 + (value % 0x400) | ||
| 127 | return strformat ("\\u%.4x\\u%.4x", highsur, lowsur) | ||
| 128 | else | ||
| 129 | return "" | ||
| 130 | end | ||
| 131 | end | ||
| 132 | |||
| 133 | local function fsub (str, pattern, repl) | ||
| 134 | -- gsub always builds a new string in a buffer, even when no match | ||
| 135 | -- exists. First using find should be more efficient when most strings | ||
| 136 | -- don't contain the pattern. | ||
| 137 | if strfind (str, pattern) then | ||
| 138 | return gsub (str, pattern, repl) | ||
| 139 | else | ||
| 140 | return str | ||
| 141 | end | ||
| 142 | end | ||
| 143 | |||
| 144 | local function quotestring (value) | ||
| 145 | -- based on the regexp "escapable" in https://github.com/douglascrockford/JSON-js | ||
| 146 | value = fsub (value, "[%z\1-\31\"\\\127]", escapeutf8) | ||
| 147 | if strfind (value, "[\194\216\220\225\226\239]") then | ||
| 148 | value = fsub (value, "\194[\128-\159\173]", escapeutf8) | ||
| 149 | value = fsub (value, "\216[\128-\132]", escapeutf8) | ||
| 150 | value = fsub (value, "\220\143", escapeutf8) | ||
| 151 | value = fsub (value, "\225\158[\180\181]", escapeutf8) | ||
| 152 | value = fsub (value, "\226\128[\140-\143\168-\175]", escapeutf8) | ||
| 153 | value = fsub (value, "\226\129[\160-\175]", escapeutf8) | ||
| 154 | value = fsub (value, "\239\187\191", escapeutf8) | ||
| 155 | value = fsub (value, "\239\191[\176-\191]", escapeutf8) | ||
| 156 | end | ||
| 157 | return "\"" .. value .. "\"" | ||
| 158 | end | ||
| 159 | json.quotestring = quotestring | ||
| 160 | |||
| 161 | local function replace(str, o, n) | ||
| 162 | local i, j = strfind (str, o, 1, true) | ||
| 163 | if i then | ||
| 164 | return strsub(str, 1, i-1) .. n .. strsub(str, j+1, -1) | ||
| 165 | else | ||
| 166 | return str | ||
| 167 | end | ||
| 168 | end | ||
| 169 | |||
| 170 | -- locale independent num2str and str2num functions | ||
| 171 | local decpoint, numfilter | ||
| 172 | |||
| 173 | local function updatedecpoint () | ||
| 174 | decpoint = strmatch(tostring(0.5), "([^05+])") | ||
| 175 | -- build a filter that can be used to remove group separators | ||
| 176 | numfilter = "[^0-9%-%+eE" .. gsub(decpoint, "[%^%$%(%)%%%.%[%]%*%+%-%?]", "%%%0") .. "]+" | ||
| 177 | end | ||
| 178 | |||
| 179 | updatedecpoint() | ||
| 180 | |||
| 181 | local function num2str (num) | ||
| 182 | return replace(fsub(tostring(num), numfilter, ""), decpoint, ".") | ||
| 183 | end | ||
| 184 | |||
| 185 | local function str2num (str) | ||
| 186 | local num = tonumber(replace(str, ".", decpoint)) | ||
| 187 | if not num then | ||
| 188 | updatedecpoint() | ||
| 189 | num = tonumber(replace(str, ".", decpoint)) | ||
| 190 | end | ||
| 191 | return num | ||
| 192 | end | ||
| 193 | |||
| 194 | local function addnewline2 (level, buffer, buflen) | ||
| 195 | buffer[buflen+1] = "\n" | ||
| 196 | buffer[buflen+2] = strrep (" ", level) | ||
| 197 | buflen = buflen + 2 | ||
| 198 | return buflen | ||
| 199 | end | ||
| 200 | |||
| 201 | function json.addnewline (state) | ||
| 202 | if state.indent then | ||
| 203 | state.bufferlen = addnewline2 (state.level or 0, | ||
| 204 | state.buffer, state.bufferlen or #(state.buffer)) | ||
| 205 | end | ||
| 206 | end | ||
| 207 | |||
| 208 | local encode2 -- forward declaration | ||
| 209 | |||
| 210 | local function addpair (key, value, prev, indent, level, buffer, buflen, tables, globalorder, state) | ||
| 211 | local kt = type (key) | ||
| 212 | if kt ~= 'string' and kt ~= 'number' then | ||
| 213 | return nil, "type '" .. kt .. "' is not supported as a key by JSON." | ||
| 214 | end | ||
| 215 | if prev then | ||
| 216 | buflen = buflen + 1 | ||
| 217 | buffer[buflen] = "," | ||
| 218 | end | ||
| 219 | if indent then | ||
| 220 | buflen = addnewline2 (level, buffer, buflen) | ||
| 221 | end | ||
| 222 | buffer[buflen+1] = quotestring (key) | ||
| 223 | buffer[buflen+2] = ":" | ||
| 224 | return encode2 (value, indent, level, buffer, buflen + 2, tables, globalorder, state) | ||
| 225 | end | ||
| 226 | |||
| 227 | local function appendcustom(res, buffer, state) | ||
| 228 | local buflen = state.bufferlen | ||
| 229 | if type (res) == 'string' then | ||
| 230 | buflen = buflen + 1 | ||
| 231 | buffer[buflen] = res | ||
| 232 | end | ||
| 233 | return buflen | ||
| 234 | end | ||
| 235 | |||
| 236 | local function exception(reason, value, state, buffer, buflen, defaultmessage) | ||
| 237 | defaultmessage = defaultmessage or reason | ||
| 238 | local handler = state.exception | ||
| 239 | if not handler then | ||
| 240 | return nil, defaultmessage | ||
| 241 | else | ||
| 242 | state.bufferlen = buflen | ||
| 243 | local ret, msg = handler (reason, value, state, defaultmessage) | ||
| 244 | if not ret then return nil, msg or defaultmessage end | ||
| 245 | return appendcustom(ret, buffer, state) | ||
| 246 | end | ||
| 247 | end | ||
| 248 | |||
| 249 | function json.encodeexception(reason, value, state, defaultmessage) | ||
| 250 | return quotestring("<" .. defaultmessage .. ">") | ||
| 251 | end | ||
| 252 | |||
| 253 | encode2 = function (value, indent, level, buffer, buflen, tables, globalorder, state) | ||
| 254 | local valtype = type (value) | ||
| 255 | local valmeta = getmetatable (value) | ||
| 256 | valmeta = type (valmeta) == 'table' and valmeta -- only tables | ||
| 257 | local valtojson = valmeta and valmeta.__tojson | ||
| 258 | if valtojson then | ||
| 259 | if tables[value] then | ||
| 260 | return exception('reference cycle', value, state, buffer, buflen) | ||
| 261 | end | ||
| 262 | tables[value] = true | ||
| 263 | state.bufferlen = buflen | ||
| 264 | local ret, msg = valtojson (value, state) | ||
| 265 | if not ret then return exception('custom encoder failed', value, state, buffer, buflen, msg) end | ||
| 266 | tables[value] = nil | ||
| 267 | buflen = appendcustom(ret, buffer, state) | ||
| 268 | elseif value == nil then | ||
| 269 | buflen = buflen + 1 | ||
| 270 | buffer[buflen] = "null" | ||
| 271 | elseif valtype == 'number' then | ||
| 272 | local s | ||
| 273 | if value ~= value or value >= huge or -value >= huge then | ||
| 274 | -- This is the behaviour of the original JSON implementation. | ||
| 275 | s = "null" | ||
| 276 | else | ||
| 277 | s = num2str (value) | ||
| 278 | end | ||
| 279 | buflen = buflen + 1 | ||
| 280 | buffer[buflen] = s | ||
| 281 | elseif valtype == 'boolean' then | ||
| 282 | buflen = buflen + 1 | ||
| 283 | buffer[buflen] = value and "true" or "false" | ||
| 284 | elseif valtype == 'string' then | ||
| 285 | buflen = buflen + 1 | ||
| 286 | buffer[buflen] = quotestring (value) | ||
| 287 | elseif valtype == 'table' then | ||
| 288 | if tables[value] then | ||
| 289 | return exception('reference cycle', value, state, buffer, buflen) | ||
| 290 | end | ||
| 291 | tables[value] = true | ||
| 292 | level = level + 1 | ||
| 293 | local isa, n = isarray (value) | ||
| 294 | if n == 0 and valmeta and valmeta.__jsontype == 'object' then | ||
| 295 | isa = false | ||
| 296 | end | ||
| 297 | local msg | ||
| 298 | if isa then -- JSON array | ||
| 299 | buflen = buflen + 1 | ||
| 300 | buffer[buflen] = "[" | ||
| 301 | for i = 1, n do | ||
| 302 | buflen, msg = encode2 (value[i], indent, level, buffer, buflen, tables, globalorder, state) | ||
| 303 | if not buflen then return nil, msg end | ||
| 304 | if i < n then | ||
| 305 | buflen = buflen + 1 | ||
| 306 | buffer[buflen] = "," | ||
| 307 | end | ||
| 308 | end | ||
| 309 | buflen = buflen + 1 | ||
| 310 | buffer[buflen] = "]" | ||
| 311 | else -- JSON object | ||
| 312 | local prev = false | ||
| 313 | buflen = buflen + 1 | ||
| 314 | buffer[buflen] = "{" | ||
| 315 | local order = valmeta and valmeta.__jsonorder or globalorder | ||
| 316 | if order then | ||
| 317 | local used = {} | ||
| 318 | n = #order | ||
| 319 | for i = 1, n do | ||
| 320 | local k = order[i] | ||
| 321 | local v = value[k] | ||
| 322 | if v then | ||
| 323 | used[k] = true | ||
| 324 | buflen, msg = addpair (k, v, prev, indent, level, buffer, buflen, tables, globalorder, state) | ||
| 325 | prev = true -- add a seperator before the next element | ||
| 326 | end | ||
| 327 | end | ||
| 328 | for k,v in pairs (value) do | ||
| 329 | if not used[k] then | ||
| 330 | buflen, msg = addpair (k, v, prev, indent, level, buffer, buflen, tables, globalorder, state) | ||
| 331 | if not buflen then return nil, msg end | ||
| 332 | prev = true -- add a seperator before the next element | ||
| 333 | end | ||
| 334 | end | ||
| 335 | else -- unordered | ||
| 336 | for k,v in pairs (value) do | ||
| 337 | buflen, msg = addpair (k, v, prev, indent, level, buffer, buflen, tables, globalorder, state) | ||
| 338 | if not buflen then return nil, msg end | ||
| 339 | prev = true -- add a seperator before the next element | ||
| 340 | end | ||
| 341 | end | ||
| 342 | if indent then | ||
| 343 | buflen = addnewline2 (level - 1, buffer, buflen) | ||
| 344 | end | ||
| 345 | buflen = buflen + 1 | ||
| 346 | buffer[buflen] = "}" | ||
| 347 | end | ||
| 348 | tables[value] = nil | ||
| 349 | else | ||
| 350 | return exception ('unsupported type', value, state, buffer, buflen, | ||
| 351 | "type '" .. valtype .. "' is not supported by JSON.") | ||
| 352 | end | ||
| 353 | return buflen | ||
| 354 | end | ||
| 355 | |||
| 356 | function json.encode (value, state) | ||
| 357 | state = state or {} | ||
| 358 | local oldbuffer = state.buffer | ||
| 359 | local buffer = oldbuffer or {} | ||
| 360 | state.buffer = buffer | ||
| 361 | updatedecpoint() | ||
| 362 | local ret, msg = encode2 (value, state.indent, state.level or 0, | ||
| 363 | buffer, state.bufferlen or 0, state.tables or {}, state.keyorder, state) | ||
| 364 | if not ret then | ||
| 365 | error (msg, 2) | ||
| 366 | elseif oldbuffer == buffer then | ||
| 367 | state.bufferlen = ret | ||
| 368 | return true | ||
| 369 | else | ||
| 370 | state.bufferlen = nil | ||
| 371 | state.buffer = nil | ||
| 372 | return concat (buffer) | ||
| 373 | end | ||
| 374 | end | ||
| 375 | |||
| 376 | local function loc (str, where) | ||
| 377 | local line, pos, linepos = 1, 1, 0 | ||
| 378 | while true do | ||
| 379 | pos = strfind (str, "\n", pos, true) | ||
| 380 | if pos and pos < where then | ||
| 381 | line = line + 1 | ||
| 382 | linepos = pos | ||
| 383 | pos = pos + 1 | ||
| 384 | else | ||
| 385 | break | ||
| 386 | end | ||
| 387 | end | ||
| 388 | return "line " .. line .. ", column " .. (where - linepos) | ||
| 389 | end | ||
| 390 | |||
| 391 | local function unterminated (str, what, where) | ||
| 392 | return nil, strlen (str) + 1, "unterminated " .. what .. " at " .. loc (str, where) | ||
| 393 | end | ||
| 394 | |||
| 395 | local function scanwhite (str, pos) | ||
| 396 | while true do | ||
| 397 | pos = strfind (str, "%S", pos) | ||
| 398 | if not pos then return nil end | ||
| 399 | local sub2 = strsub (str, pos, pos + 1) | ||
| 400 | if sub2 == "\239\187" and strsub (str, pos + 2, pos + 2) == "\191" then | ||
| 401 | -- UTF-8 Byte Order Mark | ||
| 402 | pos = pos + 3 | ||
| 403 | elseif sub2 == "//" then | ||
| 404 | pos = strfind (str, "[\n\r]", pos + 2) | ||
| 405 | if not pos then return nil end | ||
| 406 | elseif sub2 == "/*" then | ||
| 407 | pos = strfind (str, "*/", pos + 2) | ||
| 408 | if not pos then return nil end | ||
| 409 | pos = pos + 2 | ||
| 410 | else | ||
| 411 | return pos | ||
| 412 | end | ||
| 413 | end | ||
| 414 | end | ||
| 415 | |||
| 416 | local escapechars = { | ||
| 417 | ["\""] = "\"", ["\\"] = "\\", ["/"] = "/", ["b"] = "\b", ["f"] = "\f", | ||
| 418 | ["n"] = "\n", ["r"] = "\r", ["t"] = "\t" | ||
| 419 | } | ||
| 420 | |||
| 421 | local function unichar (value) | ||
| 422 | if value < 0 then | ||
| 423 | return nil | ||
| 424 | elseif value <= 0x007f then | ||
| 425 | return strchar (value) | ||
| 426 | elseif value <= 0x07ff then | ||
| 427 | return strchar (0xc0 + floor(value/0x40), | ||
| 428 | 0x80 + (floor(value) % 0x40)) | ||
| 429 | elseif value <= 0xffff then | ||
| 430 | return strchar (0xe0 + floor(value/0x1000), | ||
| 431 | 0x80 + (floor(value/0x40) % 0x40), | ||
| 432 | 0x80 + (floor(value) % 0x40)) | ||
| 433 | elseif value <= 0x10ffff then | ||
| 434 | return strchar (0xf0 + floor(value/0x40000), | ||
| 435 | 0x80 + (floor(value/0x1000) % 0x40), | ||
| 436 | 0x80 + (floor(value/0x40) % 0x40), | ||
| 437 | 0x80 + (floor(value) % 0x40)) | ||
| 438 | else | ||
| 439 | return nil | ||
| 440 | end | ||
| 441 | end | ||
| 442 | |||
| 443 | local function scanstring (str, pos) | ||
| 444 | local lastpos = pos + 1 | ||
| 445 | local buffer, n = {}, 0 | ||
| 446 | while true do | ||
| 447 | local nextpos = strfind (str, "[\"\\]", lastpos) | ||
| 448 | if not nextpos then | ||
| 449 | return unterminated (str, "string", pos) | ||
| 450 | end | ||
| 451 | if nextpos > lastpos then | ||
| 452 | n = n + 1 | ||
| 453 | buffer[n] = strsub (str, lastpos, nextpos - 1) | ||
| 454 | end | ||
| 455 | if strsub (str, nextpos, nextpos) == "\"" then | ||
| 456 | lastpos = nextpos + 1 | ||
| 457 | break | ||
| 458 | else | ||
| 459 | local escchar = strsub (str, nextpos + 1, nextpos + 1) | ||
| 460 | local value | ||
| 461 | if escchar == "u" then | ||
| 462 | value = tonumber (strsub (str, nextpos + 2, nextpos + 5), 16) | ||
| 463 | if value then | ||
| 464 | local value2 | ||
| 465 | if 0xD800 <= value and value <= 0xDBff then | ||
| 466 | -- we have the high surrogate of UTF-16. Check if there is a | ||
| 467 | -- low surrogate escaped nearby to combine them. | ||
| 468 | if strsub (str, nextpos + 6, nextpos + 7) == "\\u" then | ||
| 469 | value2 = tonumber (strsub (str, nextpos + 8, nextpos + 11), 16) | ||
| 470 | if value2 and 0xDC00 <= value2 and value2 <= 0xDFFF then | ||
| 471 | value = (value - 0xD800) * 0x400 + (value2 - 0xDC00) + 0x10000 | ||
| 472 | else | ||
| 473 | value2 = nil -- in case it was out of range for a low surrogate | ||
| 474 | end | ||
| 475 | end | ||
| 476 | end | ||
| 477 | value = value and unichar (value) | ||
| 478 | if value then | ||
| 479 | if value2 then | ||
| 480 | lastpos = nextpos + 12 | ||
| 481 | else | ||
| 482 | lastpos = nextpos + 6 | ||
| 483 | end | ||
| 484 | end | ||
| 485 | end | ||
| 486 | end | ||
| 487 | if not value then | ||
| 488 | value = escapechars[escchar] or escchar | ||
| 489 | lastpos = nextpos + 2 | ||
| 490 | end | ||
| 491 | n = n + 1 | ||
| 492 | buffer[n] = value | ||
| 493 | end | ||
| 494 | end | ||
| 495 | if n == 1 then | ||
| 496 | return buffer[1], lastpos | ||
| 497 | elseif n > 1 then | ||
| 498 | return concat (buffer), lastpos | ||
| 499 | else | ||
| 500 | return "", lastpos | ||
| 501 | end | ||
| 502 | end | ||
| 503 | |||
| 504 | local scanvalue -- forward declaration | ||
| 505 | |||
| 506 | local function scantable (what, closechar, str, startpos, nullval, objectmeta, arraymeta) | ||
| 507 | local len = strlen (str) | ||
| 508 | local tbl, n = {}, 0 | ||
| 509 | local pos = startpos + 1 | ||
| 510 | if what == 'object' then | ||
| 511 | setmetatable (tbl, objectmeta) | ||
| 512 | else | ||
| 513 | setmetatable (tbl, arraymeta) | ||
| 514 | end | ||
| 515 | while true do | ||
| 516 | pos = scanwhite (str, pos) | ||
| 517 | if not pos then return unterminated (str, what, startpos) end | ||
| 518 | local char = strsub (str, pos, pos) | ||
| 519 | if char == closechar then | ||
| 520 | return tbl, pos + 1 | ||
| 521 | end | ||
| 522 | local val1, err | ||
| 523 | val1, pos, err = scanvalue (str, pos, nullval, objectmeta, arraymeta) | ||
| 524 | if err then return nil, pos, err end | ||
| 525 | pos = scanwhite (str, pos) | ||
| 526 | if not pos then return unterminated (str, what, startpos) end | ||
| 527 | char = strsub (str, pos, pos) | ||
| 528 | if char == ":" then | ||
| 529 | if val1 == nil then | ||
| 530 | return nil, pos, "cannot use nil as table index (at " .. loc (str, pos) .. ")" | ||
| 531 | end | ||
| 532 | pos = scanwhite (str, pos + 1) | ||
| 533 | if not pos then return unterminated (str, what, startpos) end | ||
| 534 | local val2 | ||
| 535 | val2, pos, err = scanvalue (str, pos, nullval, objectmeta, arraymeta) | ||
| 536 | if err then return nil, pos, err end | ||
| 537 | tbl[val1] = val2 | ||
| 538 | pos = scanwhite (str, pos) | ||
| 539 | if not pos then return unterminated (str, what, startpos) end | ||
| 540 | char = strsub (str, pos, pos) | ||
| 541 | else | ||
| 542 | n = n + 1 | ||
| 543 | tbl[n] = val1 | ||
| 544 | end | ||
| 545 | if char == "," then | ||
| 546 | pos = pos + 1 | ||
| 547 | end | ||
| 548 | end | ||
| 549 | end | ||
| 550 | |||
| 551 | scanvalue = function (str, pos, nullval, objectmeta, arraymeta) | ||
| 552 | pos = pos or 1 | ||
| 553 | pos = scanwhite (str, pos) | ||
| 554 | if not pos then | ||
| 555 | return nil, strlen (str) + 1, "no valid JSON value (reached the end)" | ||
| 556 | end | ||
| 557 | local char = strsub (str, pos, pos) | ||
| 558 | if char == "{" then | ||
| 559 | return scantable ('object', "}", str, pos, nullval, objectmeta, arraymeta) | ||
| 560 | elseif char == "[" then | ||
| 561 | return scantable ('array', "]", str, pos, nullval, objectmeta, arraymeta) | ||
| 562 | elseif char == "\"" then | ||
| 563 | return scanstring (str, pos) | ||
| 564 | else | ||
| 565 | local pstart, pend = strfind (str, "^%-?[%d%.]+[eE]?[%+%-]?%d*", pos) | ||
| 566 | if pstart then | ||
| 567 | local number = str2num (strsub (str, pstart, pend)) | ||
| 568 | if number then | ||
| 569 | return number, pend + 1 | ||
| 570 | end | ||
| 571 | end | ||
| 572 | pstart, pend = strfind (str, "^%a%w*", pos) | ||
| 573 | if pstart then | ||
| 574 | local name = strsub (str, pstart, pend) | ||
| 575 | if name == "true" then | ||
| 576 | return true, pend + 1 | ||
| 577 | elseif name == "false" then | ||
| 578 | return false, pend + 1 | ||
| 579 | elseif name == "null" then | ||
| 580 | return nullval, pend + 1 | ||
| 581 | end | ||
| 582 | end | ||
| 583 | return nil, pos, "no valid JSON value at " .. loc (str, pos) | ||
| 584 | end | ||
| 585 | end | ||
| 586 | |||
| 587 | local function optionalmetatables(...) | ||
| 588 | if select("#", ...) > 0 then | ||
| 589 | return ... | ||
| 590 | else | ||
| 591 | return {__jsontype = 'object'}, {__jsontype = 'array'} | ||
| 592 | end | ||
| 593 | end | ||
| 594 | |||
| 595 | function json.decode (str, pos, nullval, ...) | ||
| 596 | local objectmeta, arraymeta = optionalmetatables(...) | ||
| 597 | return scanvalue (str, pos, nullval, objectmeta, arraymeta) | ||
| 598 | end | ||
| 599 | |||
| 600 | function json.use_lpeg () | ||
| 601 | local g = require ("lpeg") | ||
| 602 | |||
| 603 | if g.version() == "0.11" then | ||
| 604 | error "due to a bug in LPeg 0.11, it cannot be used for JSON matching" | ||
| 605 | end | ||
| 606 | |||
| 607 | local pegmatch = g.match | ||
| 608 | local P, S, R = g.P, g.S, g.R | ||
| 609 | |||
| 610 | local function ErrorCall (str, pos, msg, state) | ||
| 611 | if not state.msg then | ||
| 612 | state.msg = msg .. " at " .. loc (str, pos) | ||
| 613 | state.pos = pos | ||
| 614 | end | ||
| 615 | return false | ||
| 616 | end | ||
| 617 | |||
| 618 | local function Err (msg) | ||
| 619 | return g.Cmt (g.Cc (msg) * g.Carg (2), ErrorCall) | ||
| 620 | end | ||
| 621 | |||
| 622 | local SingleLineComment = P"//" * (1 - S"\n\r")^0 | ||
| 623 | local MultiLineComment = P"/*" * (1 - P"*/")^0 * P"*/" | ||
| 624 | local Space = (S" \n\r\t" + P"\239\187\191" + SingleLineComment + MultiLineComment)^0 | ||
| 625 | |||
| 626 | local PlainChar = 1 - S"\"\\\n\r" | ||
| 627 | local EscapeSequence = (P"\\" * g.C (S"\"\\/bfnrt" + Err "unsupported escape sequence")) / escapechars | ||
| 628 | local HexDigit = R("09", "af", "AF") | ||
| 629 | local function UTF16Surrogate (match, pos, high, low) | ||
| 630 | high, low = tonumber (high, 16), tonumber (low, 16) | ||
| 631 | if 0xD800 <= high and high <= 0xDBff and 0xDC00 <= low and low <= 0xDFFF then | ||
| 632 | return true, unichar ((high - 0xD800) * 0x400 + (low - 0xDC00) + 0x10000) | ||
| 633 | else | ||
| 634 | return false | ||
| 635 | end | ||
| 636 | end | ||
| 637 | local function UTF16BMP (hex) | ||
| 638 | return unichar (tonumber (hex, 16)) | ||
| 639 | end | ||
| 640 | local U16Sequence = (P"\\u" * g.C (HexDigit * HexDigit * HexDigit * HexDigit)) | ||
| 641 | local UnicodeEscape = g.Cmt (U16Sequence * U16Sequence, UTF16Surrogate) + U16Sequence/UTF16BMP | ||
| 642 | local Char = UnicodeEscape + EscapeSequence + PlainChar | ||
| 643 | local String = P"\"" * g.Cs (Char ^ 0) * (P"\"" + Err "unterminated string") | ||
| 644 | local Integer = P"-"^(-1) * (P"0" + (R"19" * R"09"^0)) | ||
| 645 | local Fractal = P"." * R"09"^0 | ||
| 646 | local Exponent = (S"eE") * (S"+-")^(-1) * R"09"^1 | ||
| 647 | local Number = (Integer * Fractal^(-1) * Exponent^(-1))/str2num | ||
| 648 | local Constant = P"true" * g.Cc (true) + P"false" * g.Cc (false) + P"null" * g.Carg (1) | ||
| 649 | local SimpleValue = Number + String + Constant | ||
| 650 | local ArrayContent, ObjectContent | ||
| 651 | |||
| 652 | -- The functions parsearray and parseobject parse only a single value/pair | ||
| 653 | -- at a time and store them directly to avoid hitting the LPeg limits. | ||
| 654 | local function parsearray (str, pos, nullval, state) | ||
| 655 | local obj, cont | ||
| 656 | local npos | ||
| 657 | local t, nt = {}, 0 | ||
| 658 | repeat | ||
| 659 | obj, cont, npos = pegmatch (ArrayContent, str, pos, nullval, state) | ||
| 660 | if not npos then break end | ||
| 661 | pos = npos | ||
| 662 | nt = nt + 1 | ||
| 663 | t[nt] = obj | ||
| 664 | until cont == 'last' | ||
| 665 | return pos, setmetatable (t, state.arraymeta) | ||
| 666 | end | ||
| 667 | |||
| 668 | local function parseobject (str, pos, nullval, state) | ||
| 669 | local obj, key, cont | ||
| 670 | local npos | ||
| 671 | local t = {} | ||
| 672 | repeat | ||
| 673 | key, obj, cont, npos = pegmatch (ObjectContent, str, pos, nullval, state) | ||
| 674 | if not npos then break end | ||
| 675 | pos = npos | ||
| 676 | t[key] = obj | ||
| 677 | until cont == 'last' | ||
| 678 | return pos, setmetatable (t, state.objectmeta) | ||
| 679 | end | ||
| 680 | |||
| 681 | local Array = P"[" * g.Cmt (g.Carg(1) * g.Carg(2), parsearray) * Space * (P"]" + Err "']' expected") | ||
| 682 | local Object = P"{" * g.Cmt (g.Carg(1) * g.Carg(2), parseobject) * Space * (P"}" + Err "'}' expected") | ||
| 683 | local Value = Space * (Array + Object + SimpleValue) | ||
| 684 | local ExpectedValue = Value + Space * Err "value expected" | ||
| 685 | ArrayContent = Value * Space * (P"," * g.Cc'cont' + g.Cc'last') * g.Cp() | ||
| 686 | local Pair = g.Cg (Space * String * Space * (P":" + Err "colon expected") * ExpectedValue) | ||
| 687 | ObjectContent = Pair * Space * (P"," * g.Cc'cont' + g.Cc'last') * g.Cp() | ||
| 688 | local DecodeValue = ExpectedValue * g.Cp () | ||
| 689 | |||
| 690 | function json.decode (str, pos, nullval, ...) | ||
| 691 | local state = {} | ||
| 692 | state.objectmeta, state.arraymeta = optionalmetatables(...) | ||
| 693 | local obj, retpos = pegmatch (DecodeValue, str, pos, nullval, state) | ||
| 694 | if state.msg then | ||
| 695 | return nil, state.pos, state.msg | ||
| 696 | else | ||
| 697 | return obj, retpos | ||
| 698 | end | ||
| 699 | end | ||
| 700 | |||
| 701 | -- use this function only once: | ||
| 702 | json.use_lpeg = function () return json end | ||
| 703 | |||
| 704 | json.using_lpeg = true | ||
| 705 | |||
| 706 | return json -- so you can get the module using json = require "dkjson".use_lpeg() | ||
| 707 | end | ||
| 708 | |||
| 709 | if always_try_using_lpeg then | ||
| 710 | pcall (json.use_lpeg) | ||
| 711 | end | ||
| 712 | |||
| 713 | return json | ||
| 714 |
| 1 | local c = require "protobuf.c" | ||
| 2 | |||
| 3 | local setmetatable = setmetatable | ||
| 4 | local type = type | ||
| 5 | local table = table | ||
| 6 | local assert = assert | ||
| 7 | local pairs = pairs | ||
| 8 | local ipairs = ipairs | ||
| 9 | local string = string | ||
| 10 | local print = print | ||
| 11 | local io = io | ||
| 12 | local tinsert = table.insert | ||
| 13 | local rawget = rawget | ||
| 14 | local readProtobufFile = readProtobufFile; | ||
| 15 | |||
| 16 | module "protobuf" | ||
| 17 | |||
| 18 | local _pattern_cache = {} | ||
| 19 | |||
| 20 | -- skynet clear | ||
| 21 | local P = c._env_new() | ||
| 22 | local GC = c._gc(P) | ||
| 23 | |||
| 24 | function lasterror() | ||
| 25 | return c._last_error(P) | ||
| 26 | end | ||
| 27 | |||
| 28 | local decode_type_cache = {} | ||
| 29 | local _R_meta = {} | ||
| 30 | |||
| 31 | function _R_meta:__index(key) | ||
| 32 | local v = decode_type_cache[self._CType][key](self, key) | ||
| 33 | self[key] = v | ||
| 34 | return v | ||
| 35 | end | ||
| 36 | |||
| 37 | local _reader = {} | ||
| 38 | |||
| 39 | function _reader:int(key) | ||
| 40 | return c._rmessage_integer(self._CObj , key , 0) | ||
| 41 | end | ||
| 42 | |||
| 43 | function _reader:real(key) | ||
| 44 | return c._rmessage_real(self._CObj , key , 0) | ||
| 45 | end | ||
| 46 | |||
| 47 | function _reader:string(key) | ||
| 48 | return c._rmessage_string(self._CObj , key , 0) | ||
| 49 | end | ||
| 50 | |||
| 51 | function _reader:bool(key) | ||
| 52 | return c._rmessage_integer(self._CObj , key , 0) ~= 0 | ||
| 53 | end | ||
| 54 | |||
| 55 | function _reader:message(key, message_type) | ||
| 56 | local rmessage = c._rmessage_message(self._CObj , key , 0) | ||
| 57 | if rmessage then | ||
| 58 | local v = { | ||
| 59 | _CObj = rmessage, | ||
| 60 | _CType = message_type, | ||
| 61 | _Parent = self, | ||
| 62 | } | ||
| 63 | return setmetatable( v , _R_meta ) | ||
| 64 | end | ||
| 65 | end | ||
| 66 | |||
| 67 | function _reader:int32(key) | ||
| 68 | return c._rmessage_int32(self._CObj , key , 0) | ||
| 69 | end | ||
| 70 | |||
| 71 | function _reader:int64(key) | ||
| 72 | return c._rmessage_int64(self._CObj , key , 0) | ||
| 73 | end | ||
| 74 | |||
| 75 | function _reader:int52(key) | ||
| 76 | return c._rmessage_int52(self._CObj , key , 0) | ||
| 77 | end | ||
| 78 | |||
| 79 | function _reader:uint52(key) | ||
| 80 | return c._rmessage_uint52(self._CObj , key , 0) | ||
| 81 | end | ||
| 82 | |||
| 83 | function _reader:int_repeated(key) | ||
| 84 | local cobj = self._CObj | ||
| 85 | local n = c._rmessage_size(cobj , key) | ||
| 86 | local ret = {} | ||
| 87 | for i=0,n-1 do | ||
| 88 | tinsert(ret, c._rmessage_integer(cobj , key , i)) | ||
| 89 | end | ||
| 90 | return ret | ||
| 91 | end | ||
| 92 | |||
| 93 | function _reader:real_repeated(key) | ||
| 94 | local cobj = self._CObj | ||
| 95 | local n = c._rmessage_size(cobj , key) | ||
| 96 | local ret = {} | ||
| 97 | for i=0,n-1 do | ||
| 98 | tinsert(ret, c._rmessage_real(cobj , key , i)) | ||
| 99 | end | ||
| 100 | return ret | ||
| 101 | end | ||
| 102 | |||
| 103 | function _reader:string_repeated(key) | ||
| 104 | local cobj = self._CObj | ||
| 105 | local n = c._rmessage_size(cobj , key) | ||
| 106 | local ret = {} | ||
| 107 | for i=0,n-1 do | ||
| 108 | tinsert(ret, c._rmessage_string(cobj , key , i)) | ||
| 109 | end | ||
| 110 | return ret | ||
| 111 | end | ||
| 112 | |||
| 113 | function _reader:bool_repeated(key) | ||
| 114 | local cobj = self._CObj | ||
| 115 | local n = c._rmessage_size(cobj , key) | ||
| 116 | local ret = {} | ||
| 117 | for i=0,n-1 do | ||
| 118 | tinsert(ret, c._rmessage_integer(cobj , key , i) ~= 0) | ||
| 119 | end | ||
| 120 | return ret | ||
| 121 | end | ||
| 122 | |||
| 123 | function _reader:message_repeated(key, message_type) | ||
| 124 | local cobj = self._CObj | ||
| 125 | local n = c._rmessage_size(cobj , key) | ||
| 126 | local ret = {} | ||
| 127 | for i=0,n-1 do | ||
| 128 | local m = { | ||
| 129 | _CObj = c._rmessage_message(cobj , key , i), | ||
| 130 | _CType = message_type, | ||
| 131 | _Parent = self, | ||
| 132 | } | ||
| 133 | tinsert(ret, setmetatable( m , _R_meta )) | ||
| 134 | end | ||
| 135 | return ret | ||
| 136 | end | ||
| 137 | |||
| 138 | function _reader:int32_repeated(key) | ||
| 139 | local cobj = self._CObj | ||
| 140 | local n = c._rmessage_size(cobj , key) | ||
| 141 | local ret = {} | ||
| 142 | for i=0,n-1 do | ||
| 143 | tinsert(ret, c._rmessage_int32(cobj , key , i)) | ||
| 144 | end | ||
| 145 | return ret | ||
| 146 | end | ||
| 147 | |||
| 148 | function _reader:int64_repeated(key) | ||
| 149 | local cobj = self._CObj | ||
| 150 | local n = c._rmessage_size(cobj , key) | ||
| 151 | local ret = {} | ||
| 152 | for i=0,n-1 do | ||
| 153 | tinsert(ret, c._rmessage_int64(cobj , key , i)) | ||
| 154 | end | ||
| 155 | return ret | ||
| 156 | end | ||
| 157 | |||
| 158 | function _reader:int52_repeated(key) | ||
| 159 | local cobj = self._CObj | ||
| 160 | local n = c._rmessage_size(cobj , key) | ||
| 161 | local ret = {} | ||
| 162 | for i=0,n-1 do | ||
| 163 | tinsert(ret, c._rmessage_int52(cobj , key , i)) | ||
| 164 | end | ||
| 165 | return ret | ||
| 166 | end | ||
| 167 | |||
| 168 | function _reader:uint52_repeated(key) | ||
| 169 | local cobj = self._CObj | ||
| 170 | local n = c._rmessage_size(cobj , key) | ||
| 171 | local ret = {} | ||
| 172 | for i=0,n-1 do | ||
| 173 | tinsert(ret, c._rmessage_uint52(cobj , key , i)) | ||
| 174 | end | ||
| 175 | return ret | ||
| 176 | end | ||
| 177 | |||
| 178 | _reader[1] = function(msg) return _reader.int end | ||
| 179 | _reader[2] = function(msg) return _reader.real end | ||
| 180 | _reader[3] = function(msg) return _reader.bool end | ||
| 181 | _reader[4] = function(msg) return _reader.string end | ||
| 182 | _reader[5] = function(msg) return _reader.string end | ||
| 183 | _reader[6] = function(msg) | ||
| 184 | local message = _reader.message | ||
| 185 | return function(self,key) | ||
| 186 | return message(self, key, msg) | ||
| 187 | end | ||
| 188 | end | ||
| 189 | _reader[7] = function(msg) return _reader.int64 end | ||
| 190 | _reader[8] = function(msg) return _reader.int32 end | ||
| 191 | _reader[9] = _reader[5] | ||
| 192 | _reader[10] = function(msg) return _reader.int52 end | ||
| 193 | _reader[11] = function(msg) return _reader.uint52 end | ||
| 194 | |||
| 195 | _reader[128+1] = function(msg) return _reader.int_repeated end | ||
| 196 | _reader[128+2] = function(msg) return _reader.real_repeated end | ||
| 197 | _reader[128+3] = function(msg) return _reader.bool_repeated end | ||
| 198 | _reader[128+4] = function(msg) return _reader.string_repeated end | ||
| 199 | _reader[128+5] = function(msg) return _reader.string_repeated end | ||
| 200 | _reader[128+6] = function(msg) | ||
| 201 | local message = _reader.message_repeated | ||
| 202 | return function(self,key) | ||
| 203 | return message(self, key, msg) | ||
| 204 | end | ||
| 205 | end | ||
| 206 | _reader[128+7] = function(msg) return _reader.int64_repeated end | ||
| 207 | _reader[128+8] = function(msg) return _reader.int32_repeated end | ||
| 208 | _reader[128+9] = _reader[128+5] | ||
| 209 | _reader[128+10] = function(msg) return _reader.int52_repeated end | ||
| 210 | _reader[128+11] = function(msg) return _reader.uint52_repeated end | ||
| 211 | |||
| 212 | local _decode_type_meta = {} | ||
| 213 | |||
| 214 | function _decode_type_meta:__index(key) | ||
| 215 | local t, msg = c._env_type(P, self._CType, key) | ||
| 216 | local func = assert(_reader[t],key)(msg) | ||
| 217 | self[key] = func | ||
| 218 | return func | ||
| 219 | end | ||
| 220 | |||
| 221 | setmetatable(decode_type_cache , { | ||
| 222 | __index = function(self, key) | ||
| 223 | local v = setmetatable({ _CType = key } , _decode_type_meta) | ||
| 224 | self[key] = v | ||
| 225 | return v | ||
| 226 | end | ||
| 227 | }) | ||
| 228 | |||
| 229 | local function decode_message( message , buffer, length) | ||
| 230 | local rmessage = c._rmessage_new(P, message, buffer, length) | ||
| 231 | if rmessage then | ||
| 232 | local self = { | ||
| 233 | _CObj = rmessage, | ||
| 234 | _CType = message, | ||
| 235 | } | ||
| 236 | c._add_rmessage(GC,rmessage) | ||
| 237 | return setmetatable( self , _R_meta ) | ||
| 238 | end | ||
| 239 | end | ||
| 240 | |||
| 241 | ----------- encode ---------------- | ||
| 242 | |||
| 243 | local encode_type_cache = {} | ||
| 244 | |||
| 245 | local function encode_message(CObj, message_type, t) | ||
| 246 | local type = encode_type_cache[message_type] | ||
| 247 | for k,v in pairs(t) do | ||
| 248 | local func = type[k] | ||
| 249 | func(CObj, k , v) | ||
| 250 | end | ||
| 251 | end | ||
| 252 | |||
| 253 | local _writer = { | ||
| 254 | int = c._wmessage_integer, | ||
| 255 | real = c._wmessage_real, | ||
| 256 | enum = c._wmessage_string, | ||
| 257 | string = c._wmessage_string, | ||
| 258 | int64 = c._wmessage_int64, | ||
| 259 | int32 = c._wmessage_int32, | ||
| 260 | int52 = c._wmessage_int52, | ||
| 261 | uint52 = c._wmessage_uint52, | ||
| 262 | } | ||
| 263 | |||
| 264 | function _writer:bool(k,v) | ||
| 265 | c._wmessage_integer(self, k, v and 1 or 0) | ||
| 266 | end | ||
| 267 | |||
| 268 | function _writer:message(k, v , message_type) | ||
| 269 | local submessage = c._wmessage_message(self, k) | ||
| 270 | encode_message(submessage, message_type, v) | ||
| 271 | end | ||
| 272 | |||
| 273 | function _writer:int_repeated(k,v) | ||
| 274 | for _,v in ipairs(v) do | ||
| 275 | c._wmessage_integer(self,k,v) | ||
| 276 | end | ||
| 277 | end | ||
| 278 | |||
| 279 | function _writer:real_repeated(k,v) | ||
| 280 | for _,v in ipairs(v) do | ||
| 281 | c._wmessage_real(self,k,v) | ||
| 282 | end | ||
| 283 | end | ||
| 284 | |||
| 285 | function _writer:bool_repeated(k,v) | ||
| 286 | for _,v in ipairs(v) do | ||
| 287 | c._wmessage_integer(self, k, v and 1 or 0) | ||
| 288 | end | ||
| 289 | end | ||
| 290 | |||
| 291 | function _writer:string_repeated(k,v) | ||
| 292 | for _,v in ipairs(v) do | ||
| 293 | c._wmessage_string(self,k,v) | ||
| 294 | end | ||
| 295 | end | ||
| 296 | |||
| 297 | function _writer:message_repeated(k,v, message_type) | ||
| 298 | for _,v in ipairs(v) do | ||
| 299 | local submessage = c._wmessage_message(self, k) | ||
| 300 | encode_message(submessage, message_type, v) | ||
| 301 | end | ||
| 302 | end | ||
| 303 | |||
| 304 | function _writer:int32_repeated(k,v) | ||
| 305 | for _,v in ipairs(v) do | ||
| 306 | c._wmessage_int32(self,k,v) | ||
| 307 | end | ||
| 308 | end | ||
| 309 | |||
| 310 | function _writer:int64_repeated(k,v) | ||
| 311 | for _,v in ipairs(v) do | ||
| 312 | c._wmessage_int64(self,k,v) | ||
| 313 | end | ||
| 314 | end | ||
| 315 | |||
| 316 | function _writer:int52_repeated(k,v) | ||
| 317 | for _,v in ipairs(v) do | ||
| 318 | c._wmessage_int52(self,k,v) | ||
| 319 | end | ||
| 320 | end | ||
| 321 | |||
| 322 | function _writer:uint52_repeated(k,v) | ||
| 323 | for _,v in ipairs(v) do | ||
| 324 | c._wmessage_uint52(self,k,v) | ||
| 325 | end | ||
| 326 | end | ||
| 327 | |||
| 328 | _writer[1] = function(msg) return _writer.int end | ||
| 329 | _writer[2] = function(msg) return _writer.real end | ||
| 330 | _writer[3] = function(msg) return _writer.bool end | ||
| 331 | _writer[4] = function(msg) return _writer.string end | ||
| 332 | _writer[5] = function(msg) return _writer.string end | ||
| 333 | _writer[6] = function(msg) | ||
| 334 | local message = _writer.message | ||
| 335 | return function(self,key , v) | ||
| 336 | return message(self, key, v, msg) | ||
| 337 | end | ||
| 338 | end | ||
| 339 | _writer[7] = function(msg) return _writer.int64 end | ||
| 340 | _writer[8] = function(msg) return _writer.int32 end | ||
| 341 | _writer[9] = _writer[5] | ||
| 342 | _writer[10] = function(msg) return _writer.int52 end | ||
| 343 | _writer[11] = function(msg) return _writer.uint52 end | ||
| 344 | |||
| 345 | _writer[128+1] = function(msg) return _writer.int_repeated end | ||
| 346 | _writer[128+2] = function(msg) return _writer.real_repeated end | ||
| 347 | _writer[128+3] = function(msg) return _writer.bool_repeated end | ||
| 348 | _writer[128+4] = function(msg) return _writer.string_repeated end | ||
| 349 | _writer[128+5] = function(msg) return _writer.string_repeated end | ||
| 350 | _writer[128+6] = function(msg) | ||
| 351 | local message = _writer.message_repeated | ||
| 352 | return function(self,key, v) | ||
| 353 | return message(self, key, v, msg) | ||
| 354 | end | ||
| 355 | end | ||
| 356 | _writer[128+7] = function(msg) return _writer.int64_repeated end | ||
| 357 | _writer[128+8] = function(msg) return _writer.int32_repeated end | ||
| 358 | _writer[128+9] = _writer[128+5] | ||
| 359 | _writer[128+10] = function(msg) return _writer.int52_repeated end | ||
| 360 | _writer[128+11] = function(msg) return _writer.uint52_repeated end | ||
| 361 | |||
| 362 | local _encode_type_meta = {} | ||
| 363 | |||
| 364 | function _encode_type_meta:__index(key) | ||
| 365 | local t, msg = c._env_type(P, self._CType, key) | ||
| 366 | local func = assert(_writer[t],key)(msg) | ||
| 367 | self[key] = func | ||
| 368 | return func | ||
| 369 | end | ||
| 370 | |||
| 371 | setmetatable(encode_type_cache , { | ||
| 372 | __index = function(self, key) | ||
| 373 | local v = setmetatable({ _CType = key } , _encode_type_meta) | ||
| 374 | self[key] = v | ||
| 375 | return v | ||
| 376 | end | ||
| 377 | }) | ||
| 378 | |||
| 379 | function encode( message, t , func , ...) | ||
| 380 | local encoder = c._wmessage_new(P, message) | ||
| 381 | assert(encoder , message) | ||
| 382 | encode_message(encoder, message, t) | ||
| 383 | if func then | ||
| 384 | local buffer, len = c._wmessage_buffer(encoder) | ||
| 385 | local ret = func(buffer, len, ...) | ||
| 386 | c._wmessage_delete(encoder) | ||
| 387 | return ret | ||
| 388 | else | ||
| 389 | local s = c._wmessage_buffer_string(encoder) | ||
| 390 | c._wmessage_delete(encoder) | ||
| 391 | return s | ||
| 392 | end | ||
| 393 | end | ||
| 394 | |||
| 395 | --------- unpack ---------- | ||
| 396 | |||
| 397 | local _pattern_type = { | ||
| 398 | [1] = {"%d","i"}, | ||
| 399 | [2] = {"%F","r"}, | ||
| 400 | [3] = {"%d","b"}, | ||
| 401 | [4] = {"%d","i"}, | ||
| 402 | [5] = {"%s","s"}, | ||
| 403 | [6] = {"%s","m"}, | ||
| 404 | [7] = {"%D","x"}, | ||
| 405 | [8] = {"%d","p"}, | ||
| 406 | [10] = {"%D","d"}, | ||
| 407 | [11] = {"%D","u"}, | ||
| 408 | [128+1] = {"%a","I"}, | ||
| 409 | [128+2] = {"%a","R"}, | ||
| 410 | [128+3] = {"%a","B"}, | ||
| 411 | [128+4] = {"%a","I"}, | ||
| 412 | [128+5] = {"%a","S"}, | ||
| 413 | [128+6] = {"%a","M"}, | ||
| 414 | [128+7] = {"%a","X"}, | ||
| 415 | [128+8] = {"%a","P"}, | ||
| 416 | [128+10] = {"%a", "D" }, | ||
| 417 | [128+11] = {"%a", "U" }, | ||
| 418 | } | ||
| 419 | |||
| 420 | _pattern_type[9] = _pattern_type[5] | ||
| 421 | _pattern_type[128+9] = _pattern_type[128+5] | ||
| 422 | |||
| 423 | |||
| 424 | local function _pattern_create(pattern) | ||
| 425 | local iter = string.gmatch(pattern,"[^ ]+") | ||
| 426 | local message = iter() | ||
| 427 | local cpat = {} | ||
| 428 | local lua = {} | ||
| 429 | for v in iter do | ||
| 430 | local tidx = c._env_type(P, message, v) | ||
| 431 | local t = _pattern_type[tidx] | ||
| 432 | assert(t,tidx) | ||
| 433 | tinsert(cpat,v .. " " .. t[1]) | ||
| 434 | tinsert(lua,t[2]) | ||
| 435 | end | ||
| 436 | local cobj = c._pattern_new(P, message , "@" .. table.concat(cpat," ")) | ||
| 437 | if cobj == nil then | ||
| 438 | return | ||
| 439 | end | ||
| 440 | c._add_pattern(GC, cobj) | ||
| 441 | local pat = { | ||
| 442 | CObj = cobj, | ||
| 443 | format = table.concat(lua), | ||
| 444 | size = 0 | ||
| 445 | } | ||
| 446 | pat.size = c._pattern_size(pat.format) | ||
| 447 | |||
| 448 | return pat | ||
| 449 | end | ||
| 450 | |||
| 451 | setmetatable(_pattern_cache, { | ||
| 452 | __index = function(t, key) | ||
| 453 | local v = _pattern_create(key) | ||
| 454 | t[key] = v | ||
| 455 | return v | ||
| 456 | end | ||
| 457 | }) | ||
| 458 | |||
| 459 | function unpack(pattern, buffer, length) | ||
| 460 | local pat = _pattern_cache[pattern] | ||
| 461 | return c._pattern_unpack(pat.CObj , pat.format, pat.size, buffer, length) | ||
| 462 | end | ||
| 463 | |||
| 464 | function pack(pattern, ...) | ||
| 465 | local pat = _pattern_cache[pattern] | ||
| 466 | return c._pattern_pack(pat.CObj, pat.format, pat.size , ...) | ||
| 467 | end | ||
| 468 | |||
| 469 | function check(typename , field) | ||
| 470 | if field == nil then | ||
| 471 | return c._env_type(P,typename) | ||
| 472 | else | ||
| 473 | return c._env_type(P,typename,field) ~=0 | ||
| 474 | end | ||
| 475 | end | ||
| 476 | |||
| 477 | -------------- | ||
| 478 | |||
| 479 | local default_cache = {} | ||
| 480 | |||
| 481 | -- todo : clear default_cache, v._CObj | ||
| 482 | |||
| 483 | local function default_table(typename) | ||
| 484 | local v = default_cache[typename] | ||
| 485 | if v then | ||
| 486 | return v | ||
| 487 | end | ||
| 488 | |||
| 489 | v = { __index = assert(decode_message(typename , "")) } | ||
| 490 | |||
| 491 | default_cache[typename] = v | ||
| 492 | return v | ||
| 493 | end | ||
| 494 | |||
| 495 | local decode_message_mt = {} | ||
| 496 | |||
| 497 | local function decode_message_cb(typename, buffer) | ||
| 498 | return setmetatable ( { typename, buffer } , decode_message_mt) | ||
| 499 | end | ||
| 500 | |||
| 501 | function decode(typename, buffer, length) | ||
| 502 | local ret = {} | ||
| 503 | local ok = c._decode(P, decode_message_cb , ret , typename, buffer, length) | ||
| 504 | if ok then | ||
| 505 | return setmetatable(ret , default_table(typename)) | ||
| 506 | else | ||
| 507 | return false , c._last_error(P) | ||
| 508 | end | ||
| 509 | end | ||
| 510 | |||
| 511 | local function expand(tbl) | ||
| 512 | local typename = rawget(tbl , 1) | ||
| 513 | local buffer = rawget(tbl , 2) | ||
| 514 | tbl[1] , tbl[2] = nil , nil | ||
| 515 | assert(c._decode(P, decode_message_cb , tbl , typename, buffer), typename) | ||
| 516 | setmetatable(tbl , default_table(typename)) | ||
| 517 | end | ||
| 518 | |||
| 519 | function decode_message_mt.__index(tbl, key) | ||
| 520 | expand(tbl) | ||
| 521 | return tbl[key] | ||
| 522 | end | ||
| 523 | |||
| 524 | function decode_message_mt.__pairs(tbl) | ||
| 525 | expand(tbl) | ||
| 526 | return pairs(tbl) | ||
| 527 | end | ||
| 528 | |||
| 529 | local function set_default(typename, tbl) | ||
| 530 | for k,v in pairs(tbl) do | ||
| 531 | if type(v) == "table" then | ||
| 532 | local t, msg = c._env_type(P, typename, k) | ||
| 533 | if t == 6 then | ||
| 534 | set_default(msg, v) | ||
| 535 | elseif t == 128+6 then | ||
| 536 | for _,v in ipairs(v) do | ||
| 537 | set_default(msg, v) | ||
| 538 | end | ||
| 539 | end | ||
| 540 | end | ||
| 541 | end | ||
| 542 | return setmetatable(tbl , default_table(typename)) | ||
| 543 | end | ||
| 544 | |||
| 545 | function register( buffer) | ||
| 546 | c._env_register(P, buffer) | ||
| 547 | end | ||
| 548 | |||
| 549 | function register_file(filename) | ||
| 550 | -- local f = assert(io.open(filename , "rb")) | ||
| 551 | -- local buffer = f:read "*a" | ||
| 552 | -- c._env_register(P, buffer) | ||
| 553 | -- f:close() | ||
| 554 | |||
| 555 | local buffer = readProtobufFile(filename); | ||
| 556 | c._env_register(P, buffer) | ||
| 557 | end | ||
| 558 | |||
| 559 | function enum_id(enum_type, enum_name) | ||
| 560 | return c._env_enum_id(P, enum_type, enum_name) | ||
| 561 | end | ||
| 562 | |||
| 563 | function extract(tbl) | ||
| 564 | local typename = rawget(tbl , 1) | ||
| 565 | local buffer = rawget(tbl , 2) | ||
| 566 | if type(typename) == "string" and type(buffer) == "string" then | ||
| 567 | if check(typename) then | ||
| 568 | expand(tbl) | ||
| 569 | end | ||
| 570 | end | ||
| 571 | |||
| 572 | for k, v in pairs(tbl) do | ||
| 573 | if type(v) == "table" then | ||
| 574 | extract(v) | ||
| 575 | end | ||
| 576 | end | ||
| 577 | end | ||
| 578 | |||
| 579 | default=set_default |
| 1 | require "core.net.socket_tcp"; | ||
| 2 | require "core.net.socket_msg"; | ||
| 3 | |||
| 4 | local ENDIAN_LITTLE = "ENDIAN_LITTLE" | ||
| 5 | local ENDIAN_BIG = "ENDIAN_BIG" | ||
| 6 | |||
| 7 | local connected = false | ||
| 8 | local connectcount = 0 | ||
| 9 | local socket_data = "" | ||
| 10 | local lastcallback | ||
| 11 | local loginaddrs = {} | ||
| 12 | |||
| 13 | ----小端 | ||
| 14 | --function int64_little(str) | ||
| 15 | -- return string.byte(str, 8) * (0xffffffffffffff+1) + string.byte(str, 7) * (0xffffffffffff+1) + string.byte(str, 6) * (0xffffffffff+1) + string.byte(str, 5) * (0xffffffff+1) + string.byte(str, 4) * (0xffffff+1) + string.byte(str, 3) * (0xffff+1) + string.byte(str, 2) * (0xff+1) + string.byte(str, 1) | ||
| 16 | --end | ||
| 17 | |||
| 18 | --小端 | ||
| 19 | function int32_little(str) | ||
| 20 | return string.byte(str, 4) * (0xffffff+1) + string.byte(str, 3) * (0xffff+1) + string.byte(str, 2) * (0xff+1) + string.byte(str, 1) | ||
| 21 | end | ||
| 22 | |||
| 23 | --大端 | ||
| 24 | function int32_big(str) | ||
| 25 | return string.byte(str, 1) * (0xffffff+1) + string.byte(str, 2) * (0xffff+1) + string.byte(str, 3) * (0xff+1) + string.byte(str, 4) | ||
| 26 | end | ||
| 27 | |||
| 28 | --小端 | ||
| 29 | function int16_little(str) | ||
| 30 | return string.byte(str, 2) * (0xff+1) + string.byte(str, 1) | ||
| 31 | end | ||
| 32 | |||
| 33 | --[[ | ||
| 34 | 包头信息 包头长度24 | ||
| 35 | len 4字节(uint32) --包头加包体总长度 | ||
| 36 | seq 4字节(uint32) | ||
| 37 | msgid 4字节(uint32) | ||
| 38 | ret 4字节(uint32) | ||
| 39 | userid 8字节(uint64) | ||
| 40 | ]]-- | ||
| 41 | local function unpack_package(text) | ||
| 42 | local size = #text; | ||
| 43 | if size < 24 then | ||
| 44 | return nil, text; | ||
| 45 | end | ||
| 46 | |||
| 47 | -- for i=1,24,1 do | ||
| 48 | -- print(i,"byte:"..text:byte(i)); | ||
| 49 | -- end | ||
| 50 | -- local s = text:byte(1) * 256 + text:byte(2) | ||
| 51 | |||
| 52 | local len = int32_little(text:sub(1,4)); | ||
| 53 | if size < len then | ||
| 54 | return nil, text; | ||
| 55 | end | ||
| 56 | |||
| 57 | local msgid = int32_little(text:sub(9,12)); | ||
| 58 | local errcode = int32_little(text:sub(13,16)); | ||
| 59 | |||
| 60 | -- logW("len:"..len,"errcode:"..errcode,"msgid:"..msgid); | ||
| 61 | |||
| 62 | local header = {len=len,errcode=errcode,msgid=msgid}; | ||
| 63 | |||
| 64 | return text:sub(25,len), text:sub(1+len),header; | ||
| 65 | end | ||
| 66 | |||
| 67 | local function onSocketData(data) | ||
| 68 | socket_data = socket_data .. data; | ||
| 69 | while true do | ||
| 70 | local package,remain,header = unpack_package(socket_data) | ||
| 71 | |||
| 72 | if package == nil then | ||
| 73 | break; | ||
| 74 | end | ||
| 75 | |||
| 76 | socket_data = remain; | ||
| 77 | |||
| 78 | local len = header.len; | ||
| 79 | local errcode = header.errcode; | ||
| 80 | local msgid = header.msgid; | ||
| 81 | local msgname = cmsg.msgtoproto(msgid); | ||
| 82 | if msgname then | ||
| 83 | -- if len > 24 then | ||
| 84 | local result,error = protobuf.decode(msgname, package); | ||
| 85 | if not error then | ||
| 86 | local data = {errcode=errcode,data=result}; | ||
| 87 | cmsg.handlemsg(msgid,msgname,data); | ||
| 88 | if msgname == "gateway_msg.login_msg" then | ||
| 89 | cmsg.flushqueue(); | ||
| 90 | end | ||
| 91 | else | ||
| 92 | dprint("failed to decode msg",msgname); | ||
| 93 | end | ||
| 94 | -- else | ||
| 95 | -- local data = {errcode=errcode,data={}}; | ||
| 96 | -- cmsg.handlemsg(msgid,msgname,data); | ||
| 97 | -- end | ||
| 98 | else | ||
| 99 | dprint("unknow msgid",string.format("%#x",msgid)); | ||
| 100 | end | ||
| 101 | end | ||
| 102 | end | ||
| 103 | |||
| 104 | local function onSocketConnect(data) | ||
| 105 | -- socket_verify.reset() | ||
| 106 | connected = true; | ||
| 107 | if lastcallback then | ||
| 108 | lastcallback(); | ||
| 109 | end | ||
| 110 | dprint("socket connected"); | ||
| 111 | end | ||
| 112 | |||
| 113 | local function onSocketDisconnect(data) | ||
| 114 | connectcount = 0 | ||
| 115 | socket_data = "" | ||
| 116 | connected = false; | ||
| 117 | |||
| 118 | EventListener.dispatchEvent(EnumEvent.SOCKET_DISCONNECT); | ||
| 119 | dprint("onSocketDisconnect") | ||
| 120 | end | ||
| 121 | |||
| 122 | function addconnectaddr(host, port) | ||
| 123 | table.insert(loginaddrs,{host,port}) | ||
| 124 | end | ||
| 125 | |||
| 126 | function makeConnect(callback,connectFaildFun) | ||
| 127 | connectcount = connectcount + 1 | ||
| 128 | lastcallback = callback | ||
| 129 | |||
| 130 | if socket_tcp.connected() then | ||
| 131 | socket_tcp.disconnect() | ||
| 132 | end | ||
| 133 | |||
| 134 | local addr = loginaddrs[math.random(1,#loginaddrs)] | ||
| 135 | local host = addr[1] | ||
| 136 | local port = addr[2] | ||
| 137 | |||
| 138 | local function onSocketConnectError(data) | ||
| 139 | connected = false | ||
| 140 | dprint("socket_connection error"); | ||
| 141 | if connectFaildFun then | ||
| 142 | connectFaildFun(data); | ||
| 143 | end | ||
| 144 | end | ||
| 145 | |||
| 146 | --bind use event: | ||
| 147 | socket_tcp.setCallback(onSocketData,onSocketConnect,onSocketConnectError,onSocketDisconnect) | ||
| 148 | socket_tcp.connect(host,port,true) | ||
| 149 | end | ||
| 150 | |||
| 151 | function parse_socket_data(data) | ||
| 152 | local socket_data_list = {}; | ||
| 153 | local _socket_data = data; | ||
| 154 | while true do | ||
| 155 | local package,remain,header = unpack_package(_socket_data) | ||
| 156 | |||
| 157 | if package == nil then | ||
| 158 | break; | ||
| 159 | end | ||
| 160 | |||
| 161 | _socket_data = remain; | ||
| 162 | |||
| 163 | local len = header.len; | ||
| 164 | local errcode = header.errcode; | ||
| 165 | local msgid = header.msgid; | ||
| 166 | local msgname = cmsg.msgtoproto(msgid); | ||
| 167 | if msgname then | ||
| 168 | dprint("-----------------reconnect socket data:",msgname); | ||
| 169 | local result,error = protobuf.decode(msgname, package); | ||
| 170 | if not error then | ||
| 171 | local data = {errcode=errcode,data=result}; | ||
| 172 | cmsg.handlemsg(msgid,msgname,data); | ||
| 173 | |||
| 174 | -- socket_data_list[#socket_data_list+1] = {msgid=msgid,msgname=msgname,errcode=errcode,data=result}; | ||
| 175 | else | ||
| 176 | dprint("failed to decode msg",msgname); | ||
| 177 | end | ||
| 178 | else | ||
| 179 | dprint("unknow msgid",string.format("%#x",msgid)); | ||
| 180 | end | ||
| 181 | end | ||
| 182 | return socket_data_list; | ||
| 183 | end | ||
| 184 | |||
| 185 | function isConnected() | ||
| 186 | return connected | ||
| 187 | end | ||
| 188 | |||
| 189 | local connectionlosttime = 0 | ||
| 190 | local connecting = false | ||
| 191 | |||
| 192 | local function checkconnection() | ||
| 193 | if connected then | ||
| 194 | connectionlosttime = 0 | ||
| 195 | connecting = false | ||
| 196 | return | ||
| 197 | end | ||
| 198 | |||
| 199 | if connectcount == 0 then | ||
| 200 | return | ||
| 201 | end | ||
| 202 | |||
| 203 | if not cmsg.hasqueuemessage() then | ||
| 204 | connectionlosttime = connectionlosttime + 1 | ||
| 205 | |||
| 206 | if connectionlosttime > 60 then | ||
| 207 | makeConnect(lastcallback) | ||
| 208 | connectionlosttime = 0 | ||
| 209 | end | ||
| 210 | else | ||
| 211 | if socket_tcp.connecttimeout() then | ||
| 212 | makeConnect(lastcallback) | ||
| 213 | end | ||
| 214 | |||
| 215 | connectionlosttime = connectionlosttime + 1 | ||
| 216 | |||
| 217 | --1分钟后清除发送数据 | ||
| 218 | if connectionlosttime > 60 then | ||
| 219 | cmsg.clearqueue() | ||
| 220 | connectionlosttime = 0 | ||
| 221 | end | ||
| 222 | end | ||
| 223 | end | ||
| 224 | |||
| 225 | --cc.Director:getInstance():getScheduler():scheduleScriptFunc(checkconnection,1,false); | ||
| 226 | |||
| 227 | |||
| 228 | |||
| 229 | |||
| 230 | |||
| 231 | |||
| 232 |
| 1 | -------- | ||
| 2 | local eventclass = require("cocos.framework.components.event"); | ||
| 3 | require("cocos.framework.package_support"); | ||
| 4 | require("core.net.protobuf"); | ||
| 5 | |||
| 6 | local print = print; | ||
| 7 | local logD = logD; | ||
| 8 | local logUI = logUI; | ||
| 9 | local string = string; | ||
| 10 | local tostring = tostring; | ||
| 11 | local socket_tcp = socket_tcp; | ||
| 12 | local protobuf = protobuf; | ||
| 13 | local aiOnSend = aiOnSend; | ||
| 14 | local DEBUG = DEBUG; | ||
| 15 | local table = table; | ||
| 16 | local json = json; | ||
| 17 | local EventListener = require("app.event.EventListener"); | ||
| 18 | local delayCall = delayCall; | ||
| 19 | local removeDelay = removeDelay; | ||
| 20 | |||
| 21 | local protos = | ||
| 22 | { | ||
| 23 | "pb/share_msg.pb", | ||
| 24 | "pb/common_msg.pb", | ||
| 25 | "pb/gateway_msg.pb", | ||
| 26 | } | ||
| 27 | |||
| 28 | local proto_id_map_send = | ||
| 29 | { | ||
| 30 | ["gateway_msg.sys_information_msg"] = 0xf001, --获取系统时间 | ||
| 31 | ["gateway_msg.sys_test_msg"] = 0xf004, --测试协议 | ||
| 32 | ["gateway_msg.login_msg"] = 0x0101, --登录 | ||
| 33 | ["gateway_msg.create_role_msg"] = 0x0104, --创建角色 | ||
| 34 | ["gateway_msg.get_rank_msg"] = 0x00201, --获取榜单 | ||
| 35 | ["gateway_msg.get_yesterday_reward_rank_msg"] = 0x00202, --获取昨天榜单奖励 | ||
| 36 | ["gateway_msg.shop_buy_msg"] = 0x00301, --购买道具 | ||
| 37 | ["gateway_msg.pay_get_id_msg"] = 0x00350, --获取订单号 | ||
| 38 | ["gateway_msg.notify_pay_succ_msg"] = 0x00351, --购买成功 | ||
| 39 | ["gateway_msg.get_pay_day_reward_msg"] = 0x00352, --领取购买的每天领取奖励 | ||
| 40 | ["gateway_msg.get_phone_num_msg"] = 0x00353, --获取电话号码 | ||
| 41 | ["gateway_msg.change_nick_msg"] = 0x0402, --改名字 | ||
| 42 | ["gateway_msg.change_head_msg"] = 0x0403, --改头像 | ||
| 43 | ["gateway_msg.get_user_info_msg"] = 0x0406, --获取用户信息 | ||
| 44 | ["gateway_msg.furniture_pos_msg"] = 0x0408, --设置家具位置 | ||
| 45 | ["gateway_msg.wall_on_msg"] = 0x0409, --换上墙纸 | ||
| 46 | ["gateway_msg.notify_task_daily_msg"] = 0x00501, --每日任务 | ||
| 47 | ["gateway_msg.get_task_daily_reward_msg"] = 0x00502, --领取每日任务 | ||
| 48 | ["gateway_msg.use_item_msg"] = 0x00603, --使用道具 | ||
| 49 | ["gateway_msg.notify_item_cnt_max_msg"] = 0x0606, --通知道具数量已达上限 | ||
| 50 | ["gateway_msg.sign_msg"] = 0x00701, --签到 | ||
| 51 | ["gateway_msg.sign_reward_msg"] = 0x00702, --签到领取奖励 | ||
| 52 | ["gateway_msg.sign_update_msg"] = 0x00703, --补签 | ||
| 53 | ["gateway_msg.get_role_reward_msg"] = 0x00704, --领取7日礼包 | ||
| 54 | ["gateway_msg.get_create_reward_msg"] = 0x00705, --领取创建奖励 | ||
| 55 | ["gateway_msg.get_online_reward_msg"] = 0x00706, --领取在线礼包 | ||
| 56 | ["gateway_msg.show_btl_cnt_reward_msg"] = 0x00707, --新手对局福利展现 | ||
| 57 | ["gateway_msg.get_btl_cnt_reward_msg"] = 0x00708, --获取 新手对局福利 | ||
| 58 | ["gateway_msg.get_turntable_reward_msg"] = 0x00709, --获取 转盘抽奖 | ||
| 59 | ["gateway_msg.get_turntable_reward_and_login_reward_msg"] = 0x0070a, --获取 转盘抽奖和登录奖励 信息 | ||
| 60 | ["gateway_msg.get_relief_msg"] = 0x0070b, --领取救济 | ||
| 61 | ["gateway_msg.update_event_msg"] = 0x0801, --更新客户端事件 | ||
| 62 | ["gateway_msg.get_event_msg"] = 0x0802, --获取客户端事件 | ||
| 63 | ["gateway_msg.game_fruit_machine_msg"] = 0x0803, --水果机 | ||
| 64 | ["gateway_msg.game_birds_msg"] = 0x0804, --飞禽走兽 | ||
| 65 | ["gateway_msg.notify_mail_msg"] = 0x0901, --通知邮件变化 | ||
| 66 | ["gateway_msg.mail_attachment_msg"] = 0x0902, --领取邮件附件 | ||
| 67 | ["gateway_msg.mail_read_msg"] = 0x0903, --读取邮件 | ||
| 68 | ["gateway_msg.mail_del_msg"] = 0x0904, --删除邮件 | ||
| 69 | ["gateway_msg.mail_share_private_give_msg"] = 0x0906, --分享(朋友/群)赠送邮件 | ||
| 70 | ["gateway_msg.mail_share_public_give_msg"] = 0x0907, --分享(朋友圈)赠送邮件 | ||
| 71 | ["gateway_msg.get_achievement_reward_msg"] = 0x0908, --领取成就达成奖励 | ||
| 72 | ["gateway_msg.lobby_enter_msg"] = 0x1000, --进入大厅 | ||
| 73 | ["gateway_msg.lobby_out_msg"] = 0x1003, --离开大厅 | ||
| 74 | ["gateway_msg.lobby_enter_room_msg"] = 0x1001, --进入房间 | ||
| 75 | ["gateway_msg.notify_user_show_in_room_msg"] = 0x1005, --更新房间里的所有玩家 | ||
| 76 | ["gateway_msg.lobby_out_room_msg"] = 0x1004, --退出房间 | ||
| 77 | ["gateway_msg.lobby_room_ready_msg"] = 0x1002, --准备 | ||
| 78 | ["gateway_msg.gm_change_item_msg"] = 0xf005, --gm 调道具 | ||
| 79 | ["gateway_msg.user_chat_msg"] = 0x1008, --用户聊天 | ||
| 80 | ["gateway_msg.change_head_frame_msg"] = 0x0404, --修改头像框 | ||
| 81 | } | ||
| 82 | |||
| 83 | local proto_id_map_res = | ||
| 84 | { | ||
| 85 | ["gateway_msg.sys_information_msg_res"] = 0xf001, --获取系统时间 | ||
| 86 | ["gateway_msg.sys_notice_msg_res"] = 0xf003, --通知玩家公告 | ||
| 87 | ["gateway_msg.sys_test_msg_res"] = 0xf004, --测试协议 | ||
| 88 | ["gateway_msg.login_msg_res"] = 0x0101, --登录 | ||
| 89 | ["gateway_msg.create_role_msg_res"] = 0x0104, --创建角色 | ||
| 90 | ["gateway_msg.get_rank_msg_res"] = 0x00201, --获取榜单 | ||
| 91 | ["gateway_msg.get_yesterday_reward_rank_msg_res"] = 0x00202, --获取昨天榜单奖励 | ||
| 92 | ["gateway_msg.shop_buy_msg_res"] = 0x00301, --购买道具 | ||
| 93 | ["gateway_msg.pay_get_id_msg_res"] = 0x00350, --获取订单号 | ||
| 94 | ["gateway_msg.notify_pay_succ_msg_res"] = 0x00351, --购买成功 | ||
| 95 | ["gateway_msg.get_pay_day_reward_msg_res"] = 0x00352, --领取购买的每天领取奖励 | ||
| 96 | ["gateway_msg.get_phone_num_msg_res"] = 0x00353, --获取电话号码 | ||
| 97 | ["gateway_msg.change_nick_msg_res"] = 0x0402, --改名字 | ||
| 98 | ["gateway_msg.change_head_msg_res"] = 0x0403, --改头像 | ||
| 99 | ["gateway_msg.get_user_info_msg_res"] = 0x0406, --获取用户信息 | ||
| 100 | ["gateway_msg.furniture_pos_msg_res"] = 0x0408, --设置家具位置 | ||
| 101 | ["gateway_msg.wall_on_msg_res"] = 0x0409, --换上墙纸 | ||
| 102 | ["gateway_msg.notify_task_daily_msg_res"] = 0x00501, --每日任务 | ||
| 103 | ["gateway_msg.get_task_daily_reward_msg_res"] = 0x00502, --领取每日任务 | ||
| 104 | ["gateway_msg.use_item_msg_res"] = 0x00603, --使用道具 | ||
| 105 | ["gateway_msg.notify_win_cnt_msg_res"] = 0x00604, --通知胜利次数变化 | ||
| 106 | ["gateway_msg.notify_lost_cnt_msg_res"] = 0x00605, --通知失败次数变化 | ||
| 107 | ["gateway_msg.notify_item_cnt_max_msg_res"] = 0x0606, --通知道具数量已达上限 | ||
| 108 | ["gateway_msg.sign_msg_res"] = 0x00701, --签到 | ||
| 109 | ["gateway_msg.sign_reward_msg_res"] = 0x00702, --签到领取奖励 | ||
| 110 | ["gateway_msg.sign_update_msg_res"] = 0x00703, --补签 | ||
| 111 | ["gateway_msg.get_role_reward_msg_res"] = 0x00704, --领取7日礼包 | ||
| 112 | ["gateway_msg.get_create_reward_msg_res"] = 0x00705, --领取创建奖励 | ||
| 113 | ["gateway_msg.get_online_reward_msg_res"] = 0x00706, --领取在线礼包 | ||
| 114 | ["gateway_msg.show_btl_cnt_reward_msg_res"] = 0x00707, --新手对局福利展现 | ||
| 115 | ["gateway_msg.get_btl_cnt_reward_msg_res"] = 0x00708, --获取 新手对局福利 | ||
| 116 | ["gateway_msg.get_turntable_reward_msg_res"] = 0x00709, --获取 转盘抽奖 | ||
| 117 | ["gateway_msg.get_turntable_reward_and_login_reward_msg_res"] = 0x0070a, --获取 转盘抽奖和登录奖励 信息 | ||
| 118 | ["gateway_msg.get_relief_msg_res"] = 0x0070b, --领取救济 | ||
| 119 | ["gateway_msg.get_event_msg_res"] = 0x0802, --获取客户端事件 | ||
| 120 | ["gateway_msg.game_fruit_machine_msg_res"] = 0x0803, --水果机 | ||
| 121 | ["gateway_msg.game_birds_msg_res"] = 0x0804, --飞禽走兽 | ||
| 122 | ["gateway_msg.notify_mail_msg_res"] = 0x0901, --通知邮件变化 | ||
| 123 | ["gateway_msg.mail_attachment_msg_res"] = 0x0902, --领取邮件附件 | ||
| 124 | ["gateway_msg.mail_read_msg_res"] = 0x0903, --读取邮件 | ||
| 125 | ["gateway_msg.mail_del_msg_res"] = 0x0904, --删除邮件 | ||
| 126 | ["gateway_msg.mail_share_private_give_msg_res"] = 0x0906, --分享(朋友/群)赠送邮件 | ||
| 127 | ["gateway_msg.mail_share_public_give_msg_res"] = 0x0907, --分享(朋友圈)赠送邮件 | ||
| 128 | ["gateway_msg.get_achievement_reward_msg_res"] = 0x0908, --领取成就达成奖励 | ||
| 129 | ["gateway_msg.notify_item_msg_res"] = 0x0601, --通知道具变化 | ||
| 130 | ["gateway_msg.notify_score_msg_res"] = 0x0602, --通知积分变化 | ||
| 131 | ["gateway_msg.notify_achievement_msg_res"] = 0x0909, --通知客户端成就更新 | ||
| 132 | ["gateway_msg.lobby_enter_msg_res"] = 0x1000, --进入大厅 | ||
| 133 | ["gateway_msg.lobby_out_msg_res"] = 0x1003, --离开大厅 | ||
| 134 | ["gateway_msg.notify_game_data_msg_res"] = 0x100a, --获取游戏数据,(重连后使用该数据) | ||
| 135 | ["gateway_msg.notify_exit_lobby_msg_res"] = 0x1007, --退出大厅 | ||
| 136 | ["gateway_msg.lobby_enter_room_msg_res"] = 0x1001, --进入房间 | ||
| 137 | ["gateway_msg.notify_user_show_in_room_msg_res"] = 0x1005, --更新房间里的所有玩家 | ||
| 138 | ["gateway_msg.lobby_out_room_msg_res"] = 0x1004, --退出房间 | ||
| 139 | ["gateway_msg.lobby_room_ready_msg_res"] = 0x1002, --准备 | ||
| 140 | ["gateway_msg.gm_change_item_msg_res"] = 0xf005, --gm 调道具 | ||
| 141 | ["gateway_msg.user_chat_msg_res"] = 0x1008, --用户聊天 | ||
| 142 | ["gateway_msg.change_head_frame_msg_res"] = 0x0404, --通知头像框改变 | ||
| 143 | ["gateway_msg.notify_game_end_msg_res"] = 0x1006, --游戏结束 | ||
| 144 | } | ||
| 145 | |||
| 146 | local id_proto_map_res = {} | ||
| 147 | |||
| 148 | for proto,id in pairs(proto_id_map_res) do | ||
| 149 | id_proto_map_res[id] = proto | ||
| 150 | end | ||
| 151 | |||
| 152 | for _,file in ipairs(protos) do | ||
| 153 | local fullPath = cc.FileUtils:getInstance():fullPathForFilename(file) | ||
| 154 | print("register pb file:"..fullPath); | ||
| 155 | protobuf.register_file(fullPath); | ||
| 156 | end | ||
| 157 | |||
| 158 | local recv = setmetatable({},eventclass) | ||
| 159 | eventclass.bind(recv,recv) | ||
| 160 | |||
| 161 | local msgqueue = {} | ||
| 162 | local authpackage | ||
| 163 | |||
| 164 | module "cmsg" | ||
| 165 | ----------------------------------------------------------------------------------------------------------------------- | ||
| 166 | |||
| 167 | function recvevent() | ||
| 168 | return recv | ||
| 169 | end | ||
| 170 | |||
| 171 | function msgtoproto(msgid) | ||
| 172 | return id_proto_map_res[msgid] | ||
| 173 | end | ||
| 174 | |||
| 175 | function getauthpackage() | ||
| 176 | return authpackage | ||
| 177 | end | ||
| 178 | |||
| 179 | local function encode(msgid,msgname,data) | ||
| 180 | local msgdata = protobuf.encode(msgname, data) | ||
| 181 | local len = #msgdata + 24; | ||
| 182 | |||
| 183 | -- lua5.1版本的string没有pack函数,是外部lpack包,集成到string里去的, lua5.3版本开始加入string.pack | ||
| 184 | -- <: 设为小端编码 | ||
| 185 | -- >: 设为大端编码 | ||
| 186 | -- =: 大小端遵循本地设置 | ||
| 187 | -- ![n]: 将最大对齐数设为 n (默认遵循本地对齐设置) | ||
| 188 | -- b: 一个有符号字节 (char) | ||
| 189 | -- B: 一个无符号字节 (char) | ||
| 190 | -- h: 一个有符号 short (本地大小) | ||
| 191 | -- H: 一个无符号 short (本地大小) | ||
| 192 | -- l: 一个有符号 long (本地大小) | ||
| 193 | -- L: 一个无符号 long (本地大小) | ||
| 194 | -- j: 一个 lua_Integer | ||
| 195 | -- J: 一个 lua_Unsigned | ||
| 196 | -- T: 一个 size_t (本地大小) | ||
| 197 | -- i[n]: 一个 n 字节长(默认为本地大小)的有符号 int | ||
| 198 | -- I[n]: 一个 n 字节长(默认为本地大小)的无符号 int | ||
| 199 | -- f: 一个 float (本地大小) | ||
| 200 | -- d: 一个 double (本地大小) | ||
| 201 | -- n: 一个 lua_Number | ||
| 202 | -- cn: n字节固定长度的字符串 | ||
| 203 | -- z: 零结尾的字符串 | ||
| 204 | -- s[n]: 长度加内容的字符串,其长度编码为一个 n 字节(默认是个 size_t) 长的无符号整数。 | ||
| 205 | -- x: 一个字节的填充 | ||
| 206 | -- Xop: 按选项 op 的方式对齐(忽略它的其它方面)的一个空条目 | ||
| 207 | -- ' ': (空格)忽略 | ||
| 208 | -- 包头+包体:len(小端,无符号 int) seq(小端,无符号 int) msgid(小端,无符号 int) ret(小端,无符号 int) uid(小端,64位,用两个 无符号int代替) | ||
| 209 | local package = string.pack("<I", len) .. string.pack("<I", 0) .. string.pack("<I", msgid)..string.pack("<I", 0) ..string.pack("<I", 0)..string.pack("<I", 0) .. msgdata; | ||
| 210 | return package | ||
| 211 | end | ||
| 212 | |||
| 213 | local function send_request(package) | ||
| 214 | if socket_tcp.connected() then | ||
| 215 | socket_tcp.send(package) | ||
| 216 | else | ||
| 217 | table.insert(msgqueue,package) | ||
| 218 | end | ||
| 219 | end | ||
| 220 | |||
| 221 | function hasqueuemessage() | ||
| 222 | if #msgqueue > 0 then | ||
| 223 | return true | ||
| 224 | else | ||
| 225 | return false | ||
| 226 | end | ||
| 227 | end | ||
| 228 | |||
| 229 | function clearqueue() | ||
| 230 | msgqueue = {} | ||
| 231 | end | ||
| 232 | |||
| 233 | function flushqueue() | ||
| 234 | if socket_tcp.connected() then | ||
| 235 | for _,package in ipairs(msgqueue) do | ||
| 236 | socket_tcp.send(package) | ||
| 237 | end | ||
| 238 | end | ||
| 239 | |||
| 240 | msgqueue = {} | ||
| 241 | end | ||
| 242 | |||
| 243 | --simulate client message response | ||
| 244 | function debugSend(msg,data) | ||
| 245 | local recv = cmsg.recvevent() | ||
| 246 | |||
| 247 | print(msg) | ||
| 248 | print(data) | ||
| 249 | |||
| 250 | delayCall(5,function() | ||
| 251 | recv:dispatchEvent({name = msg,data = "12111"}) | ||
| 252 | end) | ||
| 253 | end | ||
| 254 | |||
| 255 | local timeout_id = {} | ||
| 256 | |||
| 257 | function send(msg,data,timeOutFun) | ||
| 258 | local debugsocket = false; | ||
| 259 | if debugsocket then | ||
| 260 | debugSend(msg,data) | ||
| 261 | else | ||
| 262 | local msgid = proto_id_map_send[msg] | ||
| 263 | |||
| 264 | if msgid == nil then | ||
| 265 | print("unknown msg: not registered",msg) | ||
| 266 | return | ||
| 267 | end | ||
| 268 | |||
| 269 | local delayID = delayCall(10,function() | ||
| 270 | if timeOutFun then | ||
| 271 | timeOutFun(); | ||
| 272 | end | ||
| 273 | EventListener.dispatchEvent("net_timeout",{msg=msg}); | ||
| 274 | end); | ||
| 275 | |||
| 276 | timeout_id[tostring(msgid)] = delayID; | ||
| 277 | |||
| 278 | send_request(encode(msgid,msg,data)) | ||
| 279 | end | ||
| 280 | end | ||
| 281 | |||
| 282 | local tag = 1 | ||
| 283 | local listenertag = {} | ||
| 284 | |||
| 285 | function on(eventName, listener) | ||
| 286 | local function _listener(event) | ||
| 287 | listener(event.data) | ||
| 288 | end | ||
| 289 | |||
| 290 | tag = tag + 1 | ||
| 291 | listenertag[listener] = tag | ||
| 292 | |||
| 293 | recv:addEventListener(eventName,_listener,tag) | ||
| 294 | end | ||
| 295 | |||
| 296 | function off(eventName, listener) | ||
| 297 | local tag = listenertag[listener] | ||
| 298 | |||
| 299 | if not tag then | ||
| 300 | return | ||
| 301 | end | ||
| 302 | |||
| 303 | recv:removeEventListenersByTag(tag) | ||
| 304 | listenertag[listener] = nil | ||
| 305 | end | ||
| 306 | |||
| 307 | function handlemsg(msgid,msgname,data) | ||
| 308 | local handler = recv.listeners_[string.upper(msgname)]; | ||
| 309 | if handler then | ||
| 310 | if DEBUG == 1 then | ||
| 311 | if msgname ~= "gateway_msg.sys_information_msg_res" then | ||
| 312 | local dataStr = json.encode(data); | ||
| 313 | logD("<<<<<<<<<<<<<<<\nMSGNAME:["..msgname.."]\n DATA:"..dataStr); | ||
| 314 | end | ||
| 315 | -- logUI("MSGNAME:["..msgname.."]"); | ||
| 316 | end | ||
| 317 | recv:dispatchEvent({name = msgname,data = data}); | ||
| 318 | else | ||
| 319 | print("unhandle message",msgname) | ||
| 320 | end | ||
| 321 | |||
| 322 | if timeout_id[tostring(msgid)] then | ||
| 323 | -- print("remove msg delay id:"..timeout_id[tostring(msgid)]); | ||
| 324 | removeDelay(timeout_id[tostring(msgid)]); | ||
| 325 | timeout_id[tostring(msgid)] = nil; | ||
| 326 | end | ||
| 327 | end | ||
| 328 |
| 1 | local socket = require("socket.core") | ||
| 2 | |||
| 3 | local cc = cc; | ||
| 4 | local print = print; | ||
| 5 | local string = string; | ||
| 6 | local assert = assert; | ||
| 7 | local PROXY_SOCK_ADDR = PROXY_SOCK_ADDR; | ||
| 8 | |||
| 9 | local SOCKET_READ_TICK = 0.1 -- check socket data interval | ||
| 10 | local SOCKET_CONNECT_TICK = 1 | ||
| 11 | local SOCKET_RECONNECT_TIME = 1 -- socket reconnect try interval | ||
| 12 | local SOCKET_CONNECT_FAIL_TIMEOUT = 5 -- socket failure timeout | ||
| 13 | |||
| 14 | local STATUS_CLOSED = "closed" | ||
| 15 | local STATUS_NOT_CONNECTED = "Socket is not connected" | ||
| 16 | local STATUS_ALREADY_CONNECTED = "already connected" | ||
| 17 | |||
| 18 | local host = "" | ||
| 19 | local port = 0 | ||
| 20 | local tickScheduler = nil -- timer for data | ||
| 21 | local reconnectScheduler = nil -- timer for reconnect | ||
| 22 | local connectTimeTickScheduler = nil -- timer for connect timeout | ||
| 23 | local name = 'socket tcp client' | ||
| 24 | local tcp = nil | ||
| 25 | local isRetryConnect = true | ||
| 26 | local retrytimes = 0 | ||
| 27 | local isConnected = false | ||
| 28 | local scheduler = cc.Director:getInstance():getScheduler() | ||
| 29 | local waitConnect | ||
| 30 | |||
| 31 | module "socket_tcp" | ||
| 32 | |||
| 33 | local _onData | ||
| 34 | local _onClose | ||
| 35 | local _onConnect | ||
| 36 | local _onConnectError | ||
| 37 | |||
| 38 | local function close() | ||
| 39 | tcp:close() | ||
| 40 | |||
| 41 | if connectTimeTickScheduler then | ||
| 42 | scheduler:unscheduleScriptEntry(connectTimeTickScheduler) | ||
| 43 | connectTimeTickScheduler = nil | ||
| 44 | end | ||
| 45 | |||
| 46 | if tickScheduler then | ||
| 47 | scheduler:unscheduleScriptEntry(tickScheduler) | ||
| 48 | tickScheduler = nil | ||
| 49 | end | ||
| 50 | |||
| 51 | if isConnected and _onClose ~= nil then | ||
| 52 | _onClose() | ||
| 53 | end | ||
| 54 | end | ||
| 55 | |||
| 56 | -- if connection is initiative, do not reconnect | ||
| 57 | local function _reconnect() | ||
| 58 | if not isRetryConnect then | ||
| 59 | return | ||
| 60 | end | ||
| 61 | |||
| 62 | if connecttimeout() then | ||
| 63 | return | ||
| 64 | end | ||
| 65 | |||
| 66 | retrytimes = retrytimes + 1 | ||
| 67 | |||
| 68 | if reconnectScheduler then | ||
| 69 | scheduler:unscheduleScriptEntry(reconnectScheduler) | ||
| 70 | end | ||
| 71 | |||
| 72 | local __doReConnect = function () | ||
| 73 | scheduler:unscheduleScriptEntry(reconnectScheduler) | ||
| 74 | reconnectScheduler = nil | ||
| 75 | |||
| 76 | connect() | ||
| 77 | end | ||
| 78 | |||
| 79 | reconnectScheduler = scheduler:scheduleScriptFunc(__doReConnect, SOCKET_RECONNECT_TIME,false) | ||
| 80 | end | ||
| 81 | |||
| 82 | function connecttimeout() | ||
| 83 | if retrytimes > 3 then | ||
| 84 | return true | ||
| 85 | end | ||
| 86 | |||
| 87 | return false | ||
| 88 | end | ||
| 89 | |||
| 90 | -- connecte success, cancel the connection timerout timer | ||
| 91 | local function _onConnected() | ||
| 92 | isConnected = true | ||
| 93 | retrytimes = 0 | ||
| 94 | |||
| 95 | if _onConnect ~= nil then | ||
| 96 | _onConnect() | ||
| 97 | end | ||
| 98 | |||
| 99 | if connectTimeTickScheduler then | ||
| 100 | scheduler:unscheduleScriptEntry(connectTimeTickScheduler) | ||
| 101 | connectTimeTickScheduler = nil | ||
| 102 | end | ||
| 103 | |||
| 104 | local __tick = function() | ||
| 105 | while true do | ||
| 106 | local __body, __status, __partial = tcp:receive("*a") | ||
| 107 | |||
| 108 | if __status == STATUS_CLOSED or __status == STATUS_NOT_CONNECTED then | ||
| 109 | close() | ||
| 110 | |||
| 111 | if isConnected then | ||
| 112 | isConnected = false | ||
| 113 | -- _reconnect() | ||
| 114 | end | ||
| 115 | |||
| 116 | return | ||
| 117 | end | ||
| 118 | |||
| 119 | if (__body and string.len(__body) == 0) or (__partial and string.len(__partial) == 0) then return end | ||
| 120 | |||
| 121 | if __body and __partial then | ||
| 122 | __body = __body .. __partial | ||
| 123 | end | ||
| 124 | |||
| 125 | if _onData ~= nil then | ||
| 126 | _onData(__partial or __body) | ||
| 127 | end | ||
| 128 | end | ||
| 129 | end | ||
| 130 | |||
| 131 | -- start to read TCP data | ||
| 132 | tickScheduler = scheduler:scheduleScriptFunc(__tick, SOCKET_READ_TICK,false) | ||
| 133 | end | ||
| 134 | |||
| 135 | function setCallback(onData,onConnect,onConnectError,onClose) | ||
| 136 | _onData = onData | ||
| 137 | _onClose = onClose | ||
| 138 | _onConnect = onConnect | ||
| 139 | _onConnectError = onConnectError | ||
| 140 | |||
| 141 | retrytimes = 0 | ||
| 142 | end | ||
| 143 | |||
| 144 | function connected() | ||
| 145 | return isConnected | ||
| 146 | end | ||
| 147 | |||
| 148 | function connect(__host, __port, __retryConnectWhenFailure) | ||
| 149 | if __host then host = __host end | ||
| 150 | if __port then port = __port end | ||
| 151 | if __retryConnectWhenFailure ~= nil then isRetryConnect = __retryConnectWhenFailure end | ||
| 152 | |||
| 153 | print("connect to ",host,":",port) | ||
| 154 | tcp = socket.tcp() | ||
| 155 | tcp:settimeout(0) | ||
| 156 | |||
| 157 | local function __checkConnect() | ||
| 158 | print("连接sock代理服务器地址:",PROXY_SOCK_ADDR); | ||
| 159 | local __succ, __status; | ||
| 160 | if PROXY_SOCK_ADDR and PROXY_SOCK_ADDR ~= "" then | ||
| 161 | __succ, __status = tcp:connect(host, port,PROXY_SOCK_ADDR); | ||
| 162 | else | ||
| 163 | __succ, __status = tcp:connect(host, port); | ||
| 164 | end | ||
| 165 | if __succ == 1 or __status == STATUS_ALREADY_CONNECTED then | ||
| 166 | _onConnected() | ||
| 167 | end | ||
| 168 | |||
| 169 | return __succ | ||
| 170 | end | ||
| 171 | |||
| 172 | --start connect timer | ||
| 173 | if not __checkConnect() then | ||
| 174 | local __connectTimeTick = function () | ||
| 175 | if isConnected then return end | ||
| 176 | |||
| 177 | waitConnect = waitConnect or 0 | ||
| 178 | waitConnect = waitConnect + SOCKET_CONNECT_TICK | ||
| 179 | |||
| 180 | if waitConnect >= SOCKET_CONNECT_FAIL_TIMEOUT then | ||
| 181 | waitConnect = nil | ||
| 182 | close() | ||
| 183 | |||
| 184 | if _onConnectError ~= nil then | ||
| 185 | _onConnectError() | ||
| 186 | end | ||
| 187 | |||
| 188 | _reconnect() | ||
| 189 | else | ||
| 190 | __checkConnect() | ||
| 191 | end | ||
| 192 | end | ||
| 193 | |||
| 194 | connectTimeTickScheduler = scheduler:scheduleScriptFunc(__connectTimeTick, SOCKET_CONNECT_TICK,false) | ||
| 195 | end | ||
| 196 | end | ||
| 197 | |||
| 198 | -- disconnect on user's own initiative. | ||
| 199 | function disconnect() | ||
| 200 | setCallback(nil,nil,nil,nil) | ||
| 201 | |||
| 202 | close() | ||
| 203 | isConnected = false | ||
| 204 | isRetryConnect = false -- initiative to disconnect, no reconnect. | ||
| 205 | |||
| 206 | tcp:shutdown() | ||
| 207 | end | ||
| 208 | |||
| 209 | local senddata = "" | ||
| 210 | |||
| 211 | function send(__data) | ||
| 212 | if not isConnected then | ||
| 213 | return | ||
| 214 | end | ||
| 215 | |||
| 216 | if senddata ~= "" then | ||
| 217 | senddata = senddata .. __data | ||
| 218 | else | ||
| 219 | local n = #__data | ||
| 220 | local ok,reason,sended = tcp:send(__data) | ||
| 221 | |||
| 222 | if not ok and reason == "timeout" and sended < n then | ||
| 223 | senddata = string.sub(__data,sended + 1,-1) | ||
| 224 | end | ||
| 225 | end | ||
| 226 | end | ||
| 227 | |||
| 228 | local function checksend() | ||
| 229 | if not isConnected then | ||
| 230 | return | ||
| 231 | end | ||
| 232 | |||
| 233 | local n = #senddata | ||
| 234 | |||
| 235 | if n == 0 then | ||
| 236 | return | ||
| 237 | end | ||
| 238 | |||
| 239 | local ok,reason,sended = tcp:send(senddata) | ||
| 240 | |||
| 241 | if not ok and reason == "timeout" and sended < n then | ||
| 242 | senddata = string.sub(senddata,sended + 1,-1) | ||
| 243 | else | ||
| 244 | senddata = "" | ||
| 245 | end | ||
| 246 | end | ||
| 247 | |||
| 248 | cc.Director:getInstance():getScheduler():scheduleScriptFunc(checksend,0,false) | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
client/rubbish/client/src/core/ui/align.lua
0 → 100644
| 1 | --[[ | ||
| 2 | @Author : z_h | ||
| 3 | @Date : 2016-06-20 14:58:54 | ||
| 4 | @Content : align,对齐相关 | ||
| 5 | --]] | ||
| 6 | |||
| 7 | local director = cc.Director:getInstance() | ||
| 8 | local point = cc.p | ||
| 9 | |||
| 10 | module("align") | ||
| 11 | |||
| 12 | win_size = director:getWinSize() | ||
| 13 | win_width = win_size.width | ||
| 14 | win_height = win_size.height | ||
| 15 | win_center = point(win_width / 2, win_height / 2) |
client/rubbish/client/src/core/ui/dialog.lua
0 → 100644
| 1 | --[[ | ||
| 2 | @Author : z_h | ||
| 3 | @Date : 2016-06-20 10:00:19 | ||
| 4 | @Content : | ||
| 5 | --]] | ||
| 6 | |||
| 7 | local director = cc.Director:getInstance() | ||
| 8 | local size = director:getWinSize() | ||
| 9 | local dispatcher = director:getEventDispatcher() | ||
| 10 | |||
| 11 | module("dialog", package.seeall) | ||
| 12 | |||
| 13 | ZORDER_APP = 100 | ||
| 14 | ZORDER_POP = 1000 | ||
| 15 | |||
| 16 | uinode = function(path, ...) | ||
| 17 | local creator = function() return cc.CSLoader:createNode(path) end | ||
| 18 | local cls_name = string.format("uinode(%s)", path) | ||
| 19 | local cls = class(cls_name, creator, ...) | ||
| 20 | |||
| 21 | return cls | ||
| 22 | end | ||
| 23 | |||
| 24 | uilayer = function(path, ...) | ||
| 25 | local creator = function() | ||
| 26 | local node = cc.CSLoader:createNode(path):setContentSize(size) | ||
| 27 | ccui.Helper:doLayout(node) | ||
| 28 | return node | ||
| 29 | end | ||
| 30 | local cls_name = string.format("uilayer(%s)", path) | ||
| 31 | local cls = class(cls_name, creator, ...) | ||
| 32 | |||
| 33 | return cls | ||
| 34 | end | ||
| 35 | |||
| 36 | |||
| 37 | local _bg = nil | ||
| 38 | local _stack = {} | ||
| 39 | local _scene = nil | ||
| 40 | |||
| 41 | |||
| 42 | local function attachToScene(scene) | ||
| 43 | _scene = scene | ||
| 44 | _stack = {} | ||
| 45 | if tolua.isnull(_bg) then | ||
| 46 | _bg = cc.LayerColor:create(cc.c4b(0, 0, 0, 200)) | ||
| 47 | local listener = cc.EventListenerTouchOneByOne:create() | ||
| 48 | listener:registerScriptHandler(function() return true end, | ||
| 49 | cc.Handler.EVENT_TOUCH_BEGAN) | ||
| 50 | listener:setSwallowTouches(true) | ||
| 51 | dispatcher:addEventListenerWithSceneGraphPriority(listener, _bg) | ||
| 52 | end | ||
| 53 | _bg:retain() | ||
| 54 | if _bg:getParent() then | ||
| 55 | _bg:removeFromParent(true) | ||
| 56 | end | ||
| 57 | end | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
client/rubbish/client/src/core/ui/init.lua
0 → 100644
| 1 | --[[ | ||
| 2 | --新写的纯lua热更新 新特征 | ||
| 3 | --1.用户下载新版本,删除老版本的热更内容 | ||
| 4 | --2.纯lua实现,不依赖同城游引擎接口 | ||
| 5 | --3.Android和IOS上未测试过 | ||
| 6 | |||
| 7 | 使用方法: | ||
| 8 | local AssetsUpdate = require("ctkj.utils.AssetsUpdate"); | ||
| 9 | AssetsUpdate.init(updateSuccessCallback,updateProgressCallback,updateFailedCallback); | ||
| 10 | --]] | ||
| 11 | |||
| 12 | local AssetsUpdate = class("AssetsUpdate") | ||
| 13 | |||
| 14 | AssetsUpdate.VERSION_NUM = 0; --当前安装包版本号,用于热更新 | ||
| 15 | AssetsUpdate.localUpdateVersion = 0; --本地热更版本号(热更新过后的版本号) | ||
| 16 | AssetsUpdate.newVersion = 0; --服务器上的最新版本号 | ||
| 17 | |||
| 18 | |||
| 19 | AssetsUpdate.gameid = "yxdt" --游戏名缩写 | ||
| 20 | AssetsUpdate.platform = "android" --平台 | ||
| 21 | AssetsUpdate.isEncrypt = 1; | ||
| 22 | |||
| 23 | AssetsUpdate.updateResList = {}; | ||
| 24 | AssetsUpdate.updateResProgress = 1; | ||
| 25 | |||
| 26 | local newFilelistData = nil; | ||
| 27 | local filelistLocal = {}; | ||
| 28 | local filelistServer = {}; | ||
| 29 | |||
| 30 | local UPDATE_PATH_NAME = "GameUpdate/"..AssetsUpdate.gameid.."_"..CHANNEL; | ||
| 31 | |||
| 32 | function AssetsUpdate.init(updateSuccessCallback,updateProgressCallback,updateFailedCallback) | ||
| 33 | AssetsUpdate.updateSuccessCallback,AssetsUpdate.updateProgressCallback,AssetsUpdate.updateFailedCallback = updateSuccessCallback,updateProgressCallback,updateFailedCallback; | ||
| 34 | |||
| 35 | local targetPlatform = cc.Application:getInstance():getTargetPlatform(); | ||
| 36 | if targetPlatform == cc.PLATFORM_OS_IPHONE or targetPlatform == cc.PLATFORM_OS_IPAD then | ||
| 37 | AssetsUpdate.platform = "ios"; | ||
| 38 | elseif targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 39 | AssetsUpdate.platform = "android"; | ||
| 40 | elseif targetPlatform == cc.PLATFORM_OS_WINDOWS then | ||
| 41 | AssetsUpdate.platform = "win"; | ||
| 42 | AssetsUpdate.isEncrypt = 0; | ||
| 43 | end | ||
| 44 | |||
| 45 | if cc.UserDefault:getInstance():getStringForKey("versionnum") ~= "" then | ||
| 46 | AssetsUpdate.localUpdateVersion = tonumber(cc.UserDefault:getInstance():getStringForKey("versionnum")); | ||
| 47 | else | ||
| 48 | AssetsUpdate.localUpdateVersion = 0; | ||
| 49 | end | ||
| 50 | logUI("本地更新版本:"..AssetsUpdate.localUpdateVersion); | ||
| 51 | |||
| 52 | local versionnumFullPath = cc.FileUtils:getInstance():fullPathForFilename('res/versionnum.txt'); | ||
| 53 | local versionnumStr = cc.FileUtils:getInstance():getStringFromFile(versionnumFullPath); | ||
| 54 | local function readLine(str) | ||
| 55 | if str ~= "" then | ||
| 56 | AssetsUpdate.VERSION_NUM = tonumber(str); | ||
| 57 | end | ||
| 58 | end | ||
| 59 | readLine(versionnumStr); | ||
| 60 | logUI("安装包版本:"..AssetsUpdate.VERSION_NUM); | ||
| 61 | |||
| 62 | AssetsUpdate.server = "http://game.topdraw.com.cn/"..AssetsUpdate.gameid.."/"..CHANNEL.."/"..AssetsUpdate.platform.."/"..DeviceUtil.getAppVersionName().."/"; | ||
| 63 | AssetsUpdate.rootPath = cc.FileUtils:getInstance():getWritablePath(); | ||
| 64 | AssetsUpdate.resPath = AssetsUpdate.rootPath..UPDATE_PATH_NAME .. "/"; | ||
| 65 | if not (cc.FileUtils:getInstance():isDirectoryExist(AssetsUpdate.resPath)) then | ||
| 66 | cc.FileUtils:getInstance():createDirectory(AssetsUpdate.resPath); | ||
| 67 | end | ||
| 68 | |||
| 69 | --版本比较 | ||
| 70 | AssetsUpdate.checkVersions(); | ||
| 71 | -- AssetsUpdate.timeoutID = cc.Director:getInstance():getScheduler():scheduleScriptFunc(handler(AssetsUpdate, AssetsUpdate.timeOut), 1, false); --超时处理 | ||
| 72 | end | ||
| 73 | |||
| 74 | local function setSearchUpdatePath() | ||
| 75 | --不能在判断本地版本和服务器版本之前设置搜索路径 | ||
| 76 | --因为热更本地版本是最新发布的版本,需要删除之前热更新的目录 | ||
| 77 | local searchPaths = cc.FileUtils:getInstance():getSearchPaths(); | ||
| 78 | table.insert(searchPaths,1,AssetsUpdate.resPath); | ||
| 79 | table.insert(searchPaths,2,AssetsUpdate.resPath .. 'res/'); | ||
| 80 | table.insert(searchPaths,3,AssetsUpdate.resPath .. 'src/'); | ||
| 81 | cc.FileUtils:getInstance():setSearchPaths(searchPaths); | ||
| 82 | end | ||
| 83 | |||
| 84 | --更新本地版本号 | ||
| 85 | local function setVersion() | ||
| 86 | AssetsUpdate.newVersion = AssetsUpdate.newVersion or "1"; | ||
| 87 | cc.UserDefault:getInstance():setStringForKey("versionnum", AssetsUpdate.newVersion); | ||
| 88 | cc.UserDefault:getInstance():flush(); | ||
| 89 | end | ||
| 90 | |||
| 91 | --更新失败 | ||
| 92 | local function updateFailed() | ||
| 93 | if AssetsUpdate.localUpdateVersion > AssetsUpdate.VERSION_NUM then | ||
| 94 | logUI("热更失败,本地热更版本大于原始包版本:"..AssetsUpdate.localUpdateVersion); | ||
| 95 | else | ||
| 96 | logUI("热更失败,没有热更过版本:"..AssetsUpdate.VERSION_NUM); | ||
| 97 | end | ||
| 98 | |||
| 99 | setSearchUpdatePath(); | ||
| 100 | if AssetsUpdate.updateFailedCallback then | ||
| 101 | AssetsUpdate.updateFailedCallback(); | ||
| 102 | end | ||
| 103 | |||
| 104 | if AssetsUpdate.timeoutID ~= nil then | ||
| 105 | cc.Director:getInstance():getScheduler():unscheduleScriptEntry(AssetsUpdate.timeoutID); | ||
| 106 | AssetsUpdate.timeoutID = nil; | ||
| 107 | end | ||
| 108 | end | ||
| 109 | |||
| 110 | --更新进度(需要更新的文件数量) | ||
| 111 | local function updateProgress(_count, _total, _filename) | ||
| 112 | if AssetsUpdate.updateProgressCallback then | ||
| 113 | AssetsUpdate.updateProgressCallback({count = _count,total = _total,filename=_filename}); | ||
| 114 | end | ||
| 115 | end | ||
| 116 | |||
| 117 | --更新完成 | ||
| 118 | local function updateSuccess() | ||
| 119 | logUI("热更新成功,热更版本号:"..AssetsUpdate.newVersion); | ||
| 120 | setVersion(); | ||
| 121 | setSearchUpdatePath(); | ||
| 122 | if AssetsUpdate.updateSuccessCallback then | ||
| 123 | AssetsUpdate.updateSuccessCallback(); | ||
| 124 | end | ||
| 125 | |||
| 126 | if AssetsUpdate.timeoutID ~= nil then | ||
| 127 | cc.Director:getInstance():getScheduler():unscheduleScriptEntry(AssetsUpdate.timeoutID) | ||
| 128 | AssetsUpdate.timeoutID = nil | ||
| 129 | end | ||
| 130 | end | ||
| 131 | |||
| 132 | --版本比较 | ||
| 133 | function AssetsUpdate.checkVersions() | ||
| 134 | local xhr = cc.XMLHttpRequest:new(); | ||
| 135 | xhr.responseType = 0; --string类型 | ||
| 136 | xhr:open("GET", AssetsUpdate.server.."version.txt"); --感觉POST方式会自动在http://后加www,由于公司热更新服务器域名没有解析www所以改成GET方式 | ||
| 137 | |||
| 138 | local scheduler = cc.Director:getInstance():getScheduler(); | ||
| 139 | AssetsUpdate.timeoutID = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function () | ||
| 140 | xhr:unregisterScriptHandler(); | ||
| 141 | updateFailed(); | ||
| 142 | end, 5,false); | ||
| 143 | |||
| 144 | local function onReadyStateChange() | ||
| 145 | if xhr.readyState == 4 and (xhr.status >= 200 and xhr.status < 207) then | ||
| 146 | local confingArr = AssetsUpdate.string_split(xhr.response, "\n"); | ||
| 147 | if #confingArr >= 1 then | ||
| 148 | local verArr = AssetsUpdate.string_split(confingArr[1], "="); | ||
| 149 | AssetsUpdate.newVersion = tonumber(verArr[2]); | ||
| 150 | logUI("localUpdateVersion:"..AssetsUpdate.localUpdateVersion.." newVersion:"..AssetsUpdate.newVersion); | ||
| 151 | if AssetsUpdate.VERSION_NUM > AssetsUpdate.newVersion then | ||
| 152 | logUI("新版本,删除上个版本热更新的目录"); | ||
| 153 | cc.FileUtils:getInstance():removeDirectory(AssetsUpdate.resPath); | ||
| 154 | if AssetsUpdate.updateSuccessCallback then | ||
| 155 | AssetsUpdate.updateSuccessCallback(); | ||
| 156 | end | ||
| 157 | elseif AssetsUpdate.newVersion == AssetsUpdate.localUpdateVersion or AssetsUpdate.newVersion == AssetsUpdate.VERSION_NUM then | ||
| 158 | logUI("版本一致不需要更新"); | ||
| 159 | updateSuccess(); | ||
| 160 | else | ||
| 161 | logUI("查找需要更新的资源并下载"); | ||
| 162 | setSearchUpdatePath(); | ||
| 163 | AssetsUpdate.checkUpdateRes(); | ||
| 164 | end | ||
| 165 | else | ||
| 166 | logUI("更新失败,热更新信息格式错误:"..AssetsUpdate.server.."version.txt"); | ||
| 167 | updateFailed(); | ||
| 168 | end | ||
| 169 | else | ||
| 170 | logUI("更新失败,资源不存在:"..AssetsUpdate.server.."version.txt"); | ||
| 171 | logUI("删除上个版本热更新的目录"); | ||
| 172 | cc.FileUtils:getInstance():removeDirectory(AssetsUpdate.resPath); | ||
| 173 | updateFailed(); | ||
| 174 | end | ||
| 175 | if AssetsUpdate.timeoutID ~= nil then | ||
| 176 | cc.Director:getInstance():getScheduler():unscheduleScriptEntry(AssetsUpdate.timeoutID) | ||
| 177 | AssetsUpdate.timeoutID = nil | ||
| 178 | end | ||
| 179 | xhr:unregisterScriptHandler(); | ||
| 180 | end | ||
| 181 | xhr:registerScriptHandler(onReadyStateChange); | ||
| 182 | xhr:send(); | ||
| 183 | end | ||
| 184 | |||
| 185 | local function getFileList(_path,_list) | ||
| 186 | local _str = cc.FileUtils:getInstance():getStringFromFile(_path); | ||
| 187 | local function readLineFun(lineStr) | ||
| 188 | local contents = StringUtil.split(lineStr,','); | ||
| 189 | if #contents > 1 then | ||
| 190 | _list[contents[1]] = contents[2]; | ||
| 191 | end | ||
| 192 | end | ||
| 193 | |||
| 194 | local index = 1; | ||
| 195 | local function readLine(str) | ||
| 196 | local a,b = string.find(str,"\n"); | ||
| 197 | if a then | ||
| 198 | local lineStr = string.sub(str,1,a-1); | ||
| 199 | readLineFun(lineStr); | ||
| 200 | |||
| 201 | index = index + 1; | ||
| 202 | str = string.sub(str,b+1); | ||
| 203 | readLine(str); | ||
| 204 | else | ||
| 205 | readLineFun(str); | ||
| 206 | end | ||
| 207 | end | ||
| 208 | readLine(_str); | ||
| 209 | end | ||
| 210 | |||
| 211 | --查找更新资源 | ||
| 212 | function AssetsUpdate.checkUpdateRes() | ||
| 213 | local fullPath = cc.FileUtils:getInstance():fullPathForFilename('filelist.txt'); | ||
| 214 | getFileList(fullPath,filelistLocal); | ||
| 215 | |||
| 216 | local xhr = cc.XMLHttpRequest:new(); | ||
| 217 | xhr.responseType = 0; | ||
| 218 | xhr:open("GET", AssetsUpdate.server.."update/".."filelist.txt"); | ||
| 219 | local function onReadyStateChange() | ||
| 220 | if xhr.readyState == 4 and (xhr.status >= 200 and xhr.status < 207) then | ||
| 221 | newFilelistData = xhr.response; | ||
| 222 | AssetsUpdate.writeResToLocal("filelist_temp.txt",xhr.response); | ||
| 223 | local fullPath = AssetsUpdate.resPath .. "filelist_temp.txt"; | ||
| 224 | local file = io.open(fullPath,'r'); | ||
| 225 | if file then | ||
| 226 | local function readServerFilelist() | ||
| 227 | local txt = file:read("*l") | ||
| 228 | if txt ~= nil then | ||
| 229 | local lines = AssetsUpdate.string_split(txt, ","); | ||
| 230 | filelistServer[lines[1]] = lines[2]; | ||
| 231 | return readServerFilelist() | ||
| 232 | end | ||
| 233 | end | ||
| 234 | readServerFilelist(); | ||
| 235 | io.close(file); | ||
| 236 | else | ||
| 237 | print('filelist.txt read error!') | ||
| 238 | end | ||
| 239 | AssetsUpdate.updateResProgress = 1; | ||
| 240 | AssetsUpdate.updateResList = AssetsUpdate.getUpdateResList(); | ||
| 241 | local len = #AssetsUpdate.updateResList; | ||
| 242 | if len > 0 then | ||
| 243 | updateProgress(0, len,AssetsUpdate.updateResList[1]); | ||
| 244 | end | ||
| 245 | AssetsUpdate.downloadRes(); | ||
| 246 | else | ||
| 247 | logUI("更新失败,资源不存在:"..AssetsUpdate.server.."update/".."filelist.txt"); | ||
| 248 | updateFailed(); | ||
| 249 | end | ||
| 250 | end | ||
| 251 | xhr:registerScriptHandler(onReadyStateChange) | ||
| 252 | xhr:send(); | ||
| 253 | end | ||
| 254 | |||
| 255 | --查找需要更新资源表(更新与新增,没考虑删除) | ||
| 256 | function AssetsUpdate.getUpdateResList() | ||
| 257 | local addResTable = {} | ||
| 258 | |||
| 259 | for key1, var1 in pairs(filelistServer) do | ||
| 260 | local key = key1; | ||
| 261 | if AssetsUpdate.isEncrypt == 1 then | ||
| 262 | if string.sub(key1,string.len(key1)-3,string.len(key1)) == ".lua" then | ||
| 263 | key = key1.."c"; | ||
| 264 | end | ||
| 265 | end | ||
| 266 | if filelistLocal[key1] then | ||
| 267 | if var1 ~= filelistLocal[key1] and key1 ~= "res/filelist.txt" then | ||
| 268 | table.insert(addResTable,key) | ||
| 269 | end | ||
| 270 | else | ||
| 271 | table.insert(addResTable,key) | ||
| 272 | end | ||
| 273 | end | ||
| 274 | |||
| 275 | return addResTable; | ||
| 276 | end | ||
| 277 | |||
| 278 | --下载更新资源 | ||
| 279 | function AssetsUpdate.downloadRes() | ||
| 280 | local fileName = AssetsUpdate.updateResList[AssetsUpdate.updateResProgress] | ||
| 281 | if fileName then | ||
| 282 | local xhr = cc.XMLHttpRequest:new() | ||
| 283 | -- xhr:open("GET", AssetsUpdate.server..AssetsUpdate.newVersion.."/"..fileName); | ||
| 284 | xhr:open("GET", AssetsUpdate.server.."update/"..fileName); | ||
| 285 | |||
| 286 | local function onReadyStateChange() | ||
| 287 | if xhr.readyState == 4 and (xhr.status >= 200 and xhr.status < 207) then | ||
| 288 | local index = AssetsUpdate.string_lastIndexOf(fileName, "/"); | ||
| 289 | local updatePath = string.sub(fileName, 1, index); | ||
| 290 | local file = string.sub(fileName, index + 1); | ||
| 291 | index = AssetsUpdate.string_lastIndexOf(file, "."); | ||
| 292 | local fileName1 = string.sub(file, 1, index - 1); | ||
| 293 | local fileExtend1 = string.sub(file, index); | ||
| 294 | |||
| 295 | print("下载更新资源:"..fileName1); | ||
| 296 | local result = AssetsUpdate.writeResToLocal(updatePath..fileName1.."_temp"..fileExtend1,xhr.response); | ||
| 297 | if result then | ||
| 298 | print("count:"..AssetsUpdate.updateResProgress..",name:"..fileName); | ||
| 299 | updateProgress(AssetsUpdate.updateResProgress, #AssetsUpdate.updateResList,fileName); | ||
| 300 | AssetsUpdate.updateResProgress = AssetsUpdate.updateResProgress + 1; | ||
| 301 | AssetsUpdate.downloadRes(); | ||
| 302 | end | ||
| 303 | else | ||
| 304 | logUI("更新失败,资源不存在:"..fileName); | ||
| 305 | updateFailed(); | ||
| 306 | end | ||
| 307 | end | ||
| 308 | xhr:registerScriptHandler(onReadyStateChange); | ||
| 309 | xhr:send(); | ||
| 310 | else | ||
| 311 | print("更新完成,进入游戏"); | ||
| 312 | local req = {}; | ||
| 313 | for i,path in ipairs(AssetsUpdate.updateResList) do | ||
| 314 | local index = AssetsUpdate.string_lastIndexOf(path, "/"); | ||
| 315 | local updatePath = string.sub(path, 1, index); | ||
| 316 | local resname = string.sub(path, index + 1); | ||
| 317 | index = AssetsUpdate.string_lastIndexOf(resname, "."); | ||
| 318 | local fileName1 = string.sub(resname, 1, index - 1); | ||
| 319 | local fileExtend1 = string.sub(resname, index); | ||
| 320 | if cc.FileUtils:getInstance():isFileExist(AssetsUpdate.resPath ..updatePath..fileName1.."_temp"..fileExtend1) then | ||
| 321 | cc.FileUtils:getInstance():renameFile(AssetsUpdate.resPath ..updatePath,fileName1.."_temp"..fileExtend1,fileName1..fileExtend1) | ||
| 322 | end | ||
| 323 | |||
| 324 | if string.find(path, "AssetsUpdate") == nil then | ||
| 325 | for k,_ in pairs(package.loaded) do | ||
| 326 | k = string.gsub(k, "%.", "/") | ||
| 327 | local G_index = AssetsUpdate.string_lastIndexOf(path, ".") | ||
| 328 | local G_filename = string.sub(path, 1, G_index - 1) | ||
| 329 | if string.sub(k, 1, 4) ~= "src/" then | ||
| 330 | k = "src/"..k | ||
| 331 | end | ||
| 332 | if k == G_filename then | ||
| 333 | table.insert(req, k); | ||
| 334 | package.loaded[k] = nil; | ||
| 335 | end | ||
| 336 | end | ||
| 337 | end | ||
| 338 | end | ||
| 339 | |||
| 340 | -- cc.FileUtils:getInstance():purgeCachedEntries(); | ||
| 341 | -- if #req > 0 then | ||
| 342 | -- for key, value in pairs(req) do | ||
| 343 | -- print("require:"..value) | ||
| 344 | -- require(value) | ||
| 345 | -- end | ||
| 346 | -- end | ||
| 347 | for key1, var1 in pairs(filelistServer) do | ||
| 348 | filelistLocal[key1] = var1; | ||
| 349 | end | ||
| 350 | local mergeFilelistData = ""; --合并服务器新的文件md5 | ||
| 351 | for i,v in pairs(filelistLocal) do | ||
| 352 | mergeFilelistData = mergeFilelistData .. i..","..v; | ||
| 353 | end | ||
| 354 | print("合并服务器filelist.txt"); | ||
| 355 | AssetsUpdate.writeResToLocal("res/filelist.txt",mergeFilelistData); | ||
| 356 | cc.FileUtils:getInstance():removeFile(AssetsUpdate.resPath .. "filelist_temp.txt"); | ||
| 357 | updateSuccess(); | ||
| 358 | end | ||
| 359 | end | ||
| 360 | |||
| 361 | |||
| 362 | --资源本地写入 | ||
| 363 | function AssetsUpdate.writeResToLocal(resName, resData) | ||
| 364 | local result = false; | ||
| 365 | local tempResName = resName; | ||
| 366 | local maxLength = string.len(tempResName); | ||
| 367 | local directoryLen = 0; | ||
| 368 | local tag = string.find(tempResName,'/'); | ||
| 369 | while tag do | ||
| 370 | if tag ~= 1 then | ||
| 371 | directoryLen = directoryLen + tag; | ||
| 372 | end | ||
| 373 | tempResName = string.sub(tempResName,tag + 1,maxLength) | ||
| 374 | tag = string.find(tempResName,'/') | ||
| 375 | end | ||
| 376 | |||
| 377 | if directoryLen ~= 0 then | ||
| 378 | local tmpPath = string.sub(resName,1,directoryLen); | ||
| 379 | local fullPath = AssetsUpdate.resPath .. tmpPath; | ||
| 380 | if not (cc.FileUtils:getInstance():isDirectoryExist(fullPath)) then | ||
| 381 | cc.FileUtils:getInstance():createDirectory(fullPath); | ||
| 382 | end | ||
| 383 | end | ||
| 384 | |||
| 385 | local updateResPath = AssetsUpdate.resPath .. resName; | ||
| 386 | print("资源写入本地"..updateResPath) | ||
| 387 | local fp = io.open(updateResPath, 'w') | ||
| 388 | if fp then | ||
| 389 | fp:write(resData) | ||
| 390 | io.close(fp); | ||
| 391 | result = true; | ||
| 392 | else | ||
| 393 | print('downloadRes write error!!'); | ||
| 394 | updateFailed(); | ||
| 395 | end | ||
| 396 | return result; | ||
| 397 | end | ||
| 398 | |||
| 399 | function AssetsUpdate.timeOut(dt) | ||
| 400 | AssetsUpdate.timeOutTime = AssetsUpdate.timeOutTime or 30; | ||
| 401 | AssetsUpdate.timeOutTime = AssetsUpdate.timeOutTime - 1; | ||
| 402 | print("AssetsUpdate.timeOutTime:"..AssetsUpdate.timeOutTime); | ||
| 403 | if AssetsUpdate.timeOutTime == 0 then | ||
| 404 | updateFailed(); | ||
| 405 | end | ||
| 406 | end | ||
| 407 | |||
| 408 | function AssetsUpdate.string_split(str, split_char) | ||
| 409 | local sub_str_tab = {}; | ||
| 410 | while (true) do | ||
| 411 | local pos = nil | ||
| 412 | for i = 1, #str do | ||
| 413 | if string.sub(str, i, i) == split_char then | ||
| 414 | pos = i | ||
| 415 | break | ||
| 416 | end | ||
| 417 | end | ||
| 418 | if (not pos) then | ||
| 419 | sub_str_tab[#sub_str_tab + 1] = str; | ||
| 420 | break; | ||
| 421 | end | ||
| 422 | local sub_str = string.sub(str, 1, pos - 1); | ||
| 423 | sub_str_tab[#sub_str_tab + 1] = sub_str; | ||
| 424 | str = string.sub(str, pos + 1, #str); | ||
| 425 | end | ||
| 426 | |||
| 427 | return sub_str_tab; | ||
| 428 | end | ||
| 429 | |||
| 430 | function AssetsUpdate.string_lastIndexOf(str, split_char) | ||
| 431 | local len = #str | ||
| 432 | for i = len, 1, -1 do | ||
| 433 | if string.sub(str, i, i) == split_char then | ||
| 434 | return i | ||
| 435 | end | ||
| 436 | end | ||
| 437 | |||
| 438 | return 0 | ||
| 439 | end | ||
| 440 | |||
| 441 | return AssetsUpdate | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | |||
| 2 | cc.exports.CustomMath = class("CustomMath") | ||
| 3 | |||
| 4 | -- 自定义数学公式类 | ||
| 5 | function CustomMath:ctor( ) | ||
| 6 | |||
| 7 | end | ||
| 8 | |||
| 9 | -- C++的三元表达式 如果condition为true 返回param1 否则返回param2 | ||
| 10 | function CustomMath:AndOr( condition, param1, param2 ) | ||
| 11 | |||
| 12 | if condition then | ||
| 13 | return param1 | ||
| 14 | else | ||
| 15 | return param2 | ||
| 16 | end | ||
| 17 | end | ||
| 18 | |||
| 19 | return CustomMath | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | module("DeviceUtil", package.seeall) | ||
| 2 | |||
| 3 | --android获取uid | ||
| 4 | function getUniqueKey() | ||
| 5 | local uid = "1fyiqznjeuysjzue" | ||
| 6 | local ok | ||
| 7 | |||
| 8 | if device.platform == "ios" then | ||
| 9 | |||
| 10 | elseif device.platform == "android" then | ||
| 11 | if app.isVerGE120 then | ||
| 12 | ok, uid = luaj.callStaticMethod("com/gd/DeviceHelper", "getUniqueKey", {}, "()Ljava/lang/String;") | ||
| 13 | end | ||
| 14 | else | ||
| 15 | |||
| 16 | end | ||
| 17 | |||
| 18 | return uid | ||
| 19 | end | ||
| 20 | |||
| 21 | function DeviceUtil.getUserID() --调用android的方法实现 | ||
| 22 | local ok,uid=false,""; | ||
| 23 | local targetPlatform = cc.Application:getInstance():getTargetPlatform(); | ||
| 24 | if targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 25 | local luaj = require "cocos.cocos2d.luaj" --引入luaj | ||
| 26 | --包名/类名 这个可以在对应的android工程的manifest中得到 | ||
| 27 | local className="org/cocos2dx/lua/AppActivity"; | ||
| 28 | local args = {}; | ||
| 29 | local sigs = "()Ljava/lang/String;" --传入string参数,无返回值 | ||
| 30 | |||
| 31 | --luaj 调用 Java 方法时,可能会出现各种错误,因此 luaj 提供了一种机制让 Lua 调用代码可以确定 Java 方法是否成功调用。 | ||
| 32 | --luaj.callStaticMethod() 会返回两个值 | ||
| 33 | --当成功时,第一个值为 true,第二个值是 Java 方法的返回值(如果有) | ||
| 34 | --当失败时,第一个值为 false,第二个值是错误代码 | ||
| 35 | ok,uid = luaj.callStaticMethod(className,"getUserID",args,sigs) | ||
| 36 | if not ok then | ||
| 37 | print("getUserID error:"..uid); | ||
| 38 | end | ||
| 39 | end | ||
| 40 | return uid; | ||
| 41 | end | ||
| 42 | |||
| 43 | function DeviceUtil.getAppName() --调用android的方法实现 | ||
| 44 | local ok,appName=false,"全家棋牌"; | ||
| 45 | local targetPlatform = cc.Application:getInstance():getTargetPlatform(); | ||
| 46 | if targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 47 | local luaj = require "cocos.cocos2d.luaj" --引入luaj | ||
| 48 | --包名/类名 这个可以在对应的android工程的manifest中得到 | ||
| 49 | local className="org/cocos2dx/lua/AppActivity"; | ||
| 50 | local args = {}; | ||
| 51 | local sigs = "()Ljava/lang/String;" --传入string参数,无返回值 | ||
| 52 | |||
| 53 | --luaj 调用 Java 方法时,可能会出现各种错误,因此 luaj 提供了一种机制让 Lua 调用代码可以确定 Java 方法是否成功调用。 | ||
| 54 | --luaj.callStaticMethod() 会返回两个值 | ||
| 55 | --当成功时,第一个值为 true,第二个值是 Java 方法的返回值(如果有) | ||
| 56 | --当失败时,第一个值为 false,第二个值是错误代码 | ||
| 57 | ok,appName = luaj.callStaticMethod(className,"getAppName",args,sigs) | ||
| 58 | if not ok then | ||
| 59 | print("getAppName error:"..uid); | ||
| 60 | end | ||
| 61 | end | ||
| 62 | return appName; | ||
| 63 | end | ||
| 64 | |||
| 65 | function DeviceUtil.getDeviceId() --调用android的方法实现 | ||
| 66 | local ok,uid=false,""; | ||
| 67 | local targetPlatform = cc.Application:getInstance():getTargetPlatform(); | ||
| 68 | if targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 69 | local luaj = require "cocos.cocos2d.luaj" --引入luaj | ||
| 70 | --包名/类名 这个可以在对应的android工程的manifest中得到 | ||
| 71 | local className="org/cocos2dx/lua/AppActivity"; | ||
| 72 | local args = {}; | ||
| 73 | local sigs = "()Ljava/lang/String;" --传入string参数,无返回值 | ||
| 74 | |||
| 75 | --luaj 调用 Java 方法时,可能会出现各种错误,因此 luaj 提供了一种机制让 Lua 调用代码可以确定 Java 方法是否成功调用。 | ||
| 76 | --luaj.callStaticMethod() 会返回两个值 | ||
| 77 | --当成功时,第一个值为 true,第二个值是 Java 方法的返回值(如果有) | ||
| 78 | --当失败时,第一个值为 false,第二个值是错误代码 | ||
| 79 | ok,uid = luaj.callStaticMethod(className,"getDeviceId",args,sigs) | ||
| 80 | if not ok then | ||
| 81 | print("getDeviceId error:"..uid); | ||
| 82 | end | ||
| 83 | end | ||
| 84 | return uid; | ||
| 85 | end | ||
| 86 | |||
| 87 | function DeviceUtil.getAppVersionName() --调用android的方法实现 | ||
| 88 | local ok,ver_name=false,"4.3"; | ||
| 89 | local targetPlatform = cc.Application:getInstance():getTargetPlatform(); | ||
| 90 | if targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 91 | local luaj = require "cocos.cocos2d.luaj" --引入luaj | ||
| 92 | --包名/类名 这个可以在对应的android工程的manifest中得到 | ||
| 93 | local className="org/cocos2dx/lua/AppActivity"; | ||
| 94 | local args = {}; | ||
| 95 | local sigs = "()Ljava/lang/String;" --传入string参数,无返回值 | ||
| 96 | |||
| 97 | --luaj 调用 Java 方法时,可能会出现各种错误,因此 luaj 提供了一种机制让 Lua 调用代码可以确定 Java 方法是否成功调用。 | ||
| 98 | --luaj.callStaticMethod() 会返回两个值 | ||
| 99 | --当成功时,第一个值为 true,第二个值是 Java 方法的返回值(如果有) | ||
| 100 | --当失败时,第一个值为 false,第二个值是错误代码 | ||
| 101 | ok,ver_name = luaj.callStaticMethod(className,"getAppVersionName",args,sigs) | ||
| 102 | if not ok then | ||
| 103 | print("getAppVersionName error:"..ver_name); | ||
| 104 | end | ||
| 105 | else | ||
| 106 | |||
| 107 | end | ||
| 108 | return ver_name; | ||
| 109 | end | ||
| 110 | |||
| 111 | function DeviceUtil.initSdk(params,callbackLua) --调用android的方法实现 | ||
| 112 | local targetPlatform = cc.Application:getInstance():getTargetPlatform() | ||
| 113 | if targetPlatform ~= cc.PLATFORM_OS_WINDOWS and targetPlatform ~= cc.PLATFORM_OS_MAC then | ||
| 114 | local luaj = require "cocos.cocos2d.luaj" --引入luaj | ||
| 115 | --包名/类名 这个可以在对应的android工程的manifest中得到 | ||
| 116 | local className="org/cocos2dx/lua/AppActivity"; | ||
| 117 | local args = { tostring(params),callbackLua}; | ||
| 118 | local sigs = "(Ljava/lang/String;I)V" --传入string参数,无返回值 | ||
| 119 | |||
| 120 | --luaj 调用 Java 方法时,可能会出现各种错误,因此 luaj 提供了一种机制让 Lua 调用代码可以确定 Java 方法是否成功调用。 | ||
| 121 | --luaj.callStaticMethod() 会返回两个值 | ||
| 122 | --当成功时,第一个值为 true,第二个值是 Java 方法的返回值(如果有) | ||
| 123 | --当失败时,第一个值为 false,第二个值是错误代码 | ||
| 124 | local ok,ret = luaj.callStaticMethod(className,"initSdk",args,sigs) | ||
| 125 | if not ok then | ||
| 126 | print("initSdk error:"..ret) | ||
| 127 | end | ||
| 128 | end | ||
| 129 | end | ||
| 130 | |||
| 131 | function DeviceUtil.sendBilling(params,callbackLua) --调用android的方法实现 | ||
| 132 | local targetPlatform = cc.Application:getInstance():getTargetPlatform() | ||
| 133 | if targetPlatform ~= cc.PLATFORM_OS_WINDOWS and targetPlatform ~= cc.PLATFORM_OS_MAC then | ||
| 134 | local luaj = require "cocos.cocos2d.luaj" --引入luaj | ||
| 135 | --包名/类名 这个可以在对应的android工程的manifest中得到 | ||
| 136 | local className="org/cocos2dx/lua/AppActivity"; | ||
| 137 | local args = { tostring(params),callbackLua}; | ||
| 138 | local sigs = "(Ljava/lang/String;I)V" --传入string参数,无返回值 | ||
| 139 | |||
| 140 | --luaj 调用 Java 方法时,可能会出现各种错误,因此 luaj 提供了一种机制让 Lua 调用代码可以确定 Java 方法是否成功调用。 | ||
| 141 | --luaj.callStaticMethod() 会返回两个值 | ||
| 142 | --当成功时,第一个值为 true,第二个值是 Java 方法的返回值(如果有) | ||
| 143 | --当失败时,第一个值为 false,第二个值是错误代码 | ||
| 144 | local ok,ret = luaj.callStaticMethod(className,"sendBilling",args,sigs) | ||
| 145 | if not ok then | ||
| 146 | print("sendBilling error:"..ret); | ||
| 147 | end | ||
| 148 | else | ||
| 149 | if callbackLua then | ||
| 150 | callbackLua("fail"); | ||
| 151 | end | ||
| 152 | end | ||
| 153 | end | ||
| 154 | |||
| 155 | function DeviceUtil.payCyrcle(params,callbackLua) --调用android的方法实现 | ||
| 156 | local targetPlatform = cc.Application:getInstance():getTargetPlatform() | ||
| 157 | if targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 158 | local luaj = require "cocos.cocos2d.luaj" --引入luaj | ||
| 159 | --包名/类名 这个可以在对应的android工程的manifest中得到 | ||
| 160 | local className="org/cocos2dx/lua/AppActivity"; | ||
| 161 | local args = { tostring(params),callbackLua}; | ||
| 162 | local sigs = "(Ljava/lang/String;I)V" --传入string参数,无返回值 | ||
| 163 | |||
| 164 | --luaj 调用 Java 方法时,可能会出现各种错误,因此 luaj 提供了一种机制让 Lua 调用代码可以确定 Java 方法是否成功调用。 | ||
| 165 | --luaj.callStaticMethod() 会返回两个值 | ||
| 166 | --当成功时,第一个值为 true,第二个值是 Java 方法的返回值(如果有) | ||
| 167 | --当失败时,第一个值为 false,第二个值是错误代码 | ||
| 168 | local ok,ret = luaj.callStaticMethod(className,"payCyrcle",args,sigs) | ||
| 169 | if not ok then | ||
| 170 | print("payCyrcle error:"..ret) | ||
| 171 | end | ||
| 172 | end | ||
| 173 | end | ||
| 174 | |||
| 175 | function DeviceUtil.sendHttpRequest(params,callbackLua) --调用android的方法实现 | ||
| 176 | local targetPlatform = cc.Application:getInstance():getTargetPlatform() | ||
| 177 | if targetPlatform == cc.PLATFORM_OS_WINDOWS or targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 178 | local luaj = require "cocos.cocos2d.luaj" --引入luaj | ||
| 179 | --包名/类名 这个可以在对应的android工程的manifest中得到 | ||
| 180 | local className="org/cocos2dx/lua/AppActivity"; | ||
| 181 | local args = { tostring(params),callbackLua}; | ||
| 182 | local sigs = "(Ljava/lang/String;I)V" --传入string参数,无返回值 | ||
| 183 | |||
| 184 | --luaj 调用 Java 方法时,可能会出现各种错误,因此 luaj 提供了一种机制让 Lua 调用代码可以确定 Java 方法是否成功调用。 | ||
| 185 | --luaj.callStaticMethod() 会返回两个值 | ||
| 186 | --当成功时,第一个值为 true,第二个值是 Java 方法的返回值(如果有) | ||
| 187 | --当失败时,第一个值为 false,第二个值是错误代码 | ||
| 188 | local ok,ret = luaj.callStaticMethod(className,"sendHttpRequest",args,sigs) | ||
| 189 | if not ok then | ||
| 190 | print("sendHttpRequest error:"..ret) | ||
| 191 | end | ||
| 192 | end | ||
| 193 | end | ||
| 194 | |||
| 195 | function DeviceUtil.downloadApk(params,callbackLua) --调用android的方法实现 | ||
| 196 | local targetPlatform = cc.Application:getInstance():getTargetPlatform() | ||
| 197 | if targetPlatform == cc.PLATFORM_OS_WINDOWS or targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 198 | local luaj = require "cocos.cocos2d.luaj" --引入luaj | ||
| 199 | --包名/类名 这个可以在对应的android工程的manifest中得到 | ||
| 200 | local className="org/cocos2dx/lua/AppActivity"; | ||
| 201 | local args = { tostring(params),callbackLua}; | ||
| 202 | local sigs = "(Ljava/lang/String;I)V" --传入string参数,无返回值 | ||
| 203 | |||
| 204 | --luaj 调用 Java 方法时,可能会出现各种错误,因此 luaj 提供了一种机制让 Lua 调用代码可以确定 Java 方法是否成功调用。 | ||
| 205 | --luaj.callStaticMethod() 会返回两个值 | ||
| 206 | --当成功时,第一个值为 true,第二个值是 Java 方法的返回值(如果有) | ||
| 207 | --当失败时,第一个值为 false,第二个值是错误代码 | ||
| 208 | local ok,ret = luaj.callStaticMethod(className,"downloadApk",args,sigs) | ||
| 209 | if not ok then | ||
| 210 | print("downloadApk error:"..ret) | ||
| 211 | end | ||
| 212 | end | ||
| 213 | end | ||
| 214 | |||
| 215 | function DeviceUtil.SendAuthWechatMobile(params,callbackLua) --调用android的方法实现 | ||
| 216 | local targetPlatform = cc.Application:getInstance():getTargetPlatform() | ||
| 217 | if targetPlatform == cc.PLATFORM_OS_WINDOWS or targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 218 | local luaj = require "cocos.cocos2d.luaj" --引入luaj | ||
| 219 | --包名/类名 这个可以在对应的android工程的manifest中得到 | ||
| 220 | local className="org/cocos2dx/lua/AppActivity"; | ||
| 221 | local args = { tostring(params),callbackLua}; | ||
| 222 | local sigs = "(Ljava/lang/String;I)V" --传入string参数,无返回值 | ||
| 223 | |||
| 224 | --luaj 调用 Java 方法时,可能会出现各种错误,因此 luaj 提供了一种机制让 Lua 调用代码可以确定 Java 方法是否成功调用。 | ||
| 225 | --luaj.callStaticMethod() 会返回两个值 | ||
| 226 | --当成功时,第一个值为 true,第二个值是 Java 方法的返回值(如果有) | ||
| 227 | --当失败时,第一个值为 false,第二个值是错误代码 | ||
| 228 | local ok,ret = luaj.callStaticMethod(className,"SendAuthWechatMobile",args,sigs) | ||
| 229 | if not ok then | ||
| 230 | print("SendAuthWechatMobile error:"..ret) | ||
| 231 | end | ||
| 232 | end | ||
| 233 | end | ||
| 234 | |||
| 235 | function DeviceUtil.ShareWxWebpage(params,callbackLua) --调用android的方法实现 | ||
| 236 | local targetPlatform = cc.Application:getInstance():getTargetPlatform() | ||
| 237 | if targetPlatform == cc.PLATFORM_OS_WINDOWS or targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 238 | local luaj = require "cocos.cocos2d.luaj" --引入luaj | ||
| 239 | --包名/类名 这个可以在对应的android工程的manifest中得到 | ||
| 240 | local className="org/cocos2dx/lua/AppActivity"; | ||
| 241 | local args = { tostring(params),callbackLua}; | ||
| 242 | local sigs = "(Ljava/lang/String;I)V" --传入string参数,无返回值 | ||
| 243 | |||
| 244 | --luaj 调用 Java 方法时,可能会出现各种错误,因此 luaj 提供了一种机制让 Lua 调用代码可以确定 Java 方法是否成功调用。 | ||
| 245 | --luaj.callStaticMethod() 会返回两个值 | ||
| 246 | --当成功时,第一个值为 true,第二个值是 Java 方法的返回值(如果有) | ||
| 247 | --当失败时,第一个值为 false,第二个值是错误代码 | ||
| 248 | local ok,ret = luaj.callStaticMethod(className,"ShareWxWebpage",args,sigs) | ||
| 249 | if not ok then | ||
| 250 | print("ShareWxWebpage error:"..ret) | ||
| 251 | end | ||
| 252 | end | ||
| 253 | end | ||
| 254 | |||
| 255 | function DeviceUtil.ShareWxImage(params,callbackLua) --调用android的方法实现 | ||
| 256 | local targetPlatform = cc.Application:getInstance():getTargetPlatform() | ||
| 257 | if targetPlatform == cc.PLATFORM_OS_WINDOWS or targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 258 | local luaj = require "cocos.cocos2d.luaj" --引入luaj | ||
| 259 | --包名/类名 这个可以在对应的android工程的manifest中得到 | ||
| 260 | local className="org/cocos2dx/lua/AppActivity"; | ||
| 261 | local args = { tostring(params),callbackLua}; | ||
| 262 | local sigs = "(Ljava/lang/String;I)V" --传入string参数,无返回值 | ||
| 263 | |||
| 264 | --luaj 调用 Java 方法时,可能会出现各种错误,因此 luaj 提供了一种机制让 Lua 调用代码可以确定 Java 方法是否成功调用。 | ||
| 265 | --luaj.callStaticMethod() 会返回两个值 | ||
| 266 | --当成功时,第一个值为 true,第二个值是 Java 方法的返回值(如果有) | ||
| 267 | --当失败时,第一个值为 false,第二个值是错误代码 | ||
| 268 | local ok,ret = luaj.callStaticMethod(className,"ShareWxImage",args,sigs) | ||
| 269 | if not ok then | ||
| 270 | print("ShareWxImage error:"..ret) | ||
| 271 | end | ||
| 272 | end | ||
| 273 | end | ||
| 274 | |||
| 275 | function DeviceUtil.restartApplication(params,callbackLua) --调用android的方法实现 | ||
| 276 | local targetPlatform = cc.Application:getInstance():getTargetPlatform() | ||
| 277 | if targetPlatform == cc.PLATFORM_OS_WINDOWS or targetPlatform == cc.PLATFORM_OS_ANDROID then | ||
| 278 | local luaj = require "cocos.cocos2d.luaj" --引入luaj | ||
| 279 | --包名/类名 这个可以在对应的android工程的manifest中得到 | ||
| 280 | local className="org/cocos2dx/lua/AppActivity"; | ||
| 281 | local args = { tostring(params),callbackLua}; | ||
| 282 | local sigs = "(Ljava/lang/String;I)V" --传入string参数,无返回值 | ||
| 283 | |||
| 284 | --luaj 调用 Java 方法时,可能会出现各种错误,因此 luaj 提供了一种机制让 Lua 调用代码可以确定 Java 方法是否成功调用。 | ||
| 285 | --luaj.callStaticMethod() 会返回两个值 | ||
| 286 | --当成功时,第一个值为 true,第二个值是 Java 方法的返回值(如果有) | ||
| 287 | --当失败时,第一个值为 false,第二个值是错误代码 | ||
| 288 | local ok,ret = luaj.callStaticMethod(className,"restartApplication",args,sigs) | ||
| 289 | if not ok then | ||
| 290 | print("restartApplication error:"..ret) | ||
| 291 | end | ||
| 292 | end | ||
| 293 | end | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | --region *.lua | ||
| 2 | --Date | ||
| 3 | --此文件由[BabeLua]插件自动生成 | ||
| 4 | |||
| 5 | cc.exports.DisplayUtil = {} | ||
| 6 | |||
| 7 | function DisplayUtil.setSpriteGray(sp) | ||
| 8 | local vertDefaultSource = [[ | ||
| 9 | attribute vec4 a_position; | ||
| 10 | attribute vec2 a_texCoord; | ||
| 11 | attribute vec4 a_color; | ||
| 12 | |||
| 13 | #ifdef GL_ES | ||
| 14 | varying lowp vec4 v_fragmentColor; | ||
| 15 | varying mediump vec2 v_texCoord; | ||
| 16 | #else | ||
| 17 | varying vec4 v_fragmentColor; | ||
| 18 | varying vec2 v_texCoord; | ||
| 19 | #endif | ||
| 20 | |||
| 21 | void main() | ||
| 22 | { | ||
| 23 | gl_Position = CC_PMatrix * a_position; | ||
| 24 | v_fragmentColor = a_color; | ||
| 25 | v_texCoord = a_texCoord; | ||
| 26 | } | ||
| 27 | ]] | ||
| 28 | local pszFragSource = [[ | ||
| 29 | #ifdef GL_ES | ||
| 30 | precision mediump float; | ||
| 31 | #endif | ||
| 32 | varying vec4 v_fragmentColor; | ||
| 33 | varying vec2 v_texCoord; | ||
| 34 | |||
| 35 | void main(void) | ||
| 36 | { | ||
| 37 | vec4 c = texture2D(CC_Texture0, v_texCoord); | ||
| 38 | gl_FragColor.xyz = vec3(0.4*c.r + 0.4*c.g +0.4*c.b); | ||
| 39 | gl_FragColor.w = c.w; | ||
| 40 | } | ||
| 41 | ]] | ||
| 42 | |||
| 43 | local glProgram = cc.GLProgram:createWithByteArrays(vertDefaultSource,pszFragSource); | ||
| 44 | glProgram:bindAttribLocation(cc.ATTRIBUTE_NAME_POSITION,cc.VERTEX_ATTRIB_POSITION); | ||
| 45 | glProgram:bindAttribLocation(cc.ATTRIBUTE_NAME_COLOR,cc.VERTEX_ATTRIB_COLOR); | ||
| 46 | glProgram:bindAttribLocation(cc.ATTRIBUTE_NAME_TEX_COORD,cc.VERTEX_ATTRIB_FLAG_TEX_COORDS); | ||
| 47 | glProgram:link(); | ||
| 48 | glProgram:updateUniforms(); | ||
| 49 | sp:setGLProgram(glProgram); | ||
| 50 | end | ||
| 51 | |||
| 52 | --function DisplayUtil.setSpriteOutline(sprite) | ||
| 53 | -- local vert = [[ | ||
| 54 | -- attribute vec4 a_position; | ||
| 55 | -- attribute vec2 a_texCoord; | ||
| 56 | -- attribute vec4 a_color; | ||
| 57 | -- #ifdef GL_ES | ||
| 58 | -- varying lowp vec4 v_fragmentColor; | ||
| 59 | -- varying mediump vec2 v_texCoord; | ||
| 60 | -- #else | ||
| 61 | -- varying vec4 v_fragmentColor; | ||
| 62 | -- varying vec2 v_texCoord; | ||
| 63 | -- #endif | ||
| 64 | -- void main() | ||
| 65 | -- { | ||
| 66 | -- gl_Position = CC_PMatrix * a_position; | ||
| 67 | -- v_fragmentColor = a_color; | ||
| 68 | -- v_texCoord = a_texCoord; | ||
| 69 | -- } | ||
| 70 | -- ]] | ||
| 71 | |||
| 72 | -- local frag = [[ | ||
| 73 | -- #ifdef GL_ES | ||
| 74 | -- precision mediump float; | ||
| 75 | -- #endif | ||
| 76 | -- varying vec4 v_fragmentColor; | ||
| 77 | -- varying vec2 v_texCoord; | ||
| 78 | -- uniform vec2 my_size = vec2(1,1); // 纹理大小,纹理坐标范围为0-1 | ||
| 79 | -- void main(void) | ||
| 80 | -- { | ||
| 81 | -- vec2 unit = 1.0 / my_size.xy; // 单位坐标 | ||
| 82 | -- float step = 30.0; // 30度 | ||
| 83 | -- float width = 5; // 描边宽度 | ||
| 84 | -- float a_limit = 0.4; // 透明度限制,低于该值即视为透明 | ||
| 85 | -- vec4 border = vec4(1.0,1.0,1.0,1.0);// 边框颜色 | ||
| 86 | |||
| 87 | -- vec4 color1 = texture2D(CC_Texture0, v_texCoord); | ||
| 88 | -- gl_FragColor = color1; | ||
| 89 | -- if(color1.a >= a_limit) | ||
| 90 | -- { | ||
| 91 | -- return; // 非透明像素点不做处理 | ||
| 92 | -- } | ||
| 93 | -- // 遍历四周所有像素点 | ||
| 94 | -- for(float i = 0.0; i < 360.0; i += step) | ||
| 95 | -- { | ||
| 96 | -- // 当前角度的偏移坐标 | ||
| 97 | -- vec2 offset = vec2(cos(i) * unit.x, sin(i) * unit.y) * width; | ||
| 98 | -- // 当前像素点偏移坐标下的像素点 | ||
| 99 | -- vec4 color2 = texture2D(CC_Texture0, v_texCoord + offset); | ||
| 100 | -- if(color2.a >= a_limit) | ||
| 101 | -- { | ||
| 102 | -- gl_FragColor = border; // 不透明则将当前像素点设为边框 | ||
| 103 | -- return; | ||
| 104 | -- } | ||
| 105 | -- } | ||
| 106 | -- } | ||
| 107 | -- ]] | ||
| 108 | |||
| 109 | -- -- 1.创建glProgram | ||
| 110 | -- local glProgram = cc.GLProgram:createWithByteArrays(vert, frag) | ||
| 111 | -- -- 2.获取glProgramState | ||
| 112 | -- local glProgramState = cc.GLProgramState:getOrCreateWithGLProgram(glProgram) | ||
| 113 | -- -- 3.设置属性值 | ||
| 114 | -- local size = sprite:getTexture():getContentSizeInPixels() | ||
| 115 | -- glProgramState:setUniformVec2("my_size", cc.p(size.width, size.height)) | ||
| 116 | -- sprite:setGLProgram(glProgram) | ||
| 117 | -- sprite:setGLProgramState(glProgramState) | ||
| 118 | --end | ||
| 119 | |||
| 120 | function DisplayUtil.setSpriteOutline(sprite) | ||
| 121 | local vert = [[ | ||
| 122 | attribute vec4 a_position; | ||
| 123 | attribute vec2 a_texCoord; | ||
| 124 | attribute vec4 a_color; | ||
| 125 | #ifdef GL_ES | ||
| 126 | varying lowp vec4 v_fragmentColor; | ||
| 127 | varying mediump vec2 v_texCoord; | ||
| 128 | #else | ||
| 129 | varying vec4 v_fragmentColor; | ||
| 130 | varying vec2 v_texCoord; | ||
| 131 | #endif | ||
| 132 | void main() | ||
| 133 | { | ||
| 134 | gl_Position = CC_PMatrix * a_position; | ||
| 135 | v_fragmentColor = a_color; | ||
| 136 | v_texCoord = a_texCoord; | ||
| 137 | } | ||
| 138 | ]] | ||
| 139 | |||
| 140 | local frag = [[ | ||
| 141 | #ifdef GL_ES | ||
| 142 | precision mediump float; | ||
| 143 | #endif | ||
| 144 | |||
| 145 | varying vec2 v_texCoord; | ||
| 146 | varying vec4 v_fragmentColor; | ||
| 147 | uniform vec3 u_outlineColor; | ||
| 148 | uniform float u_threshold; | ||
| 149 | uniform float u_radius; | ||
| 150 | void main() | ||
| 151 | { | ||
| 152 | float radius = u_radius; | ||
| 153 | vec4 accum = vec4(0.0); | ||
| 154 | vec4 normal = vec4(0.0); | ||
| 155 | normal = texture2D(CC_Texture0, vec2(v_texCoord.x, v_texCoord.y)); | ||
| 156 | accum += texture2D(CC_Texture0, vec2(v_texCoord.x - radius, v_texCoord.y - radius)); | ||
| 157 | accum += texture2D(CC_Texture0, vec2(v_texCoord.x + radius, v_texCoord.y - radius)); | ||
| 158 | accum += texture2D(CC_Texture0, vec2(v_texCoord.x + radius, v_texCoord.y + radius)); | ||
| 159 | accum += texture2D(CC_Texture0, vec2(v_texCoord.x - radius, v_texCoord.y + radius)); | ||
| 160 | accum *= u_threshold; | ||
| 161 | accum.rgb = u_outlineColor * accum.a; | ||
| 162 | accum.a = 0.0; | ||
| 163 | normal = ( accum * (1.0 - normal.a)) + (normal * normal.a); | ||
| 164 | gl_FragColor = v_fragmentColor * normal; | ||
| 165 | } | ||
| 166 | ]] | ||
| 167 | |||
| 168 | -- 1.创建pProgram | ||
| 169 | local pProgram = cc.GLProgram:createWithByteArrays(vert, frag) | ||
| 170 | pProgram:bindAttribLocation(cc.ATTRIBUTE_NAME_POSITION,cc.VERTEX_ATTRIB_POSITION) | ||
| 171 | pProgram:bindAttribLocation(cc.ATTRIBUTE_NAME_COLOR,cc.VERTEX_ATTRIB_COLOR) | ||
| 172 | pProgram:bindAttribLocation(cc.ATTRIBUTE_NAME_TEX_COORD,cc.VERTEX_ATTRIB_FLAG_TEX_COORDS) | ||
| 173 | pProgram:link(); | ||
| 174 | pProgram:updateUniforms() | ||
| 175 | |||
| 176 | -- 2.获取glProgramState | ||
| 177 | local glprogramState = cc.GLProgramState:getOrCreateWithGLProgram(pProgram) | ||
| 178 | glprogramState:setUniformVec3("u_outlineColor",{x=255, y=255, z=255}) | ||
| 179 | glprogramState:setUniformFloat("u_threshold",1) | ||
| 180 | glprogramState:setUniformFloat("u_radius",0.01) | ||
| 181 | |||
| 182 | sprite:setGLProgramState(glprogramState) | ||
| 183 | |||
| 184 | end | ||
| 185 | |||
| 186 | function DisplayUtil.removeSpriteShader(sp) | ||
| 187 | local vertDefaultSource = [[ | ||
| 188 | attribute vec4 a_position; | ||
| 189 | attribute vec2 a_texCoord; | ||
| 190 | attribute vec4 a_color; | ||
| 191 | |||
| 192 | #ifdef GL_ES | ||
| 193 | varying lowp vec4 v_fragmentColor; | ||
| 194 | varying mediump vec2 v_texCoord; | ||
| 195 | #else | ||
| 196 | varying vec4 v_fragmentColor; | ||
| 197 | varying vec2 v_texCoord; | ||
| 198 | #endif | ||
| 199 | |||
| 200 | void main() | ||
| 201 | { | ||
| 202 | gl_Position = CC_PMatrix * a_position; | ||
| 203 | v_fragmentColor = a_color; | ||
| 204 | v_texCoord = a_texCoord; | ||
| 205 | } | ||
| 206 | ]] | ||
| 207 | -- 移除置灰frag | ||
| 208 | local pszRemoveGrayShader = "#ifdef GL_ES \n" .. | ||
| 209 | "precision mediump float; \n" .. | ||
| 210 | "#endif \n" .. | ||
| 211 | "varying vec4 v_fragmentColor; \n" .. | ||
| 212 | "varying vec2 v_texCoord; \n" .. | ||
| 213 | "void main(void) \n" .. | ||
| 214 | "{ \n" .. | ||
| 215 | "gl_FragColor = texture2D(CC_Texture0, v_texCoord); \n" .. | ||
| 216 | "}" | ||
| 217 | |||
| 218 | local glProgram = cc.GLProgram:createWithByteArrays(vertDefaultSource,pszRemoveGrayShader); | ||
| 219 | glProgram:bindAttribLocation(cc.ATTRIBUTE_NAME_POSITION,cc.VERTEX_ATTRIB_POSITION); | ||
| 220 | glProgram:bindAttribLocation(cc.ATTRIBUTE_NAME_COLOR,cc.VERTEX_ATTRIB_COLOR); | ||
| 221 | glProgram:bindAttribLocation(cc.ATTRIBUTE_NAME_TEX_COORD,cc.VERTEX_ATTRIB_FLAG_TEX_COORDS); | ||
| 222 | glProgram:link(); | ||
| 223 | glProgram:updateUniforms(); | ||
| 224 | sp:setGLProgram(glProgram); | ||
| 225 | end | ||
| 226 | |||
| 227 | return DisplayUtil | ||
| 228 | |||
| 229 | --endregion |
| 1 | cc.exports.ObjectPool = class("ObjectPool") | ||
| 2 | |||
| 3 | local map = {}; | ||
| 4 | |||
| 5 | local function createObject(name) | ||
| 6 | local obj = cc.Sprite:createWithSpriteFrameName(name); | ||
| 7 | obj.name = name; | ||
| 8 | -- print("create object: "..name) | ||
| 9 | return obj; | ||
| 10 | end | ||
| 11 | |||
| 12 | function ObjectPool:getObject(name) | ||
| 13 | local obj; | ||
| 14 | if map[name] == nil then | ||
| 15 | map[name] = {}; | ||
| 16 | end | ||
| 17 | if #map[name] < 1 then | ||
| 18 | obj = createObject(name); | ||
| 19 | else | ||
| 20 | obj = table.remove(map[name],#map[name]); | ||
| 21 | end | ||
| 22 | obj.x,obj.y = 0,0; | ||
| 23 | return obj; | ||
| 24 | end | ||
| 25 | |||
| 26 | function ObjectPool:pushObject(obj) | ||
| 27 | if obj.name ~= nil then | ||
| 28 | if map[obj.name] == nil then | ||
| 29 | map[obj.name] = {}; | ||
| 30 | end | ||
| 31 | map[obj.name][#map[obj.name]+1] = obj; | ||
| 32 | end | ||
| 33 | end | ||
| 34 | |||
| 35 | return ObjectPool | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local cryptoKey = 0x020207070202 | ||
| 2 | local delta = 8 | ||
| 3 | |||
| 4 | local mt = {} | ||
| 5 | |||
| 6 | function mt.__add(a, b) | ||
| 7 | local ta = type(a) | ||
| 8 | local tb = type(b) | ||
| 9 | |||
| 10 | if ta == "table" and tb == "table" then | ||
| 11 | return Obscured(a.Decrypt() + b.Decrypt()) | ||
| 12 | end | ||
| 13 | |||
| 14 | if ta == "number" then | ||
| 15 | return Obscured(a + b.Decrypt()) | ||
| 16 | end | ||
| 17 | |||
| 18 | if tb == "number" then | ||
| 19 | return Obscured(a.Decrypt() + b) | ||
| 20 | end | ||
| 21 | |||
| 22 | error("add wrong") | ||
| 23 | end | ||
| 24 | |||
| 25 | function mt.__sub(a, b) | ||
| 26 | local ta = type(a) | ||
| 27 | local tb = type(b) | ||
| 28 | |||
| 29 | if ta == "table" and tb == "table" then | ||
| 30 | return Obscured(a.Decrypt() - b.Decrypt()) | ||
| 31 | end | ||
| 32 | |||
| 33 | if ta == "number" then | ||
| 34 | return Obscured(a - b.Decrypt()) | ||
| 35 | end | ||
| 36 | |||
| 37 | if tb == "number" then | ||
| 38 | return Obscured(a.Decrypt() - b) | ||
| 39 | end | ||
| 40 | |||
| 41 | error("sub wrong") | ||
| 42 | end | ||
| 43 | |||
| 44 | function mt.__mul(a, b) | ||
| 45 | local ta = type(a) | ||
| 46 | local tb = type(b) | ||
| 47 | |||
| 48 | if ta == "table" and tb == "table" then | ||
| 49 | return Obscured(a.Decrypt() * b.Decrypt()) | ||
| 50 | end | ||
| 51 | |||
| 52 | if ta == "number" then | ||
| 53 | return Obscured(a * b.Decrypt()) | ||
| 54 | end | ||
| 55 | |||
| 56 | if tb == "number" then | ||
| 57 | return Obscured(a.Decrypt() * b) | ||
| 58 | end | ||
| 59 | |||
| 60 | error("sub wrong") | ||
| 61 | end | ||
| 62 | |||
| 63 | function mt.__div(a, b) | ||
| 64 | local ta = type(a) | ||
| 65 | local tb = type(b) | ||
| 66 | |||
| 67 | if ta == "table" and tb == "table" then | ||
| 68 | return Obscured(a.Decrypt() / b.Decrypt()) | ||
| 69 | end | ||
| 70 | |||
| 71 | if ta == "number" then | ||
| 72 | return Obscured(a / b.Decrypt()) | ||
| 73 | end | ||
| 74 | |||
| 75 | if tb == "number" then | ||
| 76 | return Obscured(a.Decrypt() / b) | ||
| 77 | end | ||
| 78 | |||
| 79 | error("sub wrong") | ||
| 80 | end | ||
| 81 | |||
| 82 | function mt.__mod(a, b) | ||
| 83 | local ta = type(a) | ||
| 84 | local tb = type(b) | ||
| 85 | |||
| 86 | if ta == "table" and tb == "table" then | ||
| 87 | return Obscured(a.Decrypt() % b.Decrypt()) | ||
| 88 | end | ||
| 89 | |||
| 90 | if ta == "number" then | ||
| 91 | return Obscured(a % b.Decrypt()) | ||
| 92 | end | ||
| 93 | |||
| 94 | if tb == "number" then | ||
| 95 | return Obscured(a.Decrypt() % b) | ||
| 96 | end | ||
| 97 | |||
| 98 | error("sub wrong") | ||
| 99 | end | ||
| 100 | |||
| 101 | function mt.__unm(a) | ||
| 102 | return Obscured(-a.Decrypt()) | ||
| 103 | end | ||
| 104 | |||
| 105 | function mt.__len(a) | ||
| 106 | return #a.Decrypt() | ||
| 107 | end | ||
| 108 | |||
| 109 | function mt.__lt(a, b) | ||
| 110 | return a.Decrypt() < b.Decrypt() | ||
| 111 | end | ||
| 112 | |||
| 113 | function mt.__le(a, b) | ||
| 114 | return a.Decrypt() <= b.Decrypt() | ||
| 115 | end | ||
| 116 | |||
| 117 | function mt.__eq(a, b) | ||
| 118 | return a.Decrypt() == b.Decrypt() | ||
| 119 | end | ||
| 120 | |||
| 121 | function mt.__call(t) | ||
| 122 | return t.Decrypt() | ||
| 123 | end | ||
| 124 | |||
| 125 | function mt.__newindex(t,_,v) | ||
| 126 | t.SetVaule(v) | ||
| 127 | end | ||
| 128 | |||
| 129 | function mt.__index(t) | ||
| 130 | return t.Decrypt() | ||
| 131 | end | ||
| 132 | |||
| 133 | local function Obscured(value) | ||
| 134 | local hiddenValue = value | ||
| 135 | local currentKey = cryptoKey | ||
| 136 | local dataName = type(value) | ||
| 137 | |||
| 138 | local o = {} | ||
| 139 | |||
| 140 | function o.Encrypt(value, key) | ||
| 141 | key = key or currentKey | ||
| 142 | |||
| 143 | if type(value) == "number" then | ||
| 144 | value = tostring(value) | ||
| 145 | end | ||
| 146 | |||
| 147 | hiddenValue = {} | ||
| 148 | |||
| 149 | for i = 1, #value do | ||
| 150 | hiddenValue[i] = string.byte(value, i) | ||
| 151 | hiddenValue[i] = bit.bxor(hiddenValue[i], key) | ||
| 152 | if hiddenValue[i] % 2 == 1 then | ||
| 153 | hiddenValue[i] = 2*hiddenValue[i] + delta + 7 | ||
| 154 | else | ||
| 155 | hiddenValue[i] = 2*hiddenValue[i] - delta | ||
| 156 | end | ||
| 157 | end | ||
| 158 | end | ||
| 159 | |||
| 160 | function o.Decrypt(key) | ||
| 161 | key = key or currentKey | ||
| 162 | local d = "" | ||
| 163 | |||
| 164 | for i,v in ipairs(hiddenValue) do | ||
| 165 | if v % 2 == 1 then | ||
| 166 | v = v - delta - 7 | ||
| 167 | else | ||
| 168 | v = v + delta | ||
| 169 | end | ||
| 170 | v = v / 2 | ||
| 171 | v = bit.bxor(v, key) | ||
| 172 | d = d .. string.char(v) | ||
| 173 | end | ||
| 174 | |||
| 175 | if dataName == "number" then | ||
| 176 | d = tonumber(d) | ||
| 177 | end | ||
| 178 | |||
| 179 | return d | ||
| 180 | end | ||
| 181 | |||
| 182 | function o.SetNewCryptoKey(newKey) | ||
| 183 | cryptoKey = newKey | ||
| 184 | o.ApplyNewCryptoKey() | ||
| 185 | end | ||
| 186 | |||
| 187 | function o.ApplyNewCryptoKey() | ||
| 188 | if currentKey ~= cryptoKey then | ||
| 189 | o.Encrypt(Decrypt(), cryptoKey) | ||
| 190 | currentKey = cryptoKey | ||
| 191 | end | ||
| 192 | end | ||
| 193 | |||
| 194 | function o.SetVaule(value) | ||
| 195 | hiddenValue = value | ||
| 196 | dataName = type(value) | ||
| 197 | o.Encrypt(value) | ||
| 198 | end | ||
| 199 | |||
| 200 | o.Encrypt(value) | ||
| 201 | setmetatable(o,mt) | ||
| 202 | return o | ||
| 203 | end | ||
| 204 | |||
| 205 | return Obscured | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | local Shake = class("Shake") | ||
| 2 | |||
| 3 | function Shake:ctor(target,delay,count,maxDis) | ||
| 4 | if target.isShake then | ||
| 5 | target:stopAction(target.action); | ||
| 6 | target:setPosition(target.init_x,target.init_y); | ||
| 7 | end | ||
| 8 | |||
| 9 | target.isShake = true; | ||
| 10 | if not target.init_x and not target.init_y then | ||
| 11 | target.init_x,target.init_y = target:getPosition(); | ||
| 12 | end | ||
| 13 | self.index = 0; | ||
| 14 | local function func() | ||
| 15 | if self.index + 1 <= count then | ||
| 16 | local _mdx = math.random(1,maxDis); | ||
| 17 | _mdx = CustomMath:AndOr( math.random()>0.5,_mdx,-_mdx); | ||
| 18 | local _tx = target.init_x +_mdx; | ||
| 19 | local _mdy = math.random(1,maxDis); | ||
| 20 | _mdy = CustomMath:AndOr( math.random()>0.5,_mdy,-_mdy); | ||
| 21 | local _ty = target.init_y +_mdy; | ||
| 22 | target:setPosition(_tx,_ty); | ||
| 23 | local moveTo = cc.MoveTo:create(delay-0.05,cc.p(target.init_x,target.init_y)); | ||
| 24 | target:runAction(moveTo); | ||
| 25 | self.index = self.index + 1; | ||
| 26 | else | ||
| 27 | target:stopAction(target.action); | ||
| 28 | target:setPosition(target.init_x,target.init_y); | ||
| 29 | target.isShake = false; | ||
| 30 | end | ||
| 31 | end | ||
| 32 | target.action = schedule(target,func,delay) | ||
| 33 | end | ||
| 34 | |||
| 35 | return Shake | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | cc.exports.StringUtil = {} | ||
| 2 | |||
| 3 | function StringUtil.split(str,split_char) | ||
| 4 | str = tostring(str); | ||
| 5 | local sub_str_tab = {}; | ||
| 6 | while (true) do | ||
| 7 | local pos = nil | ||
| 8 | for i = 1, #str do | ||
| 9 | if string.sub(str, i, i) == split_char then | ||
| 10 | pos = i | ||
| 11 | break | ||
| 12 | end | ||
| 13 | end | ||
| 14 | if (not pos) then | ||
| 15 | sub_str_tab[#sub_str_tab + 1] = str; | ||
| 16 | break; | ||
| 17 | end | ||
| 18 | local sub_str = string.sub(str, 1, pos - 1); | ||
| 19 | sub_str_tab[#sub_str_tab + 1] = sub_str; | ||
| 20 | str = string.sub(str, pos + 1, #str); | ||
| 21 | end | ||
| 22 | |||
| 23 | return sub_str_tab; | ||
| 24 | end | ||
| 25 | |||
| 26 | function GetPreciseDecimal(nNum, n) | ||
| 27 | if type(nNum) ~= "number" then | ||
| 28 | return nNum; | ||
| 29 | end | ||
| 30 | |||
| 31 | n = n or 0; | ||
| 32 | n = math.floor(n) | ||
| 33 | local fmt = '%.' .. n .. 'f' | ||
| 34 | local nRet = tonumber(string.format(fmt, nNum)) | ||
| 35 | |||
| 36 | return nRet; | ||
| 37 | end | ||
| 38 | |||
| 39 | --获取数字显示万 | ||
| 40 | function StringUtil.getWanString(value) | ||
| 41 | local str = ""; | ||
| 42 | if value >= 100000000 then | ||
| 43 | local w = tostring(math.floor(value/100000000)); | ||
| 44 | local num = 4-string.len(w); | ||
| 45 | if num < 0 then | ||
| 46 | num = 0; | ||
| 47 | end | ||
| 48 | print("亿---------------------:",value/100000000,num); | ||
| 49 | str = GetPreciseDecimal(value/100000000,num).."亿"; | ||
| 50 | elseif value >= 10000 then | ||
| 51 | local w = tostring(math.floor(value/10000)); | ||
| 52 | local num = 4-string.len(w); | ||
| 53 | if num < 0 then | ||
| 54 | num = 0; | ||
| 55 | end | ||
| 56 | str = GetPreciseDecimal(value/10000,num).."万"; | ||
| 57 | else | ||
| 58 | str = tostring(value); | ||
| 59 | end | ||
| 60 | return str; | ||
| 61 | end | ||
| 62 | |||
| 63 | --将每个字符分离出来,放到table中,一个单元内一个字符 | ||
| 64 | local function StringToTable(s) | ||
| 65 | local tb = {}; | ||
| 66 | |||
| 67 | --[[ | ||
| 68 | UTF8的编码规则: | ||
| 69 | 1. 字符的第一个字节范围: 0x00—0x7F(0-127),或者 0xC2—0xF4(194-244); UTF8 是兼容 ascii 的,所以 0~127 就和 ascii 完全一致 | ||
| 70 | 2. 0xC0, 0xC1,0xF5—0xFF(192, 193 和 245-255)不会出现在UTF8编码中 | ||
| 71 | 3. 0x80—0xBF(128-191)只会出现在第二个及随后的编码中(针对多字节编码,如汉字) | ||
| 72 | ]] | ||
| 73 | for utfChar in string.gmatch(s, "[%z\1-\127\194-\244][\128-\191]*") do | ||
| 74 | table.insert(tb, utfChar); | ||
| 75 | end | ||
| 76 | |||
| 77 | return tb; | ||
| 78 | end | ||
| 79 | |||
| 80 | --获取字符串长度,设一个中文长度为2,其他长度为1 | ||
| 81 | function StringUtil.GetUTFLen(s) | ||
| 82 | local sTable = StringToTable(s); | ||
| 83 | |||
| 84 | local len = 0; | ||
| 85 | local charLen = 0; | ||
| 86 | |||
| 87 | for i=1,#sTable do | ||
| 88 | local utfCharLen = string.len(sTable[i]) | ||
| 89 | if utfCharLen > 1 then -- 长度大于1的就认为是中文 | ||
| 90 | charLen = 2; | ||
| 91 | else | ||
| 92 | charLen = 1; | ||
| 93 | end | ||
| 94 | |||
| 95 | len = len + charLen; | ||
| 96 | end | ||
| 97 | |||
| 98 | return len; | ||
| 99 | end | ||
| 100 | |||
| 101 | --获取指定字符个数的字符串的实际长度,设一个中文长度为2,其他长度为1,count:-1表示不限制 | ||
| 102 | local function GetUTFLenWithCount(s, count) | ||
| 103 | local sTable = StringToTable(s); | ||
| 104 | |||
| 105 | local len = 0; | ||
| 106 | local charLen = 0; | ||
| 107 | local isLimited = (count >= 0); | ||
| 108 | |||
| 109 | for i=1,#sTable do | ||
| 110 | local utfCharLen = string.len(sTable[i]); | ||
| 111 | if utfCharLen > 1 then -- 长度大于1的就认为是中文 | ||
| 112 | charLen = 2; | ||
| 113 | else | ||
| 114 | charLen = 1; | ||
| 115 | end | ||
| 116 | |||
| 117 | len = len + utfCharLen; | ||
| 118 | |||
| 119 | if isLimited then | ||
| 120 | count = count - charLen | ||
| 121 | if count <= 0 then | ||
| 122 | break; | ||
| 123 | end | ||
| 124 | end | ||
| 125 | end | ||
| 126 | |||
| 127 | return len; | ||
| 128 | end | ||
| 129 | |||
| 130 | --截取指定字符个数的字符串 | ||
| 131 | function StringUtil.getMaxLenString(s, maxLen) | ||
| 132 | local len = StringUtil.GetUTFLen(s) | ||
| 133 | |||
| 134 | local dstString = s; | ||
| 135 | -- 超长,裁剪,加... | ||
| 136 | if len > maxLen then | ||
| 137 | dstString = string.sub(s, 1, GetUTFLenWithCount(s, maxLen)); | ||
| 138 | -- dstString = dstString.."..."; | ||
| 139 | end | ||
| 140 | |||
| 141 | return dstString; | ||
| 142 | end | ||
| 143 | |||
| 144 | --在前面补零,转换为固定长度的字符串 | ||
| 145 | function StringUtil.toStringFixedZeroPrefix(value,cnt) | ||
| 146 | local str = tostring(value); | ||
| 147 | local len = string.len(str); | ||
| 148 | local num = cnt - len; | ||
| 149 | if num > 0 then | ||
| 150 | local tmp_str = str; | ||
| 151 | str = ""; | ||
| 152 | for i=1,num do | ||
| 153 | str = str.."0"; | ||
| 154 | end | ||
| 155 | str = str..tmp_str; | ||
| 156 | end | ||
| 157 | return str; | ||
| 158 | end | ||
| 159 | |||
| 160 | function StringUtil.urlEncode(s) | ||
| 161 | s = string.gsub(s, "([^%w%.%- ])", function(c) return string.format("%%%02X", string.byte(c)) end) | ||
| 162 | return string.gsub(s, " ", "+") | ||
| 163 | end | ||
| 164 | |||
| 165 | function StringUtil.urlDecode(s) | ||
| 166 | s = string.gsub(s, '%%(%x%x)', function(h) return string.char(tonumber(h, 16)) end) | ||
| 167 | return s | ||
| 168 | end | ||
| 169 | |||
| 170 | return StringUtil | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | cc.exports.TableUtil = {} | ||
| 2 | |||
| 3 | -- 检查table里是否存在 | ||
| 4 | function TableUtil.IsInTable(tbl,value) | ||
| 5 | for k,v in ipairs(tbl) do | ||
| 6 | if v == value then | ||
| 7 | return true; | ||
| 8 | end | ||
| 9 | end | ||
| 10 | return false; | ||
| 11 | end | ||
| 12 | |||
| 13 | -- 遍历数组 | ||
| 14 | function TableUtil.getn(tb) | ||
| 15 | local cnt = 0; | ||
| 16 | for k,v in pairs(tb) do | ||
| 17 | cnt = cnt + 1; | ||
| 18 | end | ||
| 19 | return cnt; | ||
| 20 | end | ||
| 21 | |||
| 22 | function TableUtil.indexOf(t,v) | ||
| 23 | local index = -1; | ||
| 24 | for i,_v in ipairs(t) do | ||
| 25 | if _v == v then | ||
| 26 | index = i; | ||
| 27 | end | ||
| 28 | end | ||
| 29 | return index; | ||
| 30 | end | ||
| 31 | |||
| 32 | function TableUtil.copyTab(st) | ||
| 33 | if not st then return nil end | ||
| 34 | local tab = {} | ||
| 35 | for k, v in pairs(st or {}) do | ||
| 36 | if type(v) ~= "table" then | ||
| 37 | tab[k] = v | ||
| 38 | else | ||
| 39 | tab[k] = TableUtil.copyTab(v) | ||
| 40 | end | ||
| 41 | end | ||
| 42 | return tab | ||
| 43 | end | ||
| 44 | |||
| 45 | function TableUtil.copy_list(list) | ||
| 46 | local new_list = {}; | ||
| 47 | for i,v in ipairs(list) do | ||
| 48 | new_list[i] = v; | ||
| 49 | end | ||
| 50 | return new_list; | ||
| 51 | end | ||
| 52 | |||
| 53 | function TableUtil.isEmpty(t) | ||
| 54 | return _G.next( t ) == nil | ||
| 55 | end | ||
| 56 | |||
| 57 | --数组合并 | ||
| 58 | function TableUtil.merge(t1,t2) | ||
| 59 | local newT = {}; | ||
| 60 | for i,v in ipairs(t1) do | ||
| 61 | newT[#newT+1] = v; | ||
| 62 | end | ||
| 63 | for i,v in ipairs(t2) do | ||
| 64 | newT[#newT+1] = v; | ||
| 65 | end | ||
| 66 | return newT; | ||
| 67 | end | ||
| 68 | |||
| 69 | --数组合并 | ||
| 70 | function TableUtil.join(t1,t2) | ||
| 71 | for i,v in ipairs(t2) do | ||
| 72 | t1[#t1+1] = v; | ||
| 73 | end | ||
| 74 | return t1; | ||
| 75 | end | ||
| 76 | |||
| 77 | return TableUtil | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | cc.exports.TextRoller = class("TextRoller") | ||
| 2 | |||
| 3 | TextRoller.jumpCnt = 10; | ||
| 4 | TextRoller.nowCnt = 0; | ||
| 5 | |||
| 6 | TextRoller.txt = nil; | ||
| 7 | TextRoller.startNum = 0; | ||
| 8 | TextRoller.endNum = 0; | ||
| 9 | TextRoller.intervalNum = 0; | ||
| 10 | |||
| 11 | function TextRoller:update() | ||
| 12 | if self.nowCnt < self.jumpCnt then | ||
| 13 | self.startNum = self.startNum + self.intervalNum; | ||
| 14 | self.txt:setString(self.startNum); | ||
| 15 | self.nowCnt = self.nowCnt + 1; | ||
| 16 | self.txt:runAction(cc.Sequence:create(cc.DelayTime:create(0.05),cc.CallFunc:create(handler(self,self.update)))) | ||
| 17 | else | ||
| 18 | self.txt:setString(self.endNum); | ||
| 19 | end | ||
| 20 | end | ||
| 21 | |||
| 22 | function TextRoller:ctor(_txt,_startNum,_endNum) | ||
| 23 | self.txt = _txt; | ||
| 24 | self.startNum = _startNum; | ||
| 25 | self.endNum = _endNum; | ||
| 26 | |||
| 27 | if math.abs(self.endNum - self.startNum) < self.jumpCnt then | ||
| 28 | self.jumpCnt = self.endNum - self.startNum; | ||
| 29 | end | ||
| 30 | |||
| 31 | self.intervalNum = math.floor((self.endNum - self.startNum)/self.jumpCnt); | ||
| 32 | self.nowCnt = 0; | ||
| 33 | |||
| 34 | self:update(); | ||
| 35 | self.txt:runAction(cc.Sequence:create(cc.DelayTime:create(0.05),cc.CallFunc:create(handler(self,self.update)))) | ||
| 36 | end | ||
| 37 | |||
| 38 | return TextRoller | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | cc.exports.TimeUtil = {} | ||
| 2 | |||
| 3 | function TimeUtil.getMS(time) | ||
| 4 | local m = math.floor(time/60); | ||
| 5 | local s = math.floor(time%60); | ||
| 6 | m = CustomMath:AndOr( m<10, "0"..m, m ); | ||
| 7 | s = CustomMath:AndOr( s<10, "0"..s, s ); | ||
| 8 | return m,s | ||
| 9 | end | ||
| 10 | |||
| 11 | function TimeUtil.getHMS(time) | ||
| 12 | local h = math.floor(time/3600); | ||
| 13 | local m = math.floor((time%3600)/60); | ||
| 14 | local s = math.floor((time%3600)%60); | ||
| 15 | h = CustomMath:AndOr( h<10, "0"..h, h ); | ||
| 16 | m = CustomMath:AndOr( m<10, "0"..m, m ); | ||
| 17 | s = CustomMath:AndOr( s<10, "0"..s, s ); | ||
| 18 | return h,m,s | ||
| 19 | end | ||
| 20 | |||
| 21 | --根据秒 返回天 时 分 秒 | ||
| 22 | function TimeUtil.getDHMS(time) | ||
| 23 | local d = math.floor(time/(3600*24)); | ||
| 24 | local d_leftm = time%(3600*24) | ||
| 25 | local h = math.floor(d_leftm/3600); | ||
| 26 | local m = math.floor((d_leftm%3600)/60); | ||
| 27 | local s = math.floor((d_leftm%3600)%60); | ||
| 28 | -- d = CustomMath:AndOr( d<10, "0"..d, d ); | ||
| 29 | -- h = CustomMath:AndOr( h<10, "0"..h, h ); | ||
| 30 | -- m = CustomMath:AndOr( m<10, "0"..m, m ); | ||
| 31 | -- s = CustomMath:AndOr( s<10, "0"..s, s ); | ||
| 32 | return d,h,m,s | ||
| 33 | end | ||
| 34 | |||
| 35 | function TimeUtil.isToday(timestamp,nowtime) | ||
| 36 | local today = nil; | ||
| 37 | if nowtime and nowtime > 0 then | ||
| 38 | today = os.date("*t",nowtime); | ||
| 39 | else | ||
| 40 | today = os.date("*t"); | ||
| 41 | end | ||
| 42 | local secondOfToday = os.time({day=today.day, month=today.month,year=today.year, hour=0, min=0, sec=0}); | ||
| 43 | if timestamp >= secondOfToday and timestamp < secondOfToday + 24 * 60 * 60 then | ||
| 44 | return true | ||
| 45 | else | ||
| 46 | return false | ||
| 47 | end | ||
| 48 | end | ||
| 49 | |||
| 50 | function TimeUtil.changeToChinaWeekday(w) | ||
| 51 | local weekday = (w+6)%7; | ||
| 52 | if weekday == 0 then | ||
| 53 | weekday = 7; | ||
| 54 | end | ||
| 55 | return weekday; | ||
| 56 | end | ||
| 57 | |||
| 58 | ------------农历转换函数----------- | ||
| 59 | function TimeUtil.GetLunalTime(stime) | ||
| 60 | local st = os.date("*t",stime); | ||
| 61 | print('公历', st.year, st.month, st.day,st.hour,st.min,st.sec); | ||
| 62 | --天干名称 | ||
| 63 | local cTianGan = {"甲","乙","丙","丁","戊","己","庚","辛","壬","癸"} | ||
| 64 | --地支名称 | ||
| 65 | local cDiZhi = {"子","丑","寅","卯","辰","巳","午", "未","申","酉","戌","亥"} | ||
| 66 | --属相名称 | ||
| 67 | local cShuXiang = {"鼠","牛","虎","兔","龙","蛇", "马","羊","猴","鸡","狗","猪"} | ||
| 68 | --农历日期名 | ||
| 69 | local cDayName = | ||
| 70 | { | ||
| 71 | "*","初一","初二","初三","初四","初五", | ||
| 72 | "初六","初七","初八","初九","初十", | ||
| 73 | "十一","十二","十三","十四","十五", | ||
| 74 | "十六","十七","十八","十九","二十", | ||
| 75 | "廿一","廿二","廿三","廿四","廿五", | ||
| 76 | "廿六","廿七","廿八","廿九","三十" | ||
| 77 | } | ||
| 78 | --农历月份名 | ||
| 79 | local cMonName = {"*","正","二","三","四","五","六", "七","八","九","十","十一","腊"} | ||
| 80 | |||
| 81 | --公历每月前面的天数 | ||
| 82 | local wMonthAdd = {0,31,59,90,120,151,181,212,243,273,304,334} | ||
| 83 | -- 农历数据 | ||
| 84 | local wNongliData = {2635,333387,1701,1748,267701,694,2391,133423,1175,396438 | ||
| 85 | ,3402,3749,331177,1453,694,201326,2350,465197,3221,3402 | ||
| 86 | ,400202,2901,1386,267611,605,2349,137515,2709,464533,1738 | ||
| 87 | ,2901,330421,1242,2651,199255,1323,529706,3733,1706,398762 | ||
| 88 | ,2741,1206,267438,2647,1318,204070,3477,461653,1386,2413 | ||
| 89 | ,330077,1197,2637,268877,3365,531109,2900,2922,398042,2395 | ||
| 90 | ,1179,267415,2635,661067,1701,1748,398772,2742,2391,330031 | ||
| 91 | ,1175,1611,200010,3749,527717,1452,2742,332397,2350,3222 | ||
| 92 | ,268949,3402,3493,133973,1386,464219,605,2349,334123,2709 | ||
| 93 | ,2890,267946,2773,592565,1210,2651,395863,1323,2707,265877} | ||
| 94 | |||
| 95 | local wCurYear,wCurMonth,wCurDay; | ||
| 96 | local nTheDate,nIsEnd,m,k,n,i,nBit; | ||
| 97 | local szNongli, szNongliDay,szShuXiang; | ||
| 98 | ---取当前公历年、月、日--- | ||
| 99 | wCurYear = st.year; | ||
| 100 | wCurMonth = st.month; | ||
| 101 | wCurDay = st.day; | ||
| 102 | ---计算到初始时间1921年2月8日的天数:1921-2-8(正月初一)--- | ||
| 103 | nTheDate = (wCurYear - 1921) * 365 + (wCurYear - 1921) / 4 + wCurDay + wMonthAdd[wCurMonth] - 38 | ||
| 104 | if (((wCurYear % 4) == 0) and (wCurMonth > 2)) then | ||
| 105 | nTheDate = nTheDate + 1 | ||
| 106 | end | ||
| 107 | |||
| 108 | |||
| 109 | --计算农历天干、地支、月、日--- | ||
| 110 | nIsEnd = 0; | ||
| 111 | m = 0; | ||
| 112 | while nIsEnd ~= 1 do | ||
| 113 | if wNongliData[m+1] < 4095 then | ||
| 114 | k = 11; | ||
| 115 | else | ||
| 116 | k = 12; | ||
| 117 | end | ||
| 118 | n = k; | ||
| 119 | while n>=0 do | ||
| 120 | --获取wNongliData(m)的第n个二进制位的值 | ||
| 121 | nBit = wNongliData[m+1]; | ||
| 122 | for i=1,n do | ||
| 123 | nBit = math.floor(nBit/2); | ||
| 124 | end | ||
| 125 | |||
| 126 | nBit = nBit % 2; | ||
| 127 | |||
| 128 | |||
| 129 | if nTheDate <= (29 + nBit) then | ||
| 130 | nIsEnd = 1; | ||
| 131 | break; | ||
| 132 | end | ||
| 133 | |||
| 134 | nTheDate = nTheDate - 29 - nBit; | ||
| 135 | n = n - 1; | ||
| 136 | end | ||
| 137 | if nIsEnd ~= 0 then | ||
| 138 | break; | ||
| 139 | end | ||
| 140 | m = m + 1; | ||
| 141 | end | ||
| 142 | |||
| 143 | wCurYear = 1921 + m; | ||
| 144 | wCurMonth = k - n + 1; | ||
| 145 | wCurDay = math.floor(nTheDate); | ||
| 146 | if k == 12 then | ||
| 147 | if wCurMonth == wNongliData[m+1] / 65536 + 1 then | ||
| 148 | wCurMonth = 1 - wCurMonth; | ||
| 149 | elseif wCurMonth > wNongliData[m+1] / 65536 + 1 then | ||
| 150 | wCurMonth = wCurMonth - 1; | ||
| 151 | end | ||
| 152 | end | ||
| 153 | |||
| 154 | local lunalSecond = os.time({day=wCurDay, month=wCurMonth,year=wCurYear, hour=st.hour, min=st.min, sec=st.sec}); | ||
| 155 | local luaDate = os.date("*t",lunalSecond); | ||
| 156 | print('农历', luaDate.year, luaDate.month, luaDate.day,luaDate.hour,luaDate.min,luaDate.sec); | ||
| 157 | return lunalSecond; | ||
| 158 | -- --生成农历天干、地支、属相 ==> wNongli-- | ||
| 159 | -- szShuXiang = cShuXiang[(((wCurYear - 4) % 60) % 12) + 1] | ||
| 160 | -- szShuXiang = cShuXiang[(((wCurYear - 4) % 60) % 12) + 1]; | ||
| 161 | -- szNongli = szShuXiang .. '(' .. cTianGan[(((wCurYear - 4) % 60) % 10)+1] .. cDiZhi[(((wCurYear - 4) % 60) % 12) + 1] .. ')年' | ||
| 162 | -- --szNongli,"%s(%s%s)年",szShuXiang,cTianGan[((wCurYear - 4) % 60) % 10],cDiZhi[((wCurYear - 4) % 60) % 12]); | ||
| 163 | |||
| 164 | -- --生成农历月、日 ==> wNongliDay--*/ | ||
| 165 | -- if wCurMonth < 1 then | ||
| 166 | -- szNongliDay = "闰" .. cMonName[(-1 * wCurMonth) + 1] | ||
| 167 | -- else | ||
| 168 | -- szNongliDay = cMonName[wCurMonth+1] | ||
| 169 | -- end | ||
| 170 | |||
| 171 | -- szNongliDay = szNongliDay .. "月" .. cDayName[wCurDay+1] | ||
| 172 | -- return szNongli .. szNongliDay | ||
| 173 | end | ||
| 174 | |||
| 175 | --换算成当前年所对应的时间戳 如time为2017年5月1日 now_time时间为2018年2月15日 则返回时间为2018年5月1日所对应的时间戳 | ||
| 176 | function TimeUtil.toNowYearTime(time,now_year) | ||
| 177 | local new_time = 0; | ||
| 178 | if time > 0 and now_year > 0 then | ||
| 179 | local time_date = os.date("*t",time); | ||
| 180 | new_time = os.time({day=time_date.day, month=time_date.month,year=now_year, hour=time_date.hour, min=time_date.min, sec=time_date.sec}); | ||
| 181 | else | ||
| 182 | new_time = time; | ||
| 183 | end | ||
| 184 | return new_time; | ||
| 185 | end | ||
| 186 | |||
| 187 | return TimeUtil | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | ---------------- | ||
| 2 | --- Lua 5.1/5.2 compatibility | ||
| 3 | -- Ensures that `table.pack` and `package.searchpath` are available | ||
| 4 | -- for Lua 5.1 and LuaJIT. | ||
| 5 | -- The exported function `load` is Lua 5.2 compatible. | ||
| 6 | -- `compat.setfenv` and `compat.getfenv` are available for Lua 5.2, although | ||
| 7 | -- they are not always guaranteed to work. | ||
| 8 | -- @module pl.compat | ||
| 9 | |||
| 10 | local compat = {} | ||
| 11 | |||
| 12 | compat.lua51 = _VERSION == 'Lua 5.1' | ||
| 13 | |||
| 14 | --- execute a shell command. | ||
| 15 | -- This is a compatibility function that returns the same for Lua 5.1 and Lua 5.2 | ||
| 16 | -- @param cmd a shell command | ||
| 17 | -- @return true if successful | ||
| 18 | -- @return actual return code | ||
| 19 | function compat.execute (cmd) | ||
| 20 | local res1,res2,res2 = os.execute(cmd) | ||
| 21 | if compat.lua51 then | ||
| 22 | return res1==0,res1 | ||
| 23 | else | ||
| 24 | return not not res1,res2 | ||
| 25 | end | ||
| 26 | end | ||
| 27 | |||
| 28 | ---------------- | ||
| 29 | -- Load Lua code as a text or binary chunk. | ||
| 30 | -- @param ld code string or loader | ||
| 31 | -- @param[opt] source name of chunk for errors | ||
| 32 | -- @param[opt] mode 'b', 't' or 'bt' | ||
| 33 | -- @param[opt] env environment to load the chunk in | ||
| 34 | -- @function compat.load | ||
| 35 | |||
| 36 | --------------- | ||
| 37 | -- Get environment of a function. | ||
| 38 | -- With Lua 5.2, may return nil for a function with no global references! | ||
| 39 | -- Based on code by [Sergey Rozhenko](http://lua-users.org/lists/lua-l/2010-06/msg00313.html) | ||
| 40 | -- @param f a function or a call stack reference | ||
| 41 | -- @function compat.setfenv | ||
| 42 | |||
| 43 | --------------- | ||
| 44 | -- Set environment of a function | ||
| 45 | -- @param f a function or a call stack reference | ||
| 46 | -- @param env a table that becomes the new environment of `f` | ||
| 47 | -- @function compat.setfenv | ||
| 48 | |||
| 49 | if compat.lua51 then -- define Lua 5.2 style load() | ||
| 50 | if not tostring(assert):match 'builtin' then -- but LuaJIT's load _is_ compatible | ||
| 51 | local lua51_load = load | ||
| 52 | function compat.load(str,src,mode,env) | ||
| 53 | local chunk,err | ||
| 54 | if type(str) == 'string' then | ||
| 55 | if str:byte(1) == 27 and not (mode or 'bt'):find 'b' then | ||
| 56 | return nil,"attempt to load a binary chunk" | ||
| 57 | end | ||
| 58 | chunk,err = loadstring(str,src) | ||
| 59 | else | ||
| 60 | chunk,err = lua51_load(str,src) | ||
| 61 | end | ||
| 62 | if chunk and env then setfenv(chunk,env) end | ||
| 63 | return chunk,err | ||
| 64 | end | ||
| 65 | else | ||
| 66 | compat.load = load | ||
| 67 | end | ||
| 68 | compat.setfenv, compat.getfenv = setfenv, getfenv | ||
| 69 | else | ||
| 70 | compat.load = load | ||
| 71 | -- setfenv/getfenv replacements for Lua 5.2 | ||
| 72 | -- by Sergey Rozhenko | ||
| 73 | -- http://lua-users.org/lists/lua-l/2010-06/msg00313.html | ||
| 74 | -- Roberto Ierusalimschy notes that it is possible for getfenv to return nil | ||
| 75 | -- in the case of a function with no globals: | ||
| 76 | -- http://lua-users.org/lists/lua-l/2010-06/msg00315.html | ||
| 77 | function compat.setfenv(f, t) | ||
| 78 | f = (type(f) == 'function' and f or debug.getinfo(f + 1, 'f').func) | ||
| 79 | local name | ||
| 80 | local up = 0 | ||
| 81 | repeat | ||
| 82 | up = up + 1 | ||
| 83 | name = debug.getupvalue(f, up) | ||
| 84 | until name == '_ENV' or name == nil | ||
| 85 | if name then | ||
| 86 | debug.upvaluejoin(f, up, function() return name end, 1) -- use unique upvalue | ||
| 87 | debug.setupvalue(f, up, t) | ||
| 88 | end | ||
| 89 | if f ~= 0 then return f end | ||
| 90 | end | ||
| 91 | |||
| 92 | function compat.getfenv(f) | ||
| 93 | local f = f or 0 | ||
| 94 | f = (type(f) == 'function' and f or debug.getinfo(f + 1, 'f').func) | ||
| 95 | local name, val | ||
| 96 | local up = 0 | ||
| 97 | repeat | ||
| 98 | up = up + 1 | ||
| 99 | name, val = debug.getupvalue(f, up) | ||
| 100 | until name == '_ENV' or name == nil | ||
| 101 | return val | ||
| 102 | end | ||
| 103 | end | ||
| 104 | |||
| 105 | --- Lua 5.2 Functions Available for 5.1 | ||
| 106 | -- @section lua52 | ||
| 107 | |||
| 108 | --- pack an argument list into a table. | ||
| 109 | -- @param ... any arguments | ||
| 110 | -- @return a table with field n set to the length | ||
| 111 | -- @return the length | ||
| 112 | -- @function table.pack | ||
| 113 | if not table.pack then | ||
| 114 | function table.pack (...) | ||
| 115 | return {n=select('#',...); ...} | ||
| 116 | end | ||
| 117 | end | ||
| 118 | |||
| 119 | ------ | ||
| 120 | -- return the full path where a Lua module name would be matched. | ||
| 121 | -- @param mod module name, possibly dotted | ||
| 122 | -- @param path a path in the same form as package.path or package.cpath | ||
| 123 | -- @see path.package_path | ||
| 124 | -- @function package.searchpath | ||
| 125 | if not package.searchpath then | ||
| 126 | local sep = package.config:sub(1,1) | ||
| 127 | function package.searchpath (mod,path) | ||
| 128 | mod = mod:gsub('%.',sep) | ||
| 129 | for m in path:gmatch('[^;]+') do | ||
| 130 | local nm = m:gsub('?',mod) | ||
| 131 | local f = io.open(nm,'r') | ||
| 132 | if f then f:close(); return nm end | ||
| 133 | end | ||
| 134 | end | ||
| 135 | end | ||
| 136 | |||
| 137 | return compat |
| 1 | --- Generally useful routines. | ||
| 2 | -- See @{01-introduction.md.Generally_useful_functions|the Guide}. | ||
| 3 | -- @module pl.utils | ||
| 4 | local format,gsub,byte = string.format,string.gsub,string.byte | ||
| 5 | local compat = import '.compat' | ||
| 6 | local clock = os.clock | ||
| 7 | local stdout = io.stdout | ||
| 8 | local append = table.insert | ||
| 9 | local unpack = rawget(_G,'unpack') or rawget(table,'unpack') | ||
| 10 | |||
| 11 | local collisions = {} | ||
| 12 | |||
| 13 | local utils = { | ||
| 14 | _VERSION = "1.2.1", | ||
| 15 | lua51 = compat.lua51, | ||
| 16 | setfenv = compat.setfenv, | ||
| 17 | getfenv = compat.getfenv, | ||
| 18 | load = compat.load, | ||
| 19 | execute = compat.execute, | ||
| 20 | dir_separator = _G.package.config:sub(1,1), | ||
| 21 | unpack = unpack | ||
| 22 | } | ||
| 23 | |||
| 24 | --- end this program gracefully. | ||
| 25 | -- @param code The exit code or a message to be printed | ||
| 26 | -- @param ... extra arguments for message's format' | ||
| 27 | -- @see utils.fprintf | ||
| 28 | function utils.quit(code,...) | ||
| 29 | if type(code) == 'string' then | ||
| 30 | utils.fprintf(io.stderr,code,...) | ||
| 31 | code = -1 | ||
| 32 | else | ||
| 33 | utils.fprintf(io.stderr,...) | ||
| 34 | end | ||
| 35 | io.stderr:write('\n') | ||
| 36 | os.exit(code) | ||
| 37 | end | ||
| 38 | |||
| 39 | --- print an arbitrary number of arguments using a format. | ||
| 40 | -- @param fmt The format (see string.format) | ||
| 41 | -- @param ... Extra arguments for format | ||
| 42 | function utils.printf(fmt,...) | ||
| 43 | utils.assert_string(1,fmt) | ||
| 44 | utils.fprintf(stdout,fmt,...) | ||
| 45 | end | ||
| 46 | |||
| 47 | --- write an arbitrary number of arguments to a file using a format. | ||
| 48 | -- @param f File handle to write to. | ||
| 49 | -- @param fmt The format (see string.format). | ||
| 50 | -- @param ... Extra arguments for format | ||
| 51 | function utils.fprintf(f,fmt,...) | ||
| 52 | utils.assert_string(2,fmt) | ||
| 53 | f:write(format(fmt,...)) | ||
| 54 | end | ||
| 55 | |||
| 56 | local function import_symbol(T,k,v,libname) | ||
| 57 | local key = rawget(T,k) | ||
| 58 | -- warn about collisions! | ||
| 59 | if key and k ~= '_M' and k ~= '_NAME' and k ~= '_PACKAGE' and k ~= '_VERSION' then | ||
| 60 | utils.printf("warning: '%s.%s' overrides existing symbol\n",libname,k) | ||
| 61 | end | ||
| 62 | rawset(T,k,v) | ||
| 63 | end | ||
| 64 | |||
| 65 | local function lookup_lib(T,t) | ||
| 66 | for k,v in pairs(T) do | ||
| 67 | if v == t then return k end | ||
| 68 | end | ||
| 69 | return '?' | ||
| 70 | end | ||
| 71 | |||
| 72 | local already_imported = {} | ||
| 73 | |||
| 74 | --- take a table and 'inject' it into the local namespace. | ||
| 75 | -- @param t The Table | ||
| 76 | -- @param T An optional destination table (defaults to callers environment) | ||
| 77 | function utils.import(t,T) | ||
| 78 | T = T or _G | ||
| 79 | t = t or utils | ||
| 80 | if type(t) == 'string' then | ||
| 81 | t = require (t) | ||
| 82 | end | ||
| 83 | local libname = lookup_lib(T,t) | ||
| 84 | if already_imported[t] then return end | ||
| 85 | already_imported[t] = libname | ||
| 86 | for k,v in pairs(t) do | ||
| 87 | import_symbol(T,k,v,libname) | ||
| 88 | end | ||
| 89 | end | ||
| 90 | |||
| 91 | utils.patterns = { | ||
| 92 | FLOAT = '[%+%-%d]%d*%.?%d*[eE]?[%+%-]?%d*', | ||
| 93 | INTEGER = '[+%-%d]%d*', | ||
| 94 | IDEN = '[%a_][%w_]*', | ||
| 95 | FILE = '[%a%.\\][:%][%w%._%-\\]*' | ||
| 96 | } | ||
| 97 | |||
| 98 | --- escape any 'magic' characters in a string | ||
| 99 | -- @param s The input string | ||
| 100 | function utils.escape(s) | ||
| 101 | utils.assert_string(1,s) | ||
| 102 | return (s:gsub('[%-%.%+%[%]%(%)%$%^%%%?%*]','%%%1')) | ||
| 103 | end | ||
| 104 | |||
| 105 | --- return either of two values, depending on a condition. | ||
| 106 | -- @param cond A condition | ||
| 107 | -- @param value1 Value returned if cond is true | ||
| 108 | -- @param value2 Value returned if cond is false (can be optional) | ||
| 109 | function utils.choose(cond,value1,value2) | ||
| 110 | if cond then return value1 | ||
| 111 | else return value2 | ||
| 112 | end | ||
| 113 | end | ||
| 114 | |||
| 115 | local raise | ||
| 116 | |||
| 117 | --- return the contents of a file as a string | ||
| 118 | -- @param filename The file path | ||
| 119 | -- @param is_bin open in binary mode | ||
| 120 | -- @return file contents | ||
| 121 | function utils.readfile(filename,is_bin) | ||
| 122 | local mode = is_bin and 'b' or '' | ||
| 123 | utils.assert_string(1,filename) | ||
| 124 | local f,err = io.open(filename,'r'..mode) | ||
| 125 | if not f then return utils.raise (err) end | ||
| 126 | local res,err = f:read('*a') | ||
| 127 | f:close() | ||
| 128 | if not res then return raise (err) end | ||
| 129 | return res | ||
| 130 | end | ||
| 131 | |||
| 132 | --- write a string to a file | ||
| 133 | -- @param filename The file path | ||
| 134 | -- @param str The string | ||
| 135 | -- @return true or nil | ||
| 136 | -- @return error message | ||
| 137 | -- @raise error if filename or str aren't strings | ||
| 138 | function utils.writefile(filename,str) | ||
| 139 | utils.assert_string(1,filename) | ||
| 140 | utils.assert_string(2,str) | ||
| 141 | local f,err = io.open(filename,'w') | ||
| 142 | if not f then return raise(err) end | ||
| 143 | f:write(str) | ||
| 144 | f:close() | ||
| 145 | return true | ||
| 146 | end | ||
| 147 | |||
| 148 | --- return the contents of a file as a list of lines | ||
| 149 | -- @param filename The file path | ||
| 150 | -- @return file contents as a table | ||
| 151 | -- @raise errror if filename is not a string | ||
| 152 | function utils.readlines(filename) | ||
| 153 | utils.assert_string(1,filename) | ||
| 154 | local f,err = io.open(filename,'r') | ||
| 155 | if not f then return raise(err) end | ||
| 156 | local res = {} | ||
| 157 | for line in f:lines() do | ||
| 158 | append(res,line) | ||
| 159 | end | ||
| 160 | f:close() | ||
| 161 | return res | ||
| 162 | end | ||
| 163 | |||
| 164 | --- split a string into a list of strings separated by a delimiter. | ||
| 165 | -- @param s The input string | ||
| 166 | -- @param re A Lua string pattern; defaults to '%s+' | ||
| 167 | -- @param plain don't use Lua patterns | ||
| 168 | -- @param n optional maximum number of splits | ||
| 169 | -- @return a list-like table | ||
| 170 | -- @raise error if s is not a string | ||
| 171 | function utils.split(s,re,plain,n) | ||
| 172 | utils.assert_string(1,s) | ||
| 173 | local find,sub,append = string.find, string.sub, table.insert | ||
| 174 | local i1,ls = 1,{} | ||
| 175 | if not re then re = '%s+' end | ||
| 176 | if re == '' then return {s} end | ||
| 177 | while true do | ||
| 178 | local i2,i3 = find(s,re,i1,plain) | ||
| 179 | if not i2 then | ||
| 180 | local last = sub(s,i1) | ||
| 181 | if last ~= '' then append(ls,last) end | ||
| 182 | if #ls == 1 and ls[1] == '' then | ||
| 183 | return {} | ||
| 184 | else | ||
| 185 | return ls | ||
| 186 | end | ||
| 187 | end | ||
| 188 | append(ls,sub(s,i1,i2-1)) | ||
| 189 | if n and #ls == n then | ||
| 190 | ls[#ls] = sub(s,i1) | ||
| 191 | return ls | ||
| 192 | end | ||
| 193 | i1 = i3+1 | ||
| 194 | end | ||
| 195 | end | ||
| 196 | |||
| 197 | --- split a string into a number of values. | ||
| 198 | -- @param s the string | ||
| 199 | -- @param re the delimiter, default space | ||
| 200 | -- @return n values | ||
| 201 | -- @usage first,next = splitv('jane:doe',':') | ||
| 202 | -- @see split | ||
| 203 | function utils.splitv (s,re) | ||
| 204 | return unpack(utils.split(s,re)) | ||
| 205 | end | ||
| 206 | |||
| 207 | --- convert an array of values to strings. | ||
| 208 | -- @param t a list-like table | ||
| 209 | -- @param temp buffer to use, otherwise allocate | ||
| 210 | -- @param tostr custom tostring function, called with (value,index). | ||
| 211 | -- Otherwise use `tostring` | ||
| 212 | -- @return the converted buffer | ||
| 213 | function utils.array_tostring (t,temp,tostr) | ||
| 214 | temp, tostr = temp or {}, tostr or tostring | ||
| 215 | for i = 1,#t do | ||
| 216 | temp[i] = tostr(t[i],i) | ||
| 217 | end | ||
| 218 | return temp | ||
| 219 | end | ||
| 220 | |||
| 221 | --- execute a shell command and return the output. | ||
| 222 | -- This function redirects the output to tempfiles and returns the content of those files. | ||
| 223 | -- @param cmd a shell command | ||
| 224 | -- @param bin boolean, if true, read output as binary file | ||
| 225 | -- @return true if successful | ||
| 226 | -- @return actual return code | ||
| 227 | -- @return stdout output (string) | ||
| 228 | -- @return errout output (string) | ||
| 229 | function utils.executeex(cmd, bin) | ||
| 230 | local mode | ||
| 231 | local outfile = os.tmpname() | ||
| 232 | local errfile = os.tmpname() | ||
| 233 | |||
| 234 | if utils.dir_separator == '\\' then | ||
| 235 | outfile = os.getenv('TEMP')..outfile | ||
| 236 | errfile = os.getenv('TEMP')..errfile | ||
| 237 | end | ||
| 238 | cmd = cmd .. [[ >"]]..outfile..[[" 2>"]]..errfile..[["]] | ||
| 239 | |||
| 240 | local success, retcode = utils.execute(cmd) | ||
| 241 | local outcontent = utils.readfile(outfile, bin) | ||
| 242 | local errcontent = utils.readfile(errfile, bin) | ||
| 243 | os.remove(outfile) | ||
| 244 | os.remove(errfile) | ||
| 245 | return success, retcode, (outcontent or ""), (errcontent or "") | ||
| 246 | end | ||
| 247 | |||
| 248 | --- 'memoize' a function (cache returned value for next call). | ||
| 249 | -- This is useful if you have a function which is relatively expensive, | ||
| 250 | -- but you don't know in advance what values will be required, so | ||
| 251 | -- building a table upfront is wasteful/impossible. | ||
| 252 | -- @param func a function of at least one argument | ||
| 253 | -- @return a function with at least one argument, which is used as the key. | ||
| 254 | function utils.memoize(func) | ||
| 255 | return setmetatable({}, { | ||
| 256 | __index = function(self, k, ...) | ||
| 257 | local v = func(k,...) | ||
| 258 | self[k] = v | ||
| 259 | return v | ||
| 260 | end, | ||
| 261 | __call = function(self, k) return self[k] end | ||
| 262 | }) | ||
| 263 | end | ||
| 264 | |||
| 265 | |||
| 266 | utils.stdmt = { | ||
| 267 | List = {_name='List'}, Map = {_name='Map'}, | ||
| 268 | Set = {_name='Set'}, MultiMap = {_name='MultiMap'} | ||
| 269 | } | ||
| 270 | |||
| 271 | local _function_factories = {} | ||
| 272 | |||
| 273 | --- associate a function factory with a type. | ||
| 274 | -- A function factory takes an object of the given type and | ||
| 275 | -- returns a function for evaluating it | ||
| 276 | -- @tab mt metatable | ||
| 277 | -- @func fun a callable that returns a function | ||
| 278 | function utils.add_function_factory (mt,fun) | ||
| 279 | _function_factories[mt] = fun | ||
| 280 | end | ||
| 281 | |||
| 282 | local function _string_lambda(f) | ||
| 283 | local raise = utils.raise | ||
| 284 | if f:find '^|' or f:find '_' then | ||
| 285 | local args,body = f:match '|([^|]*)|(.+)' | ||
| 286 | if f:find '_' then | ||
| 287 | args = '_' | ||
| 288 | body = f | ||
| 289 | else | ||
| 290 | if not args then return raise 'bad string lambda' end | ||
| 291 | end | ||
| 292 | local fstr = 'return function('..args..') return '..body..' end' | ||
| 293 | local fn,err = utils.load(fstr) | ||
| 294 | if not fn then return raise(err) end | ||
| 295 | fn = fn() | ||
| 296 | return fn | ||
| 297 | else return raise 'not a string lambda' | ||
| 298 | end | ||
| 299 | end | ||
| 300 | |||
| 301 | --- an anonymous function as a string. This string is either of the form | ||
| 302 | -- '|args| expression' or is a function of one argument, '_' | ||
| 303 | -- @param lf function as a string | ||
| 304 | -- @return a function | ||
| 305 | -- @usage string_lambda '|x|x+1' (2) == 3 | ||
| 306 | -- @usage string_lambda '_+1 (2) == 3 | ||
| 307 | -- @function utils.string_lambda | ||
| 308 | utils.string_lambda = utils.memoize(_string_lambda) | ||
| 309 | |||
| 310 | local ops | ||
| 311 | |||
| 312 | --- process a function argument. | ||
| 313 | -- This is used throughout Penlight and defines what is meant by a function: | ||
| 314 | -- Something that is callable, or an operator string as defined by <code>pl.operator</code>, | ||
| 315 | -- such as '>' or '#'. If a function factory has been registered for the type, it will | ||
| 316 | -- be called to get the function. | ||
| 317 | -- @param idx argument index | ||
| 318 | -- @param f a function, operator string, or callable object | ||
| 319 | -- @param msg optional error message | ||
| 320 | -- @return a callable | ||
| 321 | -- @raise if idx is not a number or if f is not callable | ||
| 322 | function utils.function_arg (idx,f,msg) | ||
| 323 | utils.assert_arg(1,idx,'number') | ||
| 324 | local tp = type(f) | ||
| 325 | if tp == 'function' then return f end -- no worries! | ||
| 326 | -- ok, a string can correspond to an operator (like '==') | ||
| 327 | if tp == 'string' then | ||
| 328 | if not ops then ops = require 'pl.operator'.optable end | ||
| 329 | local fn = ops[f] | ||
| 330 | if fn then return fn end | ||
| 331 | local fn, err = utils.string_lambda(f) | ||
| 332 | if not fn then error(err..': '..f) end | ||
| 333 | return fn | ||
| 334 | elseif tp == 'table' or tp == 'userdata' then | ||
| 335 | local mt = getmetatable(f) | ||
| 336 | if not mt then error('not a callable object',2) end | ||
| 337 | local ff = _function_factories[mt] | ||
| 338 | if not ff then | ||
| 339 | if not mt.__call then error('not a callable object',2) end | ||
| 340 | return f | ||
| 341 | else | ||
| 342 | return ff(f) -- we have a function factory for this type! | ||
| 343 | end | ||
| 344 | end | ||
| 345 | if not msg then msg = " must be callable" end | ||
| 346 | if idx > 0 then | ||
| 347 | error("argument "..idx..": "..msg,2) | ||
| 348 | else | ||
| 349 | error(msg,2) | ||
| 350 | end | ||
| 351 | end | ||
| 352 | |||
| 353 | --- bind the first argument of the function to a value. | ||
| 354 | -- @param fn a function of at least two values (may be an operator string) | ||
| 355 | -- @param p a value | ||
| 356 | -- @return a function such that f(x) is fn(p,x) | ||
| 357 | -- @raise same as @{function_arg} | ||
| 358 | -- @see func.bind1 | ||
| 359 | function utils.bind1 (fn,p) | ||
| 360 | fn = utils.function_arg(1,fn) | ||
| 361 | return function(...) return fn(p,...) end | ||
| 362 | end | ||
| 363 | |||
| 364 | --- bind the second argument of the function to a value. | ||
| 365 | -- @param fn a function of at least two values (may be an operator string) | ||
| 366 | -- @param p a value | ||
| 367 | -- @return a function such that f(x) is fn(x,p) | ||
| 368 | -- @raise same as @{function_arg} | ||
| 369 | function utils.bind2 (fn,p) | ||
| 370 | fn = utils.function_arg(1,fn) | ||
| 371 | return function(x,...) return fn(x,p,...) end | ||
| 372 | end | ||
| 373 | |||
| 374 | |||
| 375 | --- assert that the given argument is in fact of the correct type. | ||
| 376 | -- @param n argument index | ||
| 377 | -- @param val the value | ||
| 378 | -- @param tp the type | ||
| 379 | -- @param verify an optional verfication function | ||
| 380 | -- @param msg an optional custom message | ||
| 381 | -- @param lev optional stack position for trace, default 2 | ||
| 382 | -- @raise if the argument n is not the correct type | ||
| 383 | -- @usage assert_arg(1,t,'table') | ||
| 384 | -- @usage assert_arg(n,val,'string',path.isdir,'not a directory') | ||
| 385 | function utils.assert_arg (n,val,tp,verify,msg,lev) | ||
| 386 | if type(val) ~= tp then | ||
| 387 | error(("argument %d expected a '%s', got a '%s'"):format(n,tp,type(val)),lev or 2) | ||
| 388 | end | ||
| 389 | if verify and not verify(val) then | ||
| 390 | error(("argument %d: '%s' %s"):format(n,val,msg),lev or 2) | ||
| 391 | end | ||
| 392 | end | ||
| 393 | |||
| 394 | --- assert the common case that the argument is a string. | ||
| 395 | -- @param n argument index | ||
| 396 | -- @param val a value that must be a string | ||
| 397 | -- @raise val must be a string | ||
| 398 | function utils.assert_string (n,val) | ||
| 399 | utils.assert_arg(n,val,'string',nil,nil,3) | ||
| 400 | end | ||
| 401 | |||
| 402 | local err_mode = 'default' | ||
| 403 | |||
| 404 | --- control the error strategy used by Penlight. | ||
| 405 | -- Controls how <code>utils.raise</code> works; the default is for it | ||
| 406 | -- to return nil and the error string, but if the mode is 'error' then | ||
| 407 | -- it will throw an error. If mode is 'quit' it will immediately terminate | ||
| 408 | -- the program. | ||
| 409 | -- @param mode - either 'default', 'quit' or 'error' | ||
| 410 | -- @see utils.raise | ||
| 411 | function utils.on_error (mode) | ||
| 412 | if ({['default'] = 1, ['quit'] = 2, ['error'] = 3})[mode] then | ||
| 413 | err_mode = mode | ||
| 414 | else | ||
| 415 | -- fail loudly | ||
| 416 | if err_mode == 'default' then err_mode = 'error' end | ||
| 417 | utils.raise("Bad argument expected string; 'default', 'quit', or 'error'. Got '"..tostring(mode).."'") | ||
| 418 | end | ||
| 419 | end | ||
| 420 | |||
| 421 | --- used by Penlight functions to return errors. Its global behaviour is controlled | ||
| 422 | -- by <code>utils.on_error</code> | ||
| 423 | -- @param err the error string. | ||
| 424 | -- @see utils.on_error | ||
| 425 | function utils.raise (err) | ||
| 426 | if err_mode == 'default' then return nil,err | ||
| 427 | elseif err_mode == 'quit' then utils.quit(err) | ||
| 428 | else error(err,2) | ||
| 429 | end | ||
| 430 | end | ||
| 431 | |||
| 432 | --- is the object of the specified type?. | ||
| 433 | -- If the type is a string, then use type, otherwise compare with metatable | ||
| 434 | -- @param obj An object to check | ||
| 435 | -- @param tp String of what type it should be | ||
| 436 | function utils.is_type (obj,tp) | ||
| 437 | if type(tp) == 'string' then return type(obj) == tp end | ||
| 438 | local mt = getmetatable(obj) | ||
| 439 | return tp == mt | ||
| 440 | end | ||
| 441 | |||
| 442 | raise = utils.raise | ||
| 443 | |||
| 444 | --- load a code string or bytecode chunk. | ||
| 445 | -- @param code Lua code as a string or bytecode | ||
| 446 | -- @param name for source errors | ||
| 447 | -- @param mode kind of chunk, 't' for text, 'b' for bytecode, 'bt' for all (default) | ||
| 448 | -- @param env the environment for the new chunk (default nil) | ||
| 449 | -- @return compiled chunk | ||
| 450 | -- @return error message (chunk is nil) | ||
| 451 | -- @function utils.load | ||
| 452 | |||
| 453 | --------------- | ||
| 454 | -- Get environment of a function. | ||
| 455 | -- With Lua 5.2, may return nil for a function with no global references! | ||
| 456 | -- Based on code by [Sergey Rozhenko](http://lua-users.org/lists/lua-l/2010-06/msg00313.html) | ||
| 457 | -- @param f a function or a call stack reference | ||
| 458 | -- @function utils.setfenv | ||
| 459 | |||
| 460 | --------------- | ||
| 461 | -- Set environment of a function | ||
| 462 | -- @param f a function or a call stack reference | ||
| 463 | -- @param env a table that becomes the new environment of `f` | ||
| 464 | -- @function utils.setfenv | ||
| 465 | |||
| 466 | --- execute a shell command. | ||
| 467 | -- This is a compatibility function that returns the same for Lua 5.1 and Lua 5.2 | ||
| 468 | -- @param cmd a shell command | ||
| 469 | -- @return true if successful | ||
| 470 | -- @return actual return code | ||
| 471 | -- @function utils.execute | ||
| 472 | |||
| 473 | return utils | ||
| 474 | |||
| 475 |
| 1 | --- XML LOM Utilities. | ||
| 2 | -- | ||
| 3 | -- This implements some useful things on [LOM](http://matthewwild.co.uk/projects/luaexpat/lom.html) documents, such as returned by `lxp.lom.parse`. | ||
| 4 | -- In particular, it can convert LOM back into XML text, with optional pretty-printing control. | ||
| 5 | -- It is s based on stanza.lua from [Prosody](http://hg.prosody.im/trunk/file/4621c92d2368/util/stanza.lua) | ||
| 6 | -- | ||
| 7 | -- > d = xml.parse "<nodes><node id='1'>alice</node></nodes>" | ||
| 8 | -- > = d | ||
| 9 | -- <nodes><node id='1'>alice</node></nodes> | ||
| 10 | -- > = xml.tostring(d,'',' ') | ||
| 11 | -- <nodes> | ||
| 12 | -- <node id='1'>alice</node> | ||
| 13 | -- </nodes> | ||
| 14 | -- | ||
| 15 | -- Can be used as a lightweight one-stop-shop for simple XML processing; a simple XML parser is included | ||
| 16 | -- but the default is to use `lxp.lom` if it can be found. | ||
| 17 | -- <pre> | ||
| 18 | -- Prosody IM | ||
| 19 | -- Copyright (C) 2008-2010 Matthew Wild | ||
| 20 | -- Copyright (C) 2008-2010 Waqas Hussain-- | ||
| 21 | -- classic Lua XML parser by Roberto Ierusalimschy. | ||
| 22 | -- modified to output LOM format. | ||
| 23 | -- http://lua-users.org/wiki/LuaXml | ||
| 24 | -- </pre> | ||
| 25 | -- See @{06-data.md.XML|the Guide} | ||
| 26 | -- | ||
| 27 | -- Dependencies: `pl.utils` | ||
| 28 | -- | ||
| 29 | -- Soft Dependencies: `lxp.lom` (fallback is to use basic Lua parser) | ||
| 30 | -- @module pl.xml | ||
| 31 | |||
| 32 | local utils = import '.utils' | ||
| 33 | local split = utils.split; | ||
| 34 | local t_insert = table.insert; | ||
| 35 | local t_concat = table.concat; | ||
| 36 | local t_remove = table.remove; | ||
| 37 | local s_format = string.format; | ||
| 38 | local s_match = string.match; | ||
| 39 | local tostring = tostring; | ||
| 40 | local setmetatable = setmetatable; | ||
| 41 | local getmetatable = getmetatable; | ||
| 42 | local pairs = pairs; | ||
| 43 | local ipairs = ipairs; | ||
| 44 | local type = type; | ||
| 45 | local next = next; | ||
| 46 | local print = print; | ||
| 47 | local unpack = utils.unpack; | ||
| 48 | local s_gsub = string.gsub; | ||
| 49 | local s_char = string.char; | ||
| 50 | local s_find = string.find; | ||
| 51 | local os = os; | ||
| 52 | local pcall,require,io = pcall,require,io | ||
| 53 | |||
| 54 | local _M = {} | ||
| 55 | local Doc = { __type = "doc" }; | ||
| 56 | Doc.__index = Doc; | ||
| 57 | |||
| 58 | --- create a new document node. | ||
| 59 | -- @param tag the tag name | ||
| 60 | -- @param attr optional attributes (table of name-value pairs) | ||
| 61 | function _M.new(tag, attr) | ||
| 62 | local doc = { tag = tag, attr = attr or {}, last_add = {}}; | ||
| 63 | return setmetatable(doc, Doc); | ||
| 64 | end | ||
| 65 | |||
| 66 | --- parse an XML document. By default, this uses lxp.lom.parse, but | ||
| 67 | -- falls back to basic_parse, or if use_basic is true | ||
| 68 | -- @param text_or_file file or string representation | ||
| 69 | -- @param is_file whether text_or_file is a file name or not | ||
| 70 | -- @param use_basic do a basic parse | ||
| 71 | -- @return a parsed LOM document with the document metatatables set | ||
| 72 | -- @return nil, error the error can either be a file error or a parse error | ||
| 73 | function _M.parse(text_or_file, is_file, use_basic) | ||
| 74 | local parser,status,lom | ||
| 75 | if use_basic then parser = _M.basic_parse | ||
| 76 | else | ||
| 77 | status,lom = pcall(require,'lxp.lom') | ||
| 78 | if not status then parser = _M.basic_parse else parser = lom.parse end | ||
| 79 | end | ||
| 80 | if is_file then | ||
| 81 | local f,err = io.open(text_or_file) | ||
| 82 | if not f then return nil,err end | ||
| 83 | text_or_file = f:read '*a' | ||
| 84 | f:close() | ||
| 85 | end | ||
| 86 | local doc,err = parser(text_or_file) | ||
| 87 | if not doc then return nil,err end | ||
| 88 | if lom then | ||
| 89 | _M.walk(doc,false,function(_,d) | ||
| 90 | setmetatable(d,Doc) | ||
| 91 | end) | ||
| 92 | end | ||
| 93 | return doc | ||
| 94 | end | ||
| 95 | |||
| 96 | ---- convenient function to add a document node, This updates the last inserted position. | ||
| 97 | -- @param tag a tag name | ||
| 98 | -- @param attrs optional set of attributes (name-string pairs) | ||
| 99 | function Doc:addtag(tag, attrs) | ||
| 100 | local s = _M.new(tag, attrs); | ||
| 101 | (self.last_add[#self.last_add] or self):add_direct_child(s); | ||
| 102 | t_insert(self.last_add, s); | ||
| 103 | return self; | ||
| 104 | end | ||
| 105 | |||
| 106 | --- convenient function to add a text node. This updates the last inserted position. | ||
| 107 | -- @param text a string | ||
| 108 | function Doc:text(text) | ||
| 109 | (self.last_add[#self.last_add] or self):add_direct_child(text); | ||
| 110 | return self; | ||
| 111 | end | ||
| 112 | |||
| 113 | ---- go up one level in a document | ||
| 114 | function Doc:up() | ||
| 115 | t_remove(self.last_add); | ||
| 116 | return self; | ||
| 117 | end | ||
| 118 | |||
| 119 | function Doc:reset() | ||
| 120 | local last_add = self.last_add; | ||
| 121 | for i = 1,#last_add do | ||
| 122 | last_add[i] = nil; | ||
| 123 | end | ||
| 124 | return self; | ||
| 125 | end | ||
| 126 | |||
| 127 | --- append a child to a document directly. | ||
| 128 | -- @param child a child node (either text or a document) | ||
| 129 | function Doc:add_direct_child(child) | ||
| 130 | t_insert(self, child); | ||
| 131 | end | ||
| 132 | |||
| 133 | --- append a child to a document at the last element added | ||
| 134 | -- @param child a child node (either text or a document) | ||
| 135 | function Doc:add_child(child) | ||
| 136 | (self.last_add[#self.last_add] or self):add_direct_child(child); | ||
| 137 | return self; | ||
| 138 | end | ||
| 139 | |||
| 140 | --accessing attributes: useful not to have to expose implementation (attr) | ||
| 141 | --but also can allow attr to be nil in any future optimizations | ||
| 142 | |||
| 143 | --- set attributes of a document node. | ||
| 144 | -- @param t a table containing attribute/value pairs | ||
| 145 | function Doc:set_attribs (t) | ||
| 146 | for k,v in pairs(t) do | ||
| 147 | self.attr[k] = v | ||
| 148 | end | ||
| 149 | end | ||
| 150 | |||
| 151 | --- set a single attribute of a document node. | ||
| 152 | -- @param a attribute | ||
| 153 | -- @param v its value | ||
| 154 | function Doc:set_attrib(a,v) | ||
| 155 | self.attr[a] = v | ||
| 156 | end | ||
| 157 | |||
| 158 | --- access the attributes of a document node. | ||
| 159 | function Doc:get_attribs() | ||
| 160 | return self.attr | ||
| 161 | end | ||
| 162 | |||
| 163 | local function is_text(s) return type(s) == 'string' end | ||
| 164 | |||
| 165 | --- function to create an element with a given tag name and a set of children. | ||
| 166 | -- @param tag a tag name | ||
| 167 | -- @param items either text or a table where the hash part is the attributes and the list part is the children. | ||
| 168 | function _M.elem(tag,items) | ||
| 169 | local s = _M.new(tag) | ||
| 170 | if is_text(items) then items = {items} end | ||
| 171 | if _M.is_tag(items) then | ||
| 172 | t_insert(s,items) | ||
| 173 | elseif type(items) == 'table' then | ||
| 174 | for k,v in pairs(items) do | ||
| 175 | if is_text(k) then | ||
| 176 | s.attr[k] = v | ||
| 177 | t_insert(s.attr,k) | ||
| 178 | else | ||
| 179 | s[k] = v | ||
| 180 | end | ||
| 181 | end | ||
| 182 | end | ||
| 183 | return s | ||
| 184 | end | ||
| 185 | |||
| 186 | --- given a list of names, return a number of element constructors. | ||
| 187 | -- @param list a list of names, or a comma-separated string. | ||
| 188 | -- @usage local parent,children = doc.tags 'parent,children' <br> | ||
| 189 | -- doc = parent {child 'one', child 'two'} | ||
| 190 | function _M.tags(list) | ||
| 191 | local ctors = {} | ||
| 192 | local elem = _M.elem | ||
| 193 | if is_text(list) then list = split(list,'%s*,%s*') end | ||
| 194 | for _,tag in ipairs(list) do | ||
| 195 | local ctor = function(items) return _M.elem(tag,items) end | ||
| 196 | t_insert(ctors,ctor) | ||
| 197 | end | ||
| 198 | return unpack(ctors) | ||
| 199 | end | ||
| 200 | |||
| 201 | local templ_cache = {} | ||
| 202 | |||
| 203 | local function template_cache (templ) | ||
| 204 | if is_text(templ) then | ||
| 205 | if templ_cache[templ] then | ||
| 206 | templ = templ_cache[templ] | ||
| 207 | else | ||
| 208 | local str,err = templ | ||
| 209 | templ,err = _M.parse(str,false,true) | ||
| 210 | if not templ then return nil,err end | ||
| 211 | templ_cache[str] = templ | ||
| 212 | end | ||
| 213 | elseif not _M.is_tag(templ) then | ||
| 214 | return nil, "template is not a document" | ||
| 215 | end | ||
| 216 | return templ | ||
| 217 | end | ||
| 218 | |||
| 219 | local function is_data(data) | ||
| 220 | return #data == 0 or type(data[1]) ~= 'table' | ||
| 221 | end | ||
| 222 | |||
| 223 | local function prepare_data(data) | ||
| 224 | -- a hack for ensuring that $1 maps to first element of data, etc. | ||
| 225 | -- Either this or could change the gsub call just below. | ||
| 226 | for i,v in ipairs(data) do | ||
| 227 | data[tostring(i)] = v | ||
| 228 | end | ||
| 229 | end | ||
| 230 | |||
| 231 | --- create a substituted copy of a document, | ||
| 232 | -- @param templ may be a document or a string representation which will be parsed and cached | ||
| 233 | -- @param data a table of name-value pairs or a list of such tables | ||
| 234 | -- @return an XML document | ||
| 235 | function Doc.subst(templ, data) | ||
| 236 | local err | ||
| 237 | if type(data) ~= 'table' or not next(data) then return nil, "data must be a non-empty table" end | ||
| 238 | if is_data(data) then | ||
| 239 | prepare_data(data) | ||
| 240 | end | ||
| 241 | templ,err = template_cache(templ) | ||
| 242 | if err then return nil, err end | ||
| 243 | local function _subst(item) | ||
| 244 | return _M.clone(templ,function(s) | ||
| 245 | return s:gsub('%$(%w+)',item) | ||
| 246 | end) | ||
| 247 | end | ||
| 248 | if is_data(data) then return _subst(data) end | ||
| 249 | local list = {} | ||
| 250 | for _,item in ipairs(data) do | ||
| 251 | prepare_data(item) | ||
| 252 | t_insert(list,_subst(item)) | ||
| 253 | end | ||
| 254 | if data.tag then | ||
| 255 | list = _M.elem(data.tag,list) | ||
| 256 | end | ||
| 257 | return list | ||
| 258 | end | ||
| 259 | |||
| 260 | |||
| 261 | --- get the first child with a given tag name. | ||
| 262 | -- @param tag the tag name | ||
| 263 | function Doc:child_with_name(tag) | ||
| 264 | for _, child in ipairs(self) do | ||
| 265 | if child.tag == tag then return child; end | ||
| 266 | end | ||
| 267 | end | ||
| 268 | |||
| 269 | local _children_with_name | ||
| 270 | function _children_with_name(self,tag,list,recurse) | ||
| 271 | for _, child in ipairs(self) do if type(child) == 'table' then | ||
| 272 | if child.tag == tag then t_insert(list,child) end | ||
| 273 | if recurse then _children_with_name(child,tag,list,recurse) end | ||
| 274 | end end | ||
| 275 | end | ||
| 276 | |||
| 277 | --- get all elements in a document that have a given tag. | ||
| 278 | -- @param tag a tag name | ||
| 279 | -- @param dont_recurse optionally only return the immediate children with this tag name | ||
| 280 | -- @return a list of elements | ||
| 281 | function Doc:get_elements_with_name(tag,dont_recurse) | ||
| 282 | local res = {} | ||
| 283 | _children_with_name(self,tag,res,not dont_recurse) | ||
| 284 | return res | ||
| 285 | end | ||
| 286 | |||
| 287 | -- iterate over all children of a document node, including text nodes. | ||
| 288 | function Doc:children() | ||
| 289 | local i = 0; | ||
| 290 | return function (a) | ||
| 291 | i = i + 1 | ||
| 292 | return a[i]; | ||
| 293 | end, self, i; | ||
| 294 | end | ||
| 295 | |||
| 296 | -- return the first child element of a node, if it exists. | ||
| 297 | function Doc:first_childtag() | ||
| 298 | if #self == 0 then return end | ||
| 299 | for _,t in ipairs(self) do | ||
| 300 | if type(t) == 'table' then return t end | ||
| 301 | end | ||
| 302 | end | ||
| 303 | |||
| 304 | function Doc:matching_tags(tag, xmlns) | ||
| 305 | xmlns = xmlns or self.attr.xmlns; | ||
| 306 | local tags = self; | ||
| 307 | local start_i, max_i, v = 1, #tags; | ||
| 308 | return function () | ||
| 309 | for i=start_i,max_i do | ||
| 310 | v = tags[i]; | ||
| 311 | if (not tag or v.tag == tag) | ||
| 312 | and (not xmlns or xmlns == v.attr.xmlns) then | ||
| 313 | start_i = i+1; | ||
| 314 | return v; | ||
| 315 | end | ||
| 316 | end | ||
| 317 | end, tags, start_i; | ||
| 318 | end | ||
| 319 | |||
| 320 | --- iterate over all child elements of a document node. | ||
| 321 | function Doc:childtags() | ||
| 322 | local i = 0; | ||
| 323 | return function (a) | ||
| 324 | local v | ||
| 325 | repeat | ||
| 326 | i = i + 1 | ||
| 327 | v = self[i] | ||
| 328 | if v and type(v) == 'table' then return v; end | ||
| 329 | until not v | ||
| 330 | end, self[1], i; | ||
| 331 | end | ||
| 332 | |||
| 333 | --- visit child element of a node and call a function, possibility modifying the document. | ||
| 334 | -- @param callback a function passed the node (text or element). If it returns nil, that node will be removed. | ||
| 335 | -- If it returns a value, that will replace the current node. | ||
| 336 | function Doc:maptags(callback) | ||
| 337 | local is_tag = _M.is_tag | ||
| 338 | local i = 1; | ||
| 339 | while i <= #self do | ||
| 340 | if is_tag(self[i]) then | ||
| 341 | local ret = callback(self[i]); | ||
| 342 | if ret == nil then | ||
| 343 | t_remove(self, i); | ||
| 344 | else | ||
| 345 | self[i] = ret; | ||
| 346 | i = i + 1; | ||
| 347 | end | ||
| 348 | end | ||
| 349 | end | ||
| 350 | return self; | ||
| 351 | end | ||
| 352 | |||
| 353 | local xml_escape | ||
| 354 | do | ||
| 355 | local escape_table = { ["'"] = "'", ["\""] = """, ["<"] = "<", [">"] = ">", ["&"] = "&" }; | ||
| 356 | function xml_escape(str) return (s_gsub(str, "['&<>\"]", escape_table)); end | ||
| 357 | _M.xml_escape = xml_escape; | ||
| 358 | end | ||
| 359 | |||
| 360 | -- pretty printing | ||
| 361 | -- if indent, then put each new tag on its own line | ||
| 362 | -- if attr_indent, put each new attribute on its own line | ||
| 363 | local function _dostring(t, buf, self, xml_escape, parentns, idn, indent, attr_indent) | ||
| 364 | local nsid = 0; | ||
| 365 | local tag = t.tag | ||
| 366 | local lf,alf = ""," " | ||
| 367 | if indent then lf = '\n'..idn end | ||
| 368 | if attr_indent then alf = '\n'..idn..attr_indent end | ||
| 369 | t_insert(buf, lf.."<"..tag); | ||
| 370 | local function write_attr(k,v) | ||
| 371 | if s_find(k, "\1", 1, true) then | ||
| 372 | local ns, attrk = s_match(k, "^([^\1]*)\1?(.*)$"); | ||
| 373 | nsid = nsid + 1; | ||
| 374 | t_insert(buf, " xmlns:ns"..nsid.."='"..xml_escape(ns).."' ".."ns"..nsid..":"..attrk.."='"..xml_escape(v).."'"); | ||
| 375 | elseif not(k == "xmlns" and v == parentns) then | ||
| 376 | t_insert(buf, alf..k.."='"..xml_escape(v).."'"); | ||
| 377 | end | ||
| 378 | end | ||
| 379 | -- it's useful for testing to have predictable attribute ordering, if available | ||
| 380 | if #t.attr > 0 then | ||
| 381 | for _,k in ipairs(t.attr) do | ||
| 382 | write_attr(k,t.attr[k]) | ||
| 383 | end | ||
| 384 | else | ||
| 385 | for k, v in pairs(t.attr) do | ||
| 386 | write_attr(k,v) | ||
| 387 | end | ||
| 388 | end | ||
| 389 | local len,has_children = #t; | ||
| 390 | if len == 0 then | ||
| 391 | local out = "/>" | ||
| 392 | if attr_indent then out = '\n'..idn..out end | ||
| 393 | t_insert(buf, out); | ||
| 394 | else | ||
| 395 | t_insert(buf, ">"); | ||
| 396 | for n=1,len do | ||
| 397 | local child = t[n]; | ||
| 398 | if child.tag then | ||
| 399 | self(child, buf, self, xml_escape, t.attr.xmlns,idn and idn..indent, indent, attr_indent ); | ||
| 400 | has_children = true | ||
| 401 | else -- text element | ||
| 402 | t_insert(buf, xml_escape(child)); | ||
| 403 | end | ||
| 404 | end | ||
| 405 | t_insert(buf, (has_children and lf or '').."</"..tag..">"); | ||
| 406 | end | ||
| 407 | end | ||
| 408 | |||
| 409 | ---- pretty-print an XML document | ||
| 410 | --- @param t an XML document | ||
| 411 | --- @param idn an initial indent (indents are all strings) | ||
| 412 | --- @param indent an indent for each level | ||
| 413 | --- @param attr_indent if given, indent each attribute pair and put on a separate line | ||
| 414 | --- @param xml force prefacing with <?xml...> | ||
| 415 | --- @return a string representation | ||
| 416 | function _M.tostring(t,idn,indent, attr_indent, xml) | ||
| 417 | local buf = {}; | ||
| 418 | if xml then buf[1] = "<?xml version='1.0'?>" end | ||
| 419 | _dostring(t, buf, _dostring, xml_escape, nil,idn,indent, attr_indent); | ||
| 420 | return t_concat(buf); | ||
| 421 | end | ||
| 422 | |||
| 423 | Doc.__tostring = _M.tostring | ||
| 424 | |||
| 425 | --- get the full text value of an element | ||
| 426 | function Doc:get_text() | ||
| 427 | local res = {} | ||
| 428 | for i,el in ipairs(self) do | ||
| 429 | if is_text(el) then t_insert(res,el) end | ||
| 430 | end | ||
| 431 | return t_concat(res); | ||
| 432 | end | ||
| 433 | |||
| 434 | --- make a copy of a document | ||
| 435 | -- @param doc the original document | ||
| 436 | -- @param strsubst an optional function for handling string copying which could do substitution, etc. | ||
| 437 | function _M.clone(doc, strsubst) | ||
| 438 | local lookup_table = {}; | ||
| 439 | local function _copy(object,kind,parent) | ||
| 440 | if type(object) ~= "table" then | ||
| 441 | if strsubst and is_text(object) then return strsubst(object,kind,parent) | ||
| 442 | else return object | ||
| 443 | end | ||
| 444 | elseif lookup_table[object] then | ||
| 445 | return lookup_table[object] | ||
| 446 | end | ||
| 447 | local new_table = {}; | ||
| 448 | lookup_table[object] = new_table | ||
| 449 | local tag = object.tag | ||
| 450 | new_table.tag = _copy(tag,'*TAG',parent) | ||
| 451 | if object.attr then | ||
| 452 | local res = {} | ||
| 453 | for attr,value in pairs(object.attr) do | ||
| 454 | res[attr] = _copy(value,attr,object) | ||
| 455 | end | ||
| 456 | new_table.attr = res | ||
| 457 | end | ||
| 458 | for index = 1,#object do | ||
| 459 | local v = _copy(object[index],'*TEXT',object) | ||
| 460 | t_insert(new_table,v) | ||
| 461 | end | ||
| 462 | return setmetatable(new_table, getmetatable(object)) | ||
| 463 | end | ||
| 464 | |||
| 465 | return _copy(doc) | ||
| 466 | end | ||
| 467 | |||
| 468 | Doc.filter = _M.clone -- also available as method | ||
| 469 | |||
| 470 | --- compare two documents. | ||
| 471 | -- @param t1 any value | ||
| 472 | -- @param t2 any value | ||
| 473 | function _M.compare(t1,t2) | ||
| 474 | local ty1 = type(t1) | ||
| 475 | local ty2 = type(t2) | ||
| 476 | if ty1 ~= ty2 then return false, 'type mismatch' end | ||
| 477 | if ty1 == 'string' then | ||
| 478 | return t1 == t2 and true or 'text '..t1..' ~= text '..t2 | ||
| 479 | end | ||
| 480 | if ty1 ~= 'table' or ty2 ~= 'table' then return false, 'not a document' end | ||
| 481 | if t1.tag ~= t2.tag then return false, 'tag '..t1.tag..' ~= tag '..t2.tag end | ||
| 482 | if #t1 ~= #t2 then return false, 'size '..#t1..' ~= size '..#t2..' for tag '..t1.tag end | ||
| 483 | -- compare attributes | ||
| 484 | for k,v in pairs(t1.attr) do | ||
| 485 | if t2.attr[k] ~= v then return false, 'mismatch attrib' end | ||
| 486 | end | ||
| 487 | for k,v in pairs(t2.attr) do | ||
| 488 | if t1.attr[k] ~= v then return false, 'mismatch attrib' end | ||
| 489 | end | ||
| 490 | -- compare children | ||
| 491 | for i = 1,#t1 do | ||
| 492 | local yes,err = _M.compare(t1[i],t2[i]) | ||
| 493 | if not yes then return err end | ||
| 494 | end | ||
| 495 | return true | ||
| 496 | end | ||
| 497 | |||
| 498 | --- is this value a document element? | ||
| 499 | -- @param d any value | ||
| 500 | function _M.is_tag(d) | ||
| 501 | return type(d) == 'table' and is_text(d.tag) | ||
| 502 | end | ||
| 503 | |||
| 504 | --- call the desired function recursively over the document. | ||
| 505 | -- @param doc the document | ||
| 506 | -- @param depth_first visit child notes first, then the current node | ||
| 507 | -- @param operation a function which will receive the current tag name and current node. | ||
| 508 | function _M.walk (doc, depth_first, operation) | ||
| 509 | if not depth_first then operation(doc.tag,doc) end | ||
| 510 | for _,d in ipairs(doc) do | ||
| 511 | if _M.is_tag(d) then | ||
| 512 | _M.walk(d,depth_first,operation) | ||
| 513 | end | ||
| 514 | end | ||
| 515 | if depth_first then operation(doc.tag,doc) end | ||
| 516 | end | ||
| 517 | |||
| 518 | local html_empty_elements = { --lists all HTML empty (void) elements | ||
| 519 | br = true, | ||
| 520 | img = true, | ||
| 521 | meta = true, | ||
| 522 | frame = true, | ||
| 523 | area = true, | ||
| 524 | hr = true, | ||
| 525 | base = true, | ||
| 526 | col = true, | ||
| 527 | link = true, | ||
| 528 | input = true, | ||
| 529 | option = true, | ||
| 530 | param = true, | ||
| 531 | isindex = true, | ||
| 532 | embed = true, | ||
| 533 | } | ||
| 534 | |||
| 535 | local escapes = { quot = "\"", apos = "'", lt = "<", gt = ">", amp = "&" } | ||
| 536 | local function unescape(str) return (str:gsub( "&(%a+);", escapes)); end | ||
| 537 | |||
| 538 | --- Parse a well-formed HTML file as a string. | ||
| 539 | -- Tags are case-insenstive, DOCTYPE is ignored, and empty elements can be .. empty. | ||
| 540 | -- @param s the HTML | ||
| 541 | function _M.parsehtml (s) | ||
| 542 | return _M.basic_parse(s,false,true) | ||
| 543 | end | ||
| 544 | |||
| 545 | --- Parse a simple XML document using a pure Lua parser based on Robero Ierusalimschy's original version. | ||
| 546 | -- @param s the XML document to be parsed. | ||
| 547 | -- @param all_text if true, preserves all whitespace. Otherwise only text containing non-whitespace is included. | ||
| 548 | -- @param html if true, uses relaxed HTML rules for parsing | ||
| 549 | function _M.basic_parse(s,all_text,html) | ||
| 550 | local t_insert,t_remove = table.insert,table.remove | ||
| 551 | local s_find,s_sub = string.find,string.sub | ||
| 552 | local stack = {} | ||
| 553 | local top = {} | ||
| 554 | |||
| 555 | local function parseargs(s) | ||
| 556 | local arg = {} | ||
| 557 | s:gsub("([%w:]+)%s*=%s*([\"'])(.-)%2", function (w, _, a) | ||
| 558 | if html then w = w:lower() end | ||
| 559 | arg[w] = unescape(a) | ||
| 560 | end) | ||
| 561 | if html then | ||
| 562 | s:gsub("([%w:]+)%s*=%s*([^\"']+)%s*", function (w, a) | ||
| 563 | w = w:lower() | ||
| 564 | arg[w] = unescape(a) | ||
| 565 | end) | ||
| 566 | end | ||
| 567 | return arg | ||
| 568 | end | ||
| 569 | |||
| 570 | t_insert(stack, top) | ||
| 571 | local ni,c,label,xarg, empty, _, istart | ||
| 572 | local i, j = 1, 1 | ||
| 573 | if not html then -- we're not interested in <?xml version="1.0"?> | ||
| 574 | _,istart = s_find(s,'^%s*<%?[^%?]+%?>%s*') | ||
| 575 | else -- or <!DOCTYPE ...> | ||
| 576 | _,istart = s_find(s,'^%s*<!DOCTYPE.->%s*') | ||
| 577 | end | ||
| 578 | if istart then i = istart+1 end | ||
| 579 | while true do | ||
| 580 | ni,j,c,label,xarg, empty = s_find(s, "<([%/!]?)([%w:%-_]+)(.-)(%/?)>", i) | ||
| 581 | if not ni then break end | ||
| 582 | if c == "!" then -- comment | ||
| 583 | -- case where there's no space inside comment | ||
| 584 | if not (label:match '%-%-$' and xarg == '') then | ||
| 585 | if xarg:match '%-%-$' then -- we've grabbed it all | ||
| 586 | j = j - 2 | ||
| 587 | end | ||
| 588 | -- match end of comment | ||
| 589 | _,j = s_find(s, "-->", j, true) | ||
| 590 | end | ||
| 591 | else | ||
| 592 | local text = s_sub(s, i, ni-1) | ||
| 593 | if html then | ||
| 594 | label = label:lower() | ||
| 595 | if html_empty_elements[label] then empty = "/" end | ||
| 596 | if label == 'script' then | ||
| 597 | end | ||
| 598 | end | ||
| 599 | if all_text or not s_find(text, "^%s*$") then | ||
| 600 | t_insert(top, unescape(text)) | ||
| 601 | end | ||
| 602 | if empty == "/" then -- empty element tag | ||
| 603 | t_insert(top, setmetatable({tag=label, attr=parseargs(xarg), empty=1},Doc)) | ||
| 604 | elseif c == "" then -- start tag | ||
| 605 | top = setmetatable({tag=label, attr=parseargs(xarg)},Doc) | ||
| 606 | t_insert(stack, top) -- new level | ||
| 607 | else -- end tag | ||
| 608 | local toclose = t_remove(stack) -- remove top | ||
| 609 | top = stack[#stack] | ||
| 610 | if #stack < 1 then | ||
| 611 | error("nothing to close with "..label..':'..text) | ||
| 612 | end | ||
| 613 | if toclose.tag ~= label then | ||
| 614 | error("trying to close "..toclose.tag.." with "..label.." "..text) | ||
| 615 | end | ||
| 616 | t_insert(top, toclose) | ||
| 617 | end | ||
| 618 | end | ||
| 619 | i = j+1 | ||
| 620 | end | ||
| 621 | local text = s_sub(s, i) | ||
| 622 | if all_text or not s_find(text, "^%s*$") then | ||
| 623 | t_insert(stack[#stack], unescape(text)) | ||
| 624 | end | ||
| 625 | if #stack > 1 then | ||
| 626 | error("unclosed "..stack[#stack].tag) | ||
| 627 | end | ||
| 628 | local res = stack[1] | ||
| 629 | return is_text(res[1]) and res[2] or res[1] | ||
| 630 | end | ||
| 631 | |||
| 632 | local function empty(attr) return not attr or not next(attr) end | ||
| 633 | local function is_element(d) return type(d) == 'table' and d.tag ~= nil end | ||
| 634 | |||
| 635 | -- returns the key,value pair from a table if it has exactly one entry | ||
| 636 | local function has_one_element(t) | ||
| 637 | local key,value = next(t) | ||
| 638 | if next(t,key) ~= nil then return false end | ||
| 639 | return key,value | ||
| 640 | end | ||
| 641 | |||
| 642 | local function append_capture(res,tbl) | ||
| 643 | if not empty(tbl) then -- no point in capturing empty tables... | ||
| 644 | local key | ||
| 645 | if tbl._ then -- if $_ was set then it is meant as the top-level key for the captured table | ||
| 646 | key = tbl._ | ||
| 647 | tbl._ = nil | ||
| 648 | if empty(tbl) then return end | ||
| 649 | end | ||
| 650 | -- a table with only one pair {[0]=value} shall be reduced to that value | ||
| 651 | local numkey,val = has_one_element(tbl) | ||
| 652 | if numkey == 0 then tbl = val end | ||
| 653 | if key then | ||
| 654 | res[key] = tbl | ||
| 655 | else -- otherwise, we append the captured table | ||
| 656 | t_insert(res,tbl) | ||
| 657 | end | ||
| 658 | end | ||
| 659 | end | ||
| 660 | |||
| 661 | local function make_number(pat) | ||
| 662 | if pat:find '^%d+$' then -- $1 etc means use this as an array location | ||
| 663 | pat = tonumber(pat) | ||
| 664 | end | ||
| 665 | return pat | ||
| 666 | end | ||
| 667 | |||
| 668 | local function capture_attrib(res,pat,value) | ||
| 669 | pat = make_number(pat:sub(2)) | ||
| 670 | res[pat] = value | ||
| 671 | return true | ||
| 672 | end | ||
| 673 | |||
| 674 | local match | ||
| 675 | function match(d,pat,res,keep_going) | ||
| 676 | local ret = true | ||
| 677 | if d == nil then d = '' end --return false end | ||
| 678 | -- attribute string matching is straight equality, except if the pattern is a $ capture, | ||
| 679 | -- which always succeeds. | ||
| 680 | if is_text(d) then | ||
| 681 | if not is_text(pat) then return false end | ||
| 682 | if _M.debug then print(d,pat) end | ||
| 683 | if pat:find '^%$' then | ||
| 684 | return capture_attrib(res,pat,d) | ||
| 685 | else | ||
| 686 | return d == pat | ||
| 687 | end | ||
| 688 | else | ||
| 689 | if _M.debug then print(d.tag,pat.tag) end | ||
| 690 | -- this is an element node. For a match to succeed, the attributes must | ||
| 691 | -- match as well. | ||
| 692 | -- a tagname in the pattern ending with '-' is a wildcard and matches like an attribute | ||
| 693 | local tagpat = pat.tag:match '^(.-)%-$' | ||
| 694 | if tagpat then | ||
| 695 | tagpat = make_number(tagpat) | ||
| 696 | res[tagpat] = d.tag | ||
| 697 | end | ||
| 698 | if d.tag == pat.tag or tagpat then | ||
| 699 | |||
| 700 | if not empty(pat.attr) then | ||
| 701 | if empty(d.attr) then ret = false | ||
| 702 | else | ||
| 703 | for prop,pval in pairs(pat.attr) do | ||
| 704 | local dval = d.attr[prop] | ||
| 705 | if not match(dval,pval,res) then ret = false; break end | ||
| 706 | end | ||
| 707 | end | ||
| 708 | end | ||
| 709 | -- the pattern may have child nodes. We match partially, so that {P1,P2} shall match {X,P1,X,X,P2,..} | ||
| 710 | if ret and #pat > 0 then | ||
| 711 | local i,j = 1,1 | ||
| 712 | local function next_elem() | ||
| 713 | j = j + 1 -- next child element of data | ||
| 714 | if is_text(d[j]) then j = j + 1 end | ||
| 715 | return j <= #d | ||
| 716 | end | ||
| 717 | repeat | ||
| 718 | local p = pat[i] | ||
| 719 | -- repeated {{<...>}} patterns shall match one or more elements | ||
| 720 | -- so e.g. {P+} will match {X,X,P,P,X,P,X,X,X} | ||
| 721 | if is_element(p) and p.repeated then | ||
| 722 | local found | ||
| 723 | repeat | ||
| 724 | local tbl = {} | ||
| 725 | ret = match(d[j],p,tbl,false) | ||
| 726 | if ret then | ||
| 727 | found = false --true | ||
| 728 | append_capture(res,tbl) | ||
| 729 | end | ||
| 730 | until not next_elem() or (found and not ret) | ||
| 731 | i = i + 1 | ||
| 732 | else | ||
| 733 | ret = match(d[j],p,res,false) | ||
| 734 | if ret then i = i + 1 end | ||
| 735 | end | ||
| 736 | until not next_elem() or i > #pat -- run out of elements or patterns to match | ||
| 737 | -- if every element in our pattern matched ok, then it's been a successful match | ||
| 738 | if i > #pat then return true end | ||
| 739 | end | ||
| 740 | if ret then return true end | ||
| 741 | else | ||
| 742 | ret = false | ||
| 743 | end | ||
| 744 | -- keep going anyway - look at the children! | ||
| 745 | if keep_going then | ||
| 746 | for child in d:childtags() do | ||
| 747 | ret = match(child,pat,res,keep_going) | ||
| 748 | if ret then break end | ||
| 749 | end | ||
| 750 | end | ||
| 751 | end | ||
| 752 | return ret | ||
| 753 | end | ||
| 754 | |||
| 755 | function Doc:match(pat) | ||
| 756 | local err | ||
| 757 | pat,err = template_cache(pat) | ||
| 758 | if not pat then return nil, err end | ||
| 759 | _M.walk(pat,false,function(_,d) | ||
| 760 | if is_text(d[1]) and is_element(d[2]) and is_text(d[3]) and | ||
| 761 | d[1]:find '%s*{{' and d[3]:find '}}%s*' then | ||
| 762 | t_remove(d,1) | ||
| 763 | t_remove(d,2) | ||
| 764 | d[1].repeated = true | ||
| 765 | end | ||
| 766 | end) | ||
| 767 | |||
| 768 | local res = {} | ||
| 769 | local ret = match(self,pat,res,true) | ||
| 770 | return res,ret | ||
| 771 | end | ||
| 772 | |||
| 773 | |||
| 774 | return _M | ||
| 775 |
| 1 | local scheduler = cc.Director:getInstance():getScheduler(); | ||
| 2 | |||
| 3 | function dprint( ... ) | ||
| 4 | if DEBUG then | ||
| 5 | print(...) | ||
| 6 | end | ||
| 7 | end | ||
| 8 | --打印带时间的日志 | ||
| 9 | function trace(...) | ||
| 10 | print(os.date("%Y-%m-%d %H:%M:%S")..":", ...) | ||
| 11 | end | ||
| 12 | |||
| 13 | function delayCall(delay,callback) | ||
| 14 | local id | ||
| 15 | |||
| 16 | local function oncall() | ||
| 17 | scheduler:unscheduleScriptEntry(id); | ||
| 18 | callback(); | ||
| 19 | end | ||
| 20 | |||
| 21 | id = scheduler:scheduleScriptFunc(oncall, delay,false); | ||
| 22 | return id; | ||
| 23 | end | ||
| 24 | |||
| 25 | function removeDelay(id) | ||
| 26 | scheduler:unscheduleScriptEntry(id); | ||
| 27 | end | ||
| 28 | |||
| 29 | function registerScriptTouchEvent(node,onTouchBegan,onTouchMoved,onTouchEnded) | ||
| 30 | -- local listener = cc.EventListenerTouchOneByOne:create() | ||
| 31 | -- listener:registerScriptHandler(touchBegan,cc.Handler.EVENT_TOUCH_BEGAN ) | ||
| 32 | -- listener:registerScriptHandler(touchMoved,cc.Handler.EVENT_TOUCH_MOVED ) | ||
| 33 | -- listener:registerScriptHandler(touchEnded,cc.Handler.EVENT_TOUCH_ENDED ) | ||
| 34 | -- --listener:setSwallowTouches(true) --不向下传递 | ||
| 35 | -- local eventDispatcher = node:getEventDispatcher() | ||
| 36 | -- eventDispatcher:addEventListenerWithSceneGraphPriority(listener,node) | ||
| 37 | local touchListener = cc.EventListenerTouchOneByOne:create() | ||
| 38 | touchListener:registerScriptHandler(onTouchBegan, cc.Handler.EVENT_TOUCH_BEGAN) | ||
| 39 | touchListener:registerScriptHandler(onTouchMoved, cc.Handler.EVENT_TOUCH_MOVED) | ||
| 40 | touchListener:registerScriptHandler(onTouchEnded, cc.Handler.EVENT_TOUCH_ENDED) | ||
| 41 | local eveDispatch = node:getEventDispatcher() | ||
| 42 | eveDispatch:addEventListenerWithSceneGraphPriority(touchListener, node) | ||
| 43 | end | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -3,14 +3,86 @@ cc.FileUtils:getInstance():setPopupNotify(false) | ... | @@ -3,14 +3,86 @@ cc.FileUtils:getInstance():setPopupNotify(false) |
| 3 | cc.FileUtils:getInstance():addSearchPath("src/") | 3 | cc.FileUtils:getInstance():addSearchPath("src/") |
| 4 | cc.FileUtils:getInstance():addSearchPath("res/") | 4 | cc.FileUtils:getInstance():addSearchPath("res/") |
| 5 | 5 | ||
| 6 | require "config" | 6 | local engine_loaded = {}; |
| 7 | require "cocos.init" | 7 | for i,v in pairs(package.loaded) do |
| 8 | engine_loaded[i] = v; | ||
| 9 | end | ||
| 10 | |||
| 11 | require "config"; | ||
| 12 | require "cocos.init"; | ||
| 13 | require "cocos.cocos2d.json"; | ||
| 14 | require "core.utils.util"; | ||
| 15 | |||
| 16 | __G__TRACKBACK__ = function(msg) | ||
| 17 | local traceback = debug.traceback(msg, 3); | ||
| 18 | print(traceback); | ||
| 19 | logUI(traceback); | ||
| 20 | return traceback; | ||
| 21 | end | ||
| 8 | 22 | ||
| 9 | local function main() | 23 | local function main() |
| 10 | require("app.MyApp"):create():run() | 24 | require "app.info.ConfigInfo"; |
| 25 | DEBUG = tonumber(ConfigInfo.getConfigInfo("debug")); | ||
| 26 | CHANNEL = ConfigInfo.getConfigInfo("channel"); | ||
| 27 | IS_TV = tonumber(ConfigInfo.getConfigInfo("is_tv")); | ||
| 28 | |||
| 29 | require "core.log.init"; | ||
| 30 | |||
| 31 | cc.Director:getInstance():setAnimationInterval(1/30); | ||
| 32 | |||
| 33 | require("app.MyApp"):create(); | ||
| 34 | app:enterMiniGameScene("rubbish.LoadingScene"); | ||
| 35 | end | ||
| 36 | |||
| 37 | function reloadGame() | ||
| 38 | for k,_ in pairs(package.loaded) do | ||
| 39 | local has_k = false; | ||
| 40 | for i,v in pairs(engine_loaded) do | ||
| 41 | if k == i then | ||
| 42 | has_k = true; | ||
| 43 | end | ||
| 44 | end | ||
| 45 | if not has_k then | ||
| 46 | print("remove:"..k); | ||
| 47 | package.loaded[k] = nil; | ||
| 48 | end | ||
| 49 | end | ||
| 50 | |||
| 51 | cc.Director:getInstance():purgeCachedData(); | ||
| 52 | cc.FileUtils:getInstance():purgeCachedEntries(); | ||
| 53 | |||
| 54 | require("main"); | ||
| 55 | end | ||
| 56 | |||
| 57 | function loadGame(game_name) | ||
| 58 | local searchPaths = cc.FileUtils:getInstance():getSearchPaths(); | ||
| 59 | local resPath = cc.FileUtils:getInstance():getWritablePath().."GameUpdate/"..game_name.."/"; | ||
| 60 | searchPaths = {}; | ||
| 61 | table.insert(searchPaths,1,resPath); | ||
| 62 | table.insert(searchPaths,2,resPath .. 'res/'); | ||
| 63 | table.insert(searchPaths,3,resPath .. 'src/'); | ||
| 64 | cc.FileUtils:getInstance():setSearchPaths(searchPaths); | ||
| 65 | |||
| 66 | for k,_ in pairs(package.loaded) do | ||
| 67 | local has_k = false; | ||
| 68 | for i,v in pairs(engine_loaded) do | ||
| 69 | if k == i then | ||
| 70 | has_k = true; | ||
| 71 | end | ||
| 72 | end | ||
| 73 | if not has_k then | ||
| 74 | print("remove:"..k); | ||
| 75 | package.loaded[k] = nil; | ||
| 76 | end | ||
| 77 | end | ||
| 78 | |||
| 79 | cc.FileUtils:getInstance():purgeCachedEntries(); | ||
| 80 | cc.Director:getInstance():purgeCachedData(); | ||
| 81 | |||
| 82 | app:enterScene("LoadingScene",{nextSceneName="main"}); | ||
| 11 | end | 83 | end |
| 12 | 84 | ||
| 13 | local status, msg = xpcall(main, __G__TRACKBACK__) | 85 | local status, msg = xpcall(main, __G__TRACKBACK__) |
| 14 | if not status then | 86 | if not status then |
| 15 | print(msg) | 87 | print(msg) |
| 16 | end | 88 | end |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -3,7 +3,7 @@ local AppBase = class("AppBase") | ... | @@ -3,7 +3,7 @@ local AppBase = class("AppBase") |
| 3 | 3 | ||
| 4 | function AppBase:ctor(configs) | 4 | function AppBase:ctor(configs) |
| 5 | self.configs_ = { | 5 | self.configs_ = { |
| 6 | viewsRoot = "app.views", | 6 | viewsRoot = "app.views.scene", |
| 7 | modelsRoot = "app.models", | 7 | modelsRoot = "app.models", |
| 8 | defaultSceneName = "MainScene", | 8 | defaultSceneName = "MainScene", |
| 9 | } | 9 | } |
| ... | @@ -27,6 +27,7 @@ function AppBase:ctor(configs) | ... | @@ -27,6 +27,7 @@ function AppBase:ctor(configs) |
| 27 | cc.Director:getInstance():setDisplayStats(true) | 27 | cc.Director:getInstance():setDisplayStats(true) |
| 28 | end | 28 | end |
| 29 | 29 | ||
| 30 | app = self; | ||
| 30 | -- event | 31 | -- event |
| 31 | self:onCreate() | 32 | self:onCreate() |
| 32 | end | 33 | end |
| ... | @@ -57,8 +58,8 @@ function AppBase:createView(name) | ... | @@ -57,8 +58,8 @@ function AppBase:createView(name) |
| 57 | return view:create(self, name) | 58 | return view:create(self, name) |
| 58 | end | 59 | end |
| 59 | end | 60 | end |
| 60 | error(string.format("AppBase:createView() - not found view \"%s\" in search paths \"%s\"", | 61 | -- error(string.format("AppBase:createView() - not found view \"%s\" in search paths \"%s\"", |
| 61 | name, table.concat(self.configs_.viewsRoot, ",")), 0) | 62 | -- name, table.concat(self.configs_.viewsRoot, ",")), 0) |
| 62 | end | 63 | end |
| 63 | 64 | ||
| 64 | function AppBase:onCreate() | 65 | function AppBase:onCreate() | ... | ... |
| ... | @@ -33,10 +33,10 @@ | ... | @@ -33,10 +33,10 @@ |
| 33 | <FileData Type="Normal" Path="common_minigame/bg_game_pop2.png" Plist="" /> | 33 | <FileData Type="Normal" Path="common_minigame/bg_game_pop2.png" Plist="" /> |
| 34 | <BlendFunc Src="1" Dst="771" /> | 34 | <BlendFunc Src="1" Dst="771" /> |
| 35 | </AbstractNodeData> | 35 | </AbstractNodeData> |
| 36 | <AbstractNodeData Name="txt" ActionTag="1313909803" Tag="45" IconVisible="False" PositionPercentXEnabled="True" LeftMargin="68.5001" RightMargin="68.4999" TopMargin="87.7326" BottomMargin="154.2674" IsCustomSize="True" FontSize="48" LabelText="确定要退出游戏?" HorizontalAlignmentType="HT_Center" VerticalAlignmentType="VT_Center" ShadowOffsetX="2.0000" ShadowOffsetY="-2.0000" ctype="TextObjectData"> | 36 | <AbstractNodeData Name="txt" ActionTag="1313909803" Tag="45" IconVisible="False" PositionPercentXEnabled="True" LeftMargin="68.5000" RightMargin="68.5000" TopMargin="87.7326" BottomMargin="154.2674" IsCustomSize="True" FontSize="48" LabelText="确定要退出游戏?" HorizontalAlignmentType="HT_Center" VerticalAlignmentType="VT_Center" ShadowOffsetX="2.0000" ShadowOffsetY="-2.0000" ctype="TextObjectData"> |
| 37 | <Size X="550.0000" Y="200.0000" /> | 37 | <Size X="550.0000" Y="200.0000" /> |
| 38 | <AnchorPoint ScaleX="0.5000" ScaleY="0.5000" /> | 38 | <AnchorPoint ScaleX="0.5000" ScaleY="0.5000" /> |
| 39 | <Position X="343.5001" Y="254.2674" /> | 39 | <Position X="343.5000" Y="254.2674" /> |
| 40 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> | 40 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> |
| 41 | <CColor A="255" R="255" G="255" B="255" /> | 41 | <CColor A="255" R="255" G="255" B="255" /> |
| 42 | <PrePosition X="0.5000" Y="0.5753" /> | 42 | <PrePosition X="0.5000" Y="0.5753" /> | ... | ... |
| ... | @@ -149,7 +149,7 @@ | ... | @@ -149,7 +149,7 @@ |
| 149 | <OutlineColor A="255" R="255" G="0" B="0" /> | 149 | <OutlineColor A="255" R="255" G="0" B="0" /> |
| 150 | <ShadowColor A="255" R="110" G="110" B="110" /> | 150 | <ShadowColor A="255" R="110" G="110" B="110" /> |
| 151 | </AbstractNodeData> | 151 | </AbstractNodeData> |
| 152 | <AbstractNodeData Name="Text_5_0" ActionTag="-1128051286" Tag="54" IconVisible="False" LeftMargin="243.0362" RightMargin="519.9639" TopMargin="224.8490" BottomMargin="299.1510" IsCustomSize="True" FontSize="20" LabelText="元" VerticalAlignmentType="VT_Center" ShadowOffsetX="2.0000" ShadowOffsetY="-2.0000" ctype="TextObjectData"> | 152 | <AbstractNodeData Name="Text_5_0" ActionTag="-1128051286" Tag="54" IconVisible="False" LeftMargin="243.0362" RightMargin="519.9638" TopMargin="224.8490" BottomMargin="299.1510" IsCustomSize="True" FontSize="20" LabelText="元" VerticalAlignmentType="VT_Center" ShadowOffsetX="2.0000" ShadowOffsetY="-2.0000" ctype="TextObjectData"> |
| 153 | <Size X="50.0000" Y="30.0000" /> | 153 | <Size X="50.0000" Y="30.0000" /> |
| 154 | <AnchorPoint ScaleY="0.5000" /> | 154 | <AnchorPoint ScaleY="0.5000" /> |
| 155 | <Position X="243.0362" Y="314.1510" /> | 155 | <Position X="243.0362" Y="314.1510" /> | ... | ... |
| ... | @@ -9,28 +9,28 @@ | ... | @@ -9,28 +9,28 @@ |
| 9 | <AbstractNodeData Name="panel" ActionTag="1975180710" Tag="29" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" TouchEnable="True" ClipAble="False" BackColorAlpha="102" ColorAngle="90.0000" Scale9Width="1" Scale9Height="1" ctype="PanelObjectData"> | 9 | <AbstractNodeData Name="panel" ActionTag="1975180710" Tag="29" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" TouchEnable="True" ClipAble="False" BackColorAlpha="102" ColorAngle="90.0000" Scale9Width="1" Scale9Height="1" ctype="PanelObjectData"> |
| 10 | <Size X="1280.0000" Y="720.0000" /> | 10 | <Size X="1280.0000" Y="720.0000" /> |
| 11 | <Children> | 11 | <Children> |
| 12 | <AbstractNodeData Name="bg" ActionTag="1058415707" Tag="419" IconVisible="False" ctype="SpriteObjectData"> | 12 | <AbstractNodeData Name="bg" ActionTag="1058415707" Tag="419" IconVisible="False" RightMargin="1234.0000" TopMargin="674.0000" ctype="SpriteObjectData"> |
| 13 | <Size X="1280.0000" Y="720.0000" /> | 13 | <Size X="1280.0000" Y="720.0000" /> |
| 14 | <AnchorPoint /> | 14 | <AnchorPoint /> |
| 15 | <Position /> | 15 | <Position /> |
| 16 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> | 16 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> |
| 17 | <CColor A="255" R="255" G="255" B="255" /> | 17 | <CColor A="255" R="255" G="255" B="255" /> |
| 18 | <PrePosition /> | 18 | <PrePosition /> |
| 19 | <PreSize X="1.0000" Y="1.0000" /> | 19 | <PreSize X="0.0359" Y="0.0639" /> |
| 20 | <FileData Type="Normal" Path="ui/candy/bg.png" Plist="" /> | 20 | <FileData Type="Normal" Path="ui/rubbish/bg.png" Plist="" /> |
| 21 | <BlendFunc Src="770" Dst="771" /> | 21 | <BlendFunc Src="770" Dst="1" /> |
| 22 | </AbstractNodeData> | 22 | </AbstractNodeData> |
| 23 | <AbstractNodeData Name="best" ActionTag="237805041" Tag="124" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" LeftMargin="29.9440" RightMargin="1048.0560" TopMargin="21.0720" BottomMargin="614.9280" ctype="SpriteObjectData"> | 23 | <AbstractNodeData Name="best" ActionTag="237805041" Tag="124" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" LeftMargin="107.9440" RightMargin="1126.0560" TopMargin="40.0720" BottomMargin="633.9280" ctype="SpriteObjectData"> |
| 24 | <Size X="202.0000" Y="84.0000" /> | 24 | <Size X="202.0000" Y="84.0000" /> |
| 25 | <Children> | 25 | <Children> |
| 26 | <AbstractNodeData Name="txt" ActionTag="-1518137232" Tag="125" IconVisible="False" LeftMargin="102.9288" RightMargin="41.0712" TopMargin="21.7484" BottomMargin="22.2516" FontSize="30" LabelText="999" ShadowOffsetX="2.0000" ShadowOffsetY="-2.0000" ctype="TextObjectData"> | 26 | <AbstractNodeData Name="txt" ActionTag="-1518137232" Tag="125" IconVisible="False" LeftMargin="102.9288" RightMargin="-114.9288" TopMargin="-16.2516" BottomMargin="22.2516" FontSize="30" LabelText="999" ShadowOffsetX="2.0000" ShadowOffsetY="-2.0000" ctype="TextObjectData"> |
| 27 | <Size X="58.0000" Y="40.0000" /> | 27 | <Size X="58.0000" Y="40.0000" /> |
| 28 | <AnchorPoint ScaleX="0.5000" ScaleY="0.5000" /> | 28 | <AnchorPoint ScaleX="0.5000" ScaleY="0.5000" /> |
| 29 | <Position X="131.9288" Y="42.2516" /> | 29 | <Position X="131.9288" Y="42.2516" /> |
| 30 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> | 30 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> |
| 31 | <CColor A="255" R="189" G="118" B="53" /> | 31 | <CColor A="255" R="189" G="118" B="53" /> |
| 32 | <PrePosition X="0.6531" Y="0.5030" /> | 32 | <PrePosition X="2.8680" Y="0.9185" /> |
| 33 | <PreSize X="0.2871" Y="0.4762" /> | 33 | <PreSize X="1.2609" Y="0.8696" /> |
| 34 | <FontResource Type="Normal" Path="ui/font/yahei.ttf" Plist="" /> | 34 | <FontResource Type="Normal" Path="ui/font/yahei.ttf" Plist="" /> |
| 35 | <OutlineColor A="255" R="255" G="0" B="0" /> | 35 | <OutlineColor A="255" R="255" G="0" B="0" /> |
| 36 | <ShadowColor A="255" R="110" G="110" B="110" /> | 36 | <ShadowColor A="255" R="110" G="110" B="110" /> |
| ... | @@ -41,21 +41,21 @@ | ... | @@ -41,21 +41,21 @@ |
| 41 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> | 41 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> |
| 42 | <CColor A="255" R="255" G="255" B="255" /> | 42 | <CColor A="255" R="255" G="255" B="255" /> |
| 43 | <PrePosition X="0.1023" Y="0.9124" /> | 43 | <PrePosition X="0.1023" Y="0.9124" /> |
| 44 | <PreSize X="0.1578" Y="0.1167" /> | 44 | <PreSize X="0.0359" Y="0.0639" /> |
| 45 | <FileData Type="PlistSubImage" Path="bg_best_show.png" Plist="ui/candy/candy_textures.plist" /> | 45 | <FileData Type="PlistSubImage" Path="bg_best_show.png" Plist="ui/rubbish/candy_textures.plist" /> |
| 46 | <BlendFunc Src="1" Dst="771" /> | 46 | <BlendFunc Src="1" Dst="771" /> |
| 47 | </AbstractNodeData> | 47 | </AbstractNodeData> |
| 48 | <AbstractNodeData Name="guess_num" ActionTag="1276328542" Tag="46" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" LeftMargin="252.2560" RightMargin="827.7440" TopMargin="32.2800" BottomMargin="627.7200" ctype="SpriteObjectData"> | 48 | <AbstractNodeData Name="guess_num" ActionTag="1276328542" Tag="46" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" LeftMargin="329.2560" RightMargin="904.7440" TopMargin="39.2800" BottomMargin="634.7200" ctype="SpriteObjectData"> |
| 49 | <Size X="200.0000" Y="60.0000" /> | 49 | <Size X="200.0000" Y="60.0000" /> |
| 50 | <Children> | 50 | <Children> |
| 51 | <AbstractNodeData Name="txt" ActionTag="1819871962" Tag="47" IconVisible="False" LeftMargin="96.9529" RightMargin="45.0471" TopMargin="8.7486" BottomMargin="11.2514" FontSize="30" LabelText="999" ShadowOffsetX="2.0000" ShadowOffsetY="-2.0000" ctype="TextObjectData"> | 51 | <AbstractNodeData Name="txt" ActionTag="1819871962" Tag="47" IconVisible="False" LeftMargin="96.9529" RightMargin="-108.9529" TopMargin="-5.2514" BottomMargin="11.2514" FontSize="30" LabelText="999" ShadowOffsetX="2.0000" ShadowOffsetY="-2.0000" ctype="TextObjectData"> |
| 52 | <Size X="58.0000" Y="40.0000" /> | 52 | <Size X="58.0000" Y="40.0000" /> |
| 53 | <AnchorPoint ScaleX="0.5000" ScaleY="0.5000" /> | 53 | <AnchorPoint ScaleX="0.5000" ScaleY="0.5000" /> |
| 54 | <Position X="125.9529" Y="31.2514" /> | 54 | <Position X="125.9529" Y="31.2514" /> |
| 55 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> | 55 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> |
| 56 | <CColor A="255" R="189" G="118" B="53" /> | 56 | <CColor A="255" R="189" G="118" B="53" /> |
| 57 | <PrePosition X="0.6298" Y="0.5209" /> | 57 | <PrePosition X="2.7381" Y="0.6794" /> |
| 58 | <PreSize X="0.2900" Y="0.6667" /> | 58 | <PreSize X="1.2609" Y="0.8696" /> |
| 59 | <FontResource Type="Normal" Path="ui/font/yahei.ttf" Plist="" /> | 59 | <FontResource Type="Normal" Path="ui/font/yahei.ttf" Plist="" /> |
| 60 | <OutlineColor A="255" R="255" G="0" B="0" /> | 60 | <OutlineColor A="255" R="255" G="0" B="0" /> |
| 61 | <ShadowColor A="255" R="110" G="110" B="110" /> | 61 | <ShadowColor A="255" R="110" G="110" B="110" /> |
| ... | @@ -66,19 +66,19 @@ | ... | @@ -66,19 +66,19 @@ |
| 66 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> | 66 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> |
| 67 | <CColor A="255" R="255" G="255" B="255" /> | 67 | <CColor A="255" R="255" G="255" B="255" /> |
| 68 | <PrePosition X="0.2752" Y="0.9135" /> | 68 | <PrePosition X="0.2752" Y="0.9135" /> |
| 69 | <PreSize X="0.1563" Y="0.0833" /> | 69 | <PreSize X="0.0359" Y="0.0639" /> |
| 70 | <FileData Type="PlistSubImage" Path="bg_fanpai_num.png" Plist="ui/candy/candy_textures.plist" /> | 70 | <FileData Type="PlistSubImage" Path="bg_fanpai_num.png" Plist="ui/rubbish/candy_textures.plist" /> |
| 71 | <BlendFunc Src="1" Dst="771" /> | 71 | <BlendFunc Src="1" Dst="771" /> |
| 72 | </AbstractNodeData> | 72 | </AbstractNodeData> |
| 73 | <AbstractNodeData Name="tips_show" ActionTag="913325083" Tag="421" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" LeftMargin="157.0560" RightMargin="866.9440" TopMargin="110.9120" BottomMargin="403.0880" ctype="SpriteObjectData"> | 73 | <AbstractNodeData Name="tips_show" ActionTag="913325083" Tag="421" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" LeftMargin="262.0560" RightMargin="971.9440" TopMargin="190.9120" BottomMargin="483.0880" ctype="SpriteObjectData"> |
| 74 | <Size X="256.0000" Y="206.0000" /> | 74 | <Size X="256.0000" Y="206.0000" /> |
| 75 | <AnchorPoint ScaleX="0.5000" ScaleY="0.5000" /> | 75 | <AnchorPoint ScaleX="0.5000" ScaleY="0.5000" /> |
| 76 | <Position X="285.0560" Y="506.0880" /> | 76 | <Position X="285.0560" Y="506.0880" /> |
| 77 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> | 77 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> |
| 78 | <CColor A="255" R="255" G="255" B="255" /> | 78 | <CColor A="255" R="255" G="255" B="255" /> |
| 79 | <PrePosition X="0.2227" Y="0.7029" /> | 79 | <PrePosition X="0.2227" Y="0.7029" /> |
| 80 | <PreSize X="0.2000" Y="0.2861" /> | 80 | <PreSize X="0.0359" Y="0.0639" /> |
| 81 | <FileData Type="Normal" Path="ui/candy/game_tips_show.png" Plist="" /> | 81 | <FileData Type="Normal" Path="ui/rubbish/game_tips_show.png" Plist="" /> |
| 82 | <BlendFunc Src="1" Dst="771" /> | 82 | <BlendFunc Src="1" Dst="771" /> |
| 83 | </AbstractNodeData> | 83 | </AbstractNodeData> |
| 84 | </Children> | 84 | </Children> | ... | ... |
| ... | @@ -15,7 +15,7 @@ | ... | @@ -15,7 +15,7 @@ |
| 15 | <PrePosition X="0.5000" Y="0.5000" /> | 15 | <PrePosition X="0.5000" Y="0.5000" /> |
| 16 | <PreSize X="1.0000" Y="1.0000" /> | 16 | <PreSize X="1.0000" Y="1.0000" /> |
| 17 | <FileData Type="Normal" Path="ui/rubbish/bg.png" Plist="" /> | 17 | <FileData Type="Normal" Path="ui/rubbish/bg.png" Plist="" /> |
| 18 | <BlendFunc Src="770" Dst="771" /> | 18 | <BlendFunc Src="1" Dst="771" /> |
| 19 | </AbstractNodeData> | 19 | </AbstractNodeData> |
| 20 | <AbstractNodeData Name="ArmatureNode_1" ActionTag="-1366562285" Tag="615" IconVisible="True" LeftMargin="637.1683" RightMargin="642.8317" TopMargin="442.4383" BottomMargin="277.5617" IsLoop="True" IsAutoPlay="True" CurrentAnimationName="walk" ctype="ArmatureNodeObjectData"> | 20 | <AbstractNodeData Name="ArmatureNode_1" ActionTag="-1366562285" Tag="615" IconVisible="True" LeftMargin="637.1683" RightMargin="642.8317" TopMargin="442.4383" BottomMargin="277.5617" IsLoop="True" IsAutoPlay="True" CurrentAnimationName="walk" ctype="ArmatureNodeObjectData"> |
| 21 | <Size X="0.0000" Y="0.0000" /> | 21 | <Size X="0.0000" Y="0.0000" /> |
| ... | @@ -40,7 +40,7 @@ | ... | @@ -40,7 +40,7 @@ |
| 40 | <EndColor A="255" R="255" G="255" B="255" /> | 40 | <EndColor A="255" R="255" G="255" B="255" /> |
| 41 | <ColorVector ScaleY="1.0000" /> | 41 | <ColorVector ScaleY="1.0000" /> |
| 42 | </AbstractNodeData> | 42 | </AbstractNodeData> |
| 43 | <AbstractNodeData Name="btn_introduce" ActionTag="-506607103" Tag="87" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" LeftMargin="1130.8920" RightMargin="52.1080" TopMargin="41.3440" BottomMargin="584.6560" TouchEnable="True" FontSize="14" Scale9Enable="True" LeftEage="15" RightEage="15" TopEage="11" BottomEage="11" Scale9OriginX="15" Scale9OriginY="11" Scale9Width="67" Scale9Height="72" ShadowOffsetX="2.0000" ShadowOffsetY="-2.0000" ctype="ButtonObjectData"> | 43 | <AbstractNodeData Name="btn_introduce" ActionTag="-506607103" Tag="87" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" LeftMargin="1130.8920" RightMargin="52.1080" TopMargin="41.3440" BottomMargin="584.6560" TouchEnable="True" FontSize="14" Scale9Enable="True" LeftEage="15" RightEage="15" TopEage="11" BottomEage="11" Scale9OriginX="15" Scale9OriginY="11" Scale9Width="16" Scale9Height="14" ShadowOffsetX="2.0000" ShadowOffsetY="-2.0000" ctype="ButtonObjectData"> |
| 44 | <Size X="97.0000" Y="94.0000" /> | 44 | <Size X="97.0000" Y="94.0000" /> |
| 45 | <AnchorPoint ScaleX="0.5000" ScaleY="0.5000" /> | 45 | <AnchorPoint ScaleX="0.5000" ScaleY="0.5000" /> |
| 46 | <Position X="1179.3920" Y="631.6560" /> | 46 | <Position X="1179.3920" Y="631.6560" /> |
| ... | @@ -50,8 +50,8 @@ | ... | @@ -50,8 +50,8 @@ |
| 50 | <PreSize X="0.0758" Y="0.1306" /> | 50 | <PreSize X="0.0758" Y="0.1306" /> |
| 51 | <TextColor A="255" R="65" G="65" B="70" /> | 51 | <TextColor A="255" R="65" G="65" B="70" /> |
| 52 | <DisabledFileData Type="Default" Path="Default/Button_Disable.png" Plist="" /> | 52 | <DisabledFileData Type="Default" Path="Default/Button_Disable.png" Plist="" /> |
| 53 | <PressedFileData Type="PlistSubImage" Path="btn_guess_introduce.png" Plist="ui/rubbish/candy_textures.plist" /> | 53 | <PressedFileData Type="Default" Path="Default/Button_Press.png" Plist="" /> |
| 54 | <NormalFileData Type="PlistSubImage" Path="btn_guess_introduce.png" Plist="ui/rubbish/candy_textures.plist" /> | 54 | <NormalFileData Type="Default" Path="Default/Button_Normal.png" Plist="" /> |
| 55 | <OutlineColor A="255" R="255" G="0" B="0" /> | 55 | <OutlineColor A="255" R="255" G="0" B="0" /> |
| 56 | <ShadowColor A="255" R="110" G="110" B="110" /> | 56 | <ShadowColor A="255" R="110" G="110" B="110" /> |
| 57 | </AbstractNodeData> | 57 | </AbstractNodeData> | ... | ... |
| ... | @@ -6,15 +6,15 @@ | ... | @@ -6,15 +6,15 @@ |
| 6 | <ObjectData Name="Layer" Tag="30" ctype="GameLayerObjectData"> | 6 | <ObjectData Name="Layer" Tag="30" ctype="GameLayerObjectData"> |
| 7 | <Size X="241.0000" Y="320.0000" /> | 7 | <Size X="241.0000" Y="320.0000" /> |
| 8 | <Children> | 8 | <Children> |
| 9 | <AbstractNodeData Name="girl_1" ActionTag="1045743099" Tag="31" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" LeftMargin="-120.5000" RightMargin="120.5000" ctype="SpriteObjectData"> | 9 | <AbstractNodeData Name="girl_1" ActionTag="1045743099" Tag="31" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" LeftMargin="-23.0000" RightMargin="218.0000" TopMargin="274.0000" ctype="SpriteObjectData"> |
| 10 | <Size X="241.0000" Y="320.0000" /> | 10 | <Size X="46.0000" Y="46.0000" /> |
| 11 | <AnchorPoint ScaleX="0.5000" /> | 11 | <AnchorPoint ScaleX="0.5000" /> |
| 12 | <Position /> | 12 | <Position /> |
| 13 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> | 13 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> |
| 14 | <CColor A="255" R="255" G="255" B="255" /> | 14 | <CColor A="255" R="255" G="255" B="255" /> |
| 15 | <PrePosition /> | 15 | <PrePosition /> |
| 16 | <PreSize X="1.0000" Y="1.0000" /> | 16 | <PreSize X="0.1909" Y="0.1437" /> |
| 17 | <FileData Type="Normal" Path="ui/candy/girl.png" Plist="" /> | 17 | <FileData Type="Default" Path="Default/Sprite.png" Plist="" /> |
| 18 | <BlendFunc Src="1" Dst="771" /> | 18 | <BlendFunc Src="1" Dst="771" /> |
| 19 | </AbstractNodeData> | 19 | </AbstractNodeData> |
| 20 | <AbstractNodeData Name="pokect" ActionTag="-159700197" Tag="41" IconVisible="False" LeftMargin="-91.8160" RightMargin="132.8160" TopMargin="240.3760" BottomMargin="69.6240" TouchEnable="True" ClipAble="False" BackColorAlpha="102" ColorAngle="90.0000" Scale9Width="1" Scale9Height="1" ctype="PanelObjectData"> | 20 | <AbstractNodeData Name="pokect" ActionTag="-159700197" Tag="41" IconVisible="False" LeftMargin="-91.8160" RightMargin="132.8160" TopMargin="240.3760" BottomMargin="69.6240" TouchEnable="True" ClipAble="False" BackColorAlpha="102" ColorAngle="90.0000" Scale9Width="1" Scale9Height="1" ctype="PanelObjectData"> |
| ... | @@ -30,7 +30,7 @@ | ... | @@ -30,7 +30,7 @@ |
| 30 | <EndColor A="255" R="255" G="255" B="255" /> | 30 | <EndColor A="255" R="255" G="255" B="255" /> |
| 31 | <ColorVector ScaleY="1.0000" /> | 31 | <ColorVector ScaleY="1.0000" /> |
| 32 | </AbstractNodeData> | 32 | </AbstractNodeData> |
| 33 | <AbstractNodeData Name="magnet" ActionTag="1242017924" Tag="12" IconVisible="True" LeftMargin="-2.1780" RightMargin="243.1780" TopMargin="232.2840" BottomMargin="87.7160" IsLoop="True" IsAutoPlay="True" CurrentAnimationName="Action0" ctype="ArmatureNodeObjectData"> | 33 | <AbstractNodeData Name="magnet" ActionTag="1242017924" Tag="12" IconVisible="True" LeftMargin="-2.1780" RightMargin="243.1780" TopMargin="232.2840" BottomMargin="87.7160" IsLoop="True" IsAutoPlay="True" CurrentAnimationName="walk" ctype="ArmatureNodeObjectData"> |
| 34 | <Size X="0.0000" Y="0.0000" /> | 34 | <Size X="0.0000" Y="0.0000" /> |
| 35 | <AnchorPoint /> | 35 | <AnchorPoint /> |
| 36 | <Position X="-2.1780" Y="87.7160" /> | 36 | <Position X="-2.1780" Y="87.7160" /> |
| ... | @@ -38,9 +38,9 @@ | ... | @@ -38,9 +38,9 @@ |
| 38 | <CColor A="255" R="255" G="255" B="255" /> | 38 | <CColor A="255" R="255" G="255" B="255" /> |
| 39 | <PrePosition X="-0.0090" Y="0.2741" /> | 39 | <PrePosition X="-0.0090" Y="0.2741" /> |
| 40 | <PreSize X="0.0000" Y="0.0000" /> | 40 | <PreSize X="0.0000" Y="0.0000" /> |
| 41 | <FileData Type="Normal" Path="ui/candy/candy_magnet/candy_magnet.ExportJson" Plist="" /> | 41 | <FileData Type="Default" Path="Default/DemoPlayer.ExportJson" Plist="" /> |
| 42 | </AbstractNodeData> | 42 | </AbstractNodeData> |
| 43 | <AbstractNodeData Name="flash" ActionTag="-444353949" Tag="15" IconVisible="True" LeftMargin="23.6212" RightMargin="217.3788" TopMargin="300.4264" BottomMargin="19.5736" IsLoop="False" IsAutoPlay="False" CurrentAnimationName="Animation1" ctype="ArmatureNodeObjectData"> | 43 | <AbstractNodeData Name="flash" ActionTag="-444353949" Tag="15" IconVisible="True" LeftMargin="23.6212" RightMargin="217.3788" TopMargin="300.4264" BottomMargin="19.5736" IsLoop="False" IsAutoPlay="False" CurrentAnimationName="walk" ctype="ArmatureNodeObjectData"> |
| 44 | <Size X="0.0000" Y="0.0000" /> | 44 | <Size X="0.0000" Y="0.0000" /> |
| 45 | <AnchorPoint /> | 45 | <AnchorPoint /> |
| 46 | <Position X="23.6212" Y="19.5736" /> | 46 | <Position X="23.6212" Y="19.5736" /> |
| ... | @@ -48,20 +48,20 @@ | ... | @@ -48,20 +48,20 @@ |
| 48 | <CColor A="255" R="255" G="255" B="255" /> | 48 | <CColor A="255" R="255" G="255" B="255" /> |
| 49 | <PrePosition X="0.0980" Y="0.0612" /> | 49 | <PrePosition X="0.0980" Y="0.0612" /> |
| 50 | <PreSize X="0.0000" Y="0.0000" /> | 50 | <PreSize X="0.0000" Y="0.0000" /> |
| 51 | <FileData Type="Normal" Path="ui/candy/jietangguolight01/jietangguolight01.ExportJson" Plist="" /> | 51 | <FileData Type="Default" Path="Default/DemoPlayer.ExportJson" Plist="" /> |
| 52 | </AbstractNodeData> | 52 | </AbstractNodeData> |
| 53 | <AbstractNodeData Name="candy_daizi" ActionTag="-1682033247" Tag="14" IconVisible="False" LeftMargin="-124.5405" RightMargin="96.5405" TopMargin="230.5468" BottomMargin="-10.5469" ctype="SpriteObjectData"> | 53 | <AbstractNodeData Name="candy_daizi" ActionTag="-1682033247" Tag="14" IconVisible="False" LeftMargin="-13.0405" RightMargin="208.0405" TopMargin="257.5469" BottomMargin="16.4531" ctype="SpriteObjectData"> |
| 54 | <Size X="269.0000" Y="100.0000" /> | 54 | <Size X="46.0000" Y="46.0000" /> |
| 55 | <AnchorPoint ScaleX="0.5000" ScaleY="0.5000" /> | 55 | <AnchorPoint ScaleX="0.5000" ScaleY="0.5000" /> |
| 56 | <Position X="9.9595" Y="39.4531" /> | 56 | <Position X="9.9595" Y="39.4531" /> |
| 57 | <Scale ScaleX="0.8000" ScaleY="0.8000" /> | 57 | <Scale ScaleX="0.8000" ScaleY="0.8000" /> |
| 58 | <CColor A="255" R="255" G="255" B="255" /> | 58 | <CColor A="255" R="255" G="255" B="255" /> |
| 59 | <PrePosition X="0.0413" Y="0.1233" /> | 59 | <PrePosition X="0.0413" Y="0.1233" /> |
| 60 | <PreSize X="1.1162" Y="0.3125" /> | 60 | <PreSize X="0.1909" Y="0.1437" /> |
| 61 | <FileData Type="Normal" Path="ui/candy/candy_daizi.png" Plist="" /> | 61 | <FileData Type="Default" Path="Default/Sprite.png" Plist="" /> |
| 62 | <BlendFunc Src="1" Dst="771" /> | 62 | <BlendFunc Src="1" Dst="771" /> |
| 63 | </AbstractNodeData> | 63 | </AbstractNodeData> |
| 64 | <AbstractNodeData Name="shield" ActionTag="-1223599666" Tag="70" IconVisible="True" LeftMargin="-4.5331" RightMargin="245.5331" TopMargin="184.2726" BottomMargin="135.7274" IsLoop="True" IsAutoPlay="True" CurrentAnimationName="Animation1" ctype="ArmatureNodeObjectData"> | 64 | <AbstractNodeData Name="shield" ActionTag="-1223599666" Tag="70" IconVisible="True" LeftMargin="-4.5331" RightMargin="245.5331" TopMargin="184.2726" BottomMargin="135.7274" IsLoop="True" IsAutoPlay="True" CurrentAnimationName="walk" ctype="ArmatureNodeObjectData"> |
| 65 | <Size X="0.0000" Y="0.0000" /> | 65 | <Size X="0.0000" Y="0.0000" /> |
| 66 | <AnchorPoint /> | 66 | <AnchorPoint /> |
| 67 | <Position X="-4.5331" Y="135.7274" /> | 67 | <Position X="-4.5331" Y="135.7274" /> |
| ... | @@ -69,7 +69,7 @@ | ... | @@ -69,7 +69,7 @@ |
| 69 | <CColor A="255" R="255" G="255" B="255" /> | 69 | <CColor A="255" R="255" G="255" B="255" /> |
| 70 | <PrePosition X="-0.0188" Y="0.4241" /> | 70 | <PrePosition X="-0.0188" Y="0.4241" /> |
| 71 | <PreSize X="0.0000" Y="0.0000" /> | 71 | <PreSize X="0.0000" Y="0.0000" /> |
| 72 | <FileData Type="Normal" Path="ui/candy/hudunnew/hudunnew.ExportJson" Plist="" /> | 72 | <FileData Type="Default" Path="Default/DemoPlayer.ExportJson" Plist="" /> |
| 73 | </AbstractNodeData> | 73 | </AbstractNodeData> |
| 74 | </Children> | 74 | </Children> |
| 75 | </ObjectData> | 75 | </ObjectData> | ... | ... |
| ... | @@ -6,15 +6,15 @@ | ... | @@ -6,15 +6,15 @@ |
| 6 | <ObjectData Name="Layer" Tag="30" ctype="GameLayerObjectData"> | 6 | <ObjectData Name="Layer" Tag="30" ctype="GameLayerObjectData"> |
| 7 | <Size X="234.0000" Y="286.0000" /> | 7 | <Size X="234.0000" Y="286.0000" /> |
| 8 | <Children> | 8 | <Children> |
| 9 | <AbstractNodeData Name="girl_1" ActionTag="1045743099" Tag="31" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" LeftMargin="-107.7612" RightMargin="107.7612" ctype="SpriteObjectData"> | 9 | <AbstractNodeData Name="girl_1" ActionTag="1045743099" Tag="31" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" LeftMargin="-13.7570" RightMargin="201.7570" TopMargin="240.0000" ctype="SpriteObjectData"> |
| 10 | <Size X="234.0000" Y="286.0000" /> | 10 | <Size X="46.0000" Y="46.0000" /> |
| 11 | <AnchorPoint ScaleX="0.5000" /> | 11 | <AnchorPoint ScaleX="0.5000" /> |
| 12 | <Position X="9.2388" /> | 12 | <Position X="9.2430" /> |
| 13 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> | 13 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> |
| 14 | <CColor A="255" R="255" G="255" B="255" /> | 14 | <CColor A="255" R="255" G="255" B="255" /> |
| 15 | <PrePosition X="0.0395" /> | 15 | <PrePosition X="0.0395" /> |
| 16 | <PreSize X="1.0000" Y="1.0000" /> | 16 | <PreSize X="0.1966" Y="0.1608" /> |
| 17 | <FileData Type="Normal" Path="ui/candy/girl_shdx.png" Plist="" /> | 17 | <FileData Type="Default" Path="Default/Sprite.png" Plist="" /> |
| 18 | <BlendFunc Src="1" Dst="771" /> | 18 | <BlendFunc Src="1" Dst="771" /> |
| 19 | </AbstractNodeData> | 19 | </AbstractNodeData> |
| 20 | <AbstractNodeData Name="pokect" ActionTag="-159700197" Tag="41" IconVisible="False" LeftMargin="-87.2379" RightMargin="121.2379" TopMargin="205.9375" BottomMargin="70.0625" TouchEnable="True" ClipAble="False" BackColorAlpha="102" ColorAngle="90.0000" Scale9Width="1" Scale9Height="1" ctype="PanelObjectData"> | 20 | <AbstractNodeData Name="pokect" ActionTag="-159700197" Tag="41" IconVisible="False" LeftMargin="-87.2379" RightMargin="121.2379" TopMargin="205.9375" BottomMargin="70.0625" TouchEnable="True" ClipAble="False" BackColorAlpha="102" ColorAngle="90.0000" Scale9Width="1" Scale9Height="1" ctype="PanelObjectData"> |
| ... | @@ -30,7 +30,7 @@ | ... | @@ -30,7 +30,7 @@ |
| 30 | <EndColor A="255" R="255" G="255" B="255" /> | 30 | <EndColor A="255" R="255" G="255" B="255" /> |
| 31 | <ColorVector ScaleY="1.0000" /> | 31 | <ColorVector ScaleY="1.0000" /> |
| 32 | </AbstractNodeData> | 32 | </AbstractNodeData> |
| 33 | <AbstractNodeData Name="magnet" ActionTag="1242017924" Tag="12" IconVisible="True" LeftMargin="-2.1780" RightMargin="236.1780" TopMargin="198.2840" BottomMargin="87.7160" IsLoop="True" IsAutoPlay="True" CurrentAnimationName="Action0" ctype="ArmatureNodeObjectData"> | 33 | <AbstractNodeData Name="magnet" ActionTag="1242017924" Tag="12" IconVisible="True" LeftMargin="-2.1780" RightMargin="236.1780" TopMargin="198.2840" BottomMargin="87.7160" IsLoop="True" IsAutoPlay="True" CurrentAnimationName="walk" ctype="ArmatureNodeObjectData"> |
| 34 | <Size X="0.0000" Y="0.0000" /> | 34 | <Size X="0.0000" Y="0.0000" /> |
| 35 | <AnchorPoint /> | 35 | <AnchorPoint /> |
| 36 | <Position X="-2.1780" Y="87.7160" /> | 36 | <Position X="-2.1780" Y="87.7160" /> |
| ... | @@ -38,9 +38,9 @@ | ... | @@ -38,9 +38,9 @@ |
| 38 | <CColor A="255" R="255" G="255" B="255" /> | 38 | <CColor A="255" R="255" G="255" B="255" /> |
| 39 | <PrePosition X="-0.0093" Y="0.3067" /> | 39 | <PrePosition X="-0.0093" Y="0.3067" /> |
| 40 | <PreSize X="0.0000" Y="0.0000" /> | 40 | <PreSize X="0.0000" Y="0.0000" /> |
| 41 | <FileData Type="Normal" Path="ui/candy/candy_magnet/candy_magnet.ExportJson" Plist="" /> | 41 | <FileData Type="Default" Path="Default/DemoPlayer.ExportJson" Plist="" /> |
| 42 | </AbstractNodeData> | 42 | </AbstractNodeData> |
| 43 | <AbstractNodeData Name="flash" ActionTag="-444353949" Tag="15" IconVisible="True" LeftMargin="23.6212" RightMargin="210.3788" TopMargin="266.4264" BottomMargin="19.5736" IsLoop="False" IsAutoPlay="False" CurrentAnimationName="Animation1" ctype="ArmatureNodeObjectData"> | 43 | <AbstractNodeData Name="flash" ActionTag="-444353949" Tag="15" IconVisible="True" LeftMargin="23.6212" RightMargin="210.3788" TopMargin="266.4264" BottomMargin="19.5736" IsLoop="False" IsAutoPlay="False" CurrentAnimationName="walk" ctype="ArmatureNodeObjectData"> |
| 44 | <Size X="0.0000" Y="0.0000" /> | 44 | <Size X="0.0000" Y="0.0000" /> |
| 45 | <AnchorPoint /> | 45 | <AnchorPoint /> |
| 46 | <Position X="23.6212" Y="19.5736" /> | 46 | <Position X="23.6212" Y="19.5736" /> |
| ... | @@ -48,20 +48,20 @@ | ... | @@ -48,20 +48,20 @@ |
| 48 | <CColor A="255" R="255" G="255" B="255" /> | 48 | <CColor A="255" R="255" G="255" B="255" /> |
| 49 | <PrePosition X="0.1009" Y="0.0684" /> | 49 | <PrePosition X="0.1009" Y="0.0684" /> |
| 50 | <PreSize X="0.0000" Y="0.0000" /> | 50 | <PreSize X="0.0000" Y="0.0000" /> |
| 51 | <FileData Type="Normal" Path="ui/candy/jietangguolight01/jietangguolight01.ExportJson" Plist="" /> | 51 | <FileData Type="Default" Path="Default/DemoPlayer.ExportJson" Plist="" /> |
| 52 | </AbstractNodeData> | 52 | </AbstractNodeData> |
| 53 | <AbstractNodeData Name="candy_daizi" ActionTag="-1682033247" Tag="14" IconVisible="False" LeftMargin="-115.5389" RightMargin="80.5389" TopMargin="195.5468" BottomMargin="-9.5468" ctype="SpriteObjectData"> | 53 | <AbstractNodeData Name="candy_daizi" ActionTag="-1682033247" Tag="14" IconVisible="False" LeftMargin="-4.0389" RightMargin="192.0389" TopMargin="222.5468" BottomMargin="17.4532" ctype="SpriteObjectData"> |
| 54 | <Size X="269.0000" Y="100.0000" /> | 54 | <Size X="46.0000" Y="46.0000" /> |
| 55 | <AnchorPoint ScaleX="0.5000" ScaleY="0.5000" /> | 55 | <AnchorPoint ScaleX="0.5000" ScaleY="0.5000" /> |
| 56 | <Position X="18.9611" Y="40.4532" /> | 56 | <Position X="18.9611" Y="40.4532" /> |
| 57 | <Scale ScaleX="0.8000" ScaleY="0.8000" /> | 57 | <Scale ScaleX="0.8000" ScaleY="0.8000" /> |
| 58 | <CColor A="255" R="255" G="255" B="255" /> | 58 | <CColor A="255" R="255" G="255" B="255" /> |
| 59 | <PrePosition X="0.0810" Y="0.1414" /> | 59 | <PrePosition X="0.0810" Y="0.1414" /> |
| 60 | <PreSize X="1.1496" Y="0.3497" /> | 60 | <PreSize X="0.1966" Y="0.1608" /> |
| 61 | <FileData Type="Normal" Path="ui/candy/candy_daizi.png" Plist="" /> | 61 | <FileData Type="Default" Path="Default/Sprite.png" Plist="" /> |
| 62 | <BlendFunc Src="1" Dst="771" /> | 62 | <BlendFunc Src="1" Dst="771" /> |
| 63 | </AbstractNodeData> | 63 | </AbstractNodeData> |
| 64 | <AbstractNodeData Name="shield" ActionTag="-1223599666" Tag="70" IconVisible="True" LeftMargin="10.0809" RightMargin="223.9191" TopMargin="156.2898" BottomMargin="129.7102" IsLoop="True" IsAutoPlay="True" CurrentAnimationName="Animation1" ctype="ArmatureNodeObjectData"> | 64 | <AbstractNodeData Name="shield" ActionTag="-1223599666" Tag="70" IconVisible="True" LeftMargin="10.0809" RightMargin="223.9191" TopMargin="156.2898" BottomMargin="129.7102" IsLoop="True" IsAutoPlay="True" CurrentAnimationName="walk" ctype="ArmatureNodeObjectData"> |
| 65 | <Size X="0.0000" Y="0.0000" /> | 65 | <Size X="0.0000" Y="0.0000" /> |
| 66 | <AnchorPoint /> | 66 | <AnchorPoint /> |
| 67 | <Position X="10.0809" Y="129.7102" /> | 67 | <Position X="10.0809" Y="129.7102" /> |
| ... | @@ -69,7 +69,7 @@ | ... | @@ -69,7 +69,7 @@ |
| 69 | <CColor A="255" R="255" G="255" B="255" /> | 69 | <CColor A="255" R="255" G="255" B="255" /> |
| 70 | <PrePosition X="0.0431" Y="0.4535" /> | 70 | <PrePosition X="0.0431" Y="0.4535" /> |
| 71 | <PreSize X="0.0000" Y="0.0000" /> | 71 | <PreSize X="0.0000" Y="0.0000" /> |
| 72 | <FileData Type="Normal" Path="ui/candy/hudunnew/hudunnew.ExportJson" Plist="" /> | 72 | <FileData Type="Default" Path="Default/DemoPlayer.ExportJson" Plist="" /> |
| 73 | </AbstractNodeData> | 73 | </AbstractNodeData> |
| 74 | </Children> | 74 | </Children> |
| 75 | </ObjectData> | 75 | </ObjectData> | ... | ... |
| ... | @@ -4,30 +4,30 @@ | ... | @@ -4,30 +4,30 @@ |
| 4 | <Content> | 4 | <Content> |
| 5 | <Animation Duration="0" Speed="1.0000" /> | 5 | <Animation Duration="0" Speed="1.0000" /> |
| 6 | <ObjectData Name="Scene" ctype="GameNodeObjectData"> | 6 | <ObjectData Name="Scene" ctype="GameNodeObjectData"> |
| 7 | <Size X="960.0000" Y="640.0000" /> | 7 | <Size X="1280.0000" Y="720.0000" /> |
| 8 | <Children> | 8 | <Children> |
| 9 | <AbstractNodeData Name="bg" ActionTag="953446860" Tag="5" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" LeftMargin="457.0000" RightMargin="457.0000" TopMargin="297.0000" BottomMargin="297.0000" ctype="SpriteObjectData"> | 9 | <AbstractNodeData Name="bg" ActionTag="953446860" Tag="5" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" ctype="SpriteObjectData"> |
| 10 | <Size X="1280.0000" Y="720.0000" /> | 10 | <Size X="1280.0000" Y="720.0000" /> |
| 11 | <AnchorPoint ScaleX="0.5000" ScaleY="0.5000" /> | 11 | <AnchorPoint ScaleX="0.5000" ScaleY="0.5000" /> |
| 12 | <Position X="480.0000" Y="320.0000" /> | 12 | <Position X="640.0000" Y="360.0000" /> |
| 13 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> | 13 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> |
| 14 | <CColor A="255" R="255" G="255" B="255" /> | 14 | <CColor A="255" R="255" G="255" B="255" /> |
| 15 | <PrePosition X="0.5000" Y="0.5000" /> | 15 | <PrePosition X="0.5000" Y="0.5000" /> |
| 16 | <PreSize X="0.0479" Y="0.0719" /> | 16 | <PreSize X="1.0000" Y="1.0000" /> |
| 17 | <FileData Type="Normal" Path="ui/rubbish/bg.png" Plist="" /> | 17 | <FileData Type="Normal" Path="ui/rubbish/bg.png" Plist="" /> |
| 18 | <BlendFunc Src="770" Dst="771" /> | 18 | <BlendFunc Src="1" Dst="771" /> |
| 19 | </AbstractNodeData> | 19 | </AbstractNodeData> |
| 20 | <AbstractNodeData Name="ArmatureNode_1" ActionTag="-14698423" Tag="616" IconVisible="True" LeftMargin="656.3848" RightMargin="303.6152" TopMargin="364.1816" BottomMargin="275.8184" IsLoop="True" IsAutoPlay="True" CurrentAnimationName="walk" ctype="ArmatureNodeObjectData"> | 20 | <AbstractNodeData Name="ArmatureNode_1" ActionTag="-14698423" Tag="616" IconVisible="True" LeftMargin="656.3848" RightMargin="623.6152" TopMargin="444.1816" BottomMargin="275.8184" IsLoop="True" IsAutoPlay="True" CurrentAnimationName="walk" ctype="ArmatureNodeObjectData"> |
| 21 | <Size X="0.0000" Y="0.0000" /> | 21 | <Size X="0.0000" Y="0.0000" /> |
| 22 | <AnchorPoint /> | 22 | <AnchorPoint /> |
| 23 | <Position X="656.3848" Y="275.8184" /> | 23 | <Position X="656.3848" Y="275.8184" /> |
| 24 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> | 24 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> |
| 25 | <CColor A="255" R="255" G="255" B="255" /> | 25 | <CColor A="255" R="255" G="255" B="255" /> |
| 26 | <PrePosition X="0.6837" Y="0.4310" /> | 26 | <PrePosition X="0.5128" Y="0.3831" /> |
| 27 | <PreSize X="0.0000" Y="0.0000" /> | 27 | <PreSize X="0.0000" Y="0.0000" /> |
| 28 | <FileData Type="Default" Path="Default/DemoPlayer.ExportJson" Plist="" /> | 28 | <FileData Type="Default" Path="Default/DemoPlayer.ExportJson" Plist="" /> |
| 29 | </AbstractNodeData> | 29 | </AbstractNodeData> |
| 30 | <AbstractNodeData Name="LoadingBar" ActionTag="-170014364" Tag="109" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" LeftMargin="208.6240" RightMargin="171.3760" TopMargin="513.7840" BottomMargin="68.2160" TouchEnable="True" ClipAble="False" BackColorAlpha="102" ColorAngle="90.0000" LeftEage="191" RightEage="191" TopEage="19" BottomEage="19" Scale9OriginX="191" Scale9OriginY="19" Scale9Width="198" Scale9Height="20" ctype="PanelObjectData"> | 30 | <AbstractNodeData Name="LoadingBar" ActionTag="-170014364" Tag="109" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" LeftMargin="374.8320" RightMargin="325.1680" TopMargin="581.6320" BottomMargin="80.3680" TouchEnable="True" ClipAble="False" BackColorAlpha="102" ColorAngle="90.0000" LeftEage="191" RightEage="191" TopEage="19" BottomEage="19" Scale9OriginX="191" Scale9OriginY="19" Scale9Width="198" Scale9Height="20" ctype="PanelObjectData"> |
| 31 | <Size X="580.0000" Y="58.0000" /> | 31 | <Size X="580.0000" Y="58.0000" /> |
| 32 | <Children> | 32 | <Children> |
| 33 | <AbstractNodeData Name="bar" ActionTag="1363230393" Tag="107" IconVisible="False" LeftMargin="20.0000" RightMargin="20.0000" TopMargin="17.0000" BottomMargin="17.0000" ProgressInfo="0" ctype="LoadingBarObjectData"> | 33 | <AbstractNodeData Name="bar" ActionTag="1363230393" Tag="107" IconVisible="False" LeftMargin="20.0000" RightMargin="20.0000" TopMargin="17.0000" BottomMargin="17.0000" ProgressInfo="0" ctype="LoadingBarObjectData"> |
| ... | @@ -42,48 +42,48 @@ | ... | @@ -42,48 +42,48 @@ |
| 42 | </AbstractNodeData> | 42 | </AbstractNodeData> |
| 43 | </Children> | 43 | </Children> |
| 44 | <AnchorPoint ScaleX="0.5000" ScaleY="0.5000" /> | 44 | <AnchorPoint ScaleX="0.5000" ScaleY="0.5000" /> |
| 45 | <Position X="498.6240" Y="97.2160" /> | 45 | <Position X="664.8320" Y="109.3680" /> |
| 46 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> | 46 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> |
| 47 | <CColor A="255" R="255" G="255" B="255" /> | 47 | <CColor A="255" R="255" G="255" B="255" /> |
| 48 | <PrePosition X="0.5194" Y="0.1519" /> | 48 | <PrePosition X="0.5194" Y="0.1519" /> |
| 49 | <PreSize X="0.6042" Y="0.0906" /> | 49 | <PreSize X="0.4531" Y="0.0806" /> |
| 50 | <FileData Type="Normal" Path="common_minigame/loading_bar_bg.png" Plist="" /> | 50 | <FileData Type="Normal" Path="common_minigame/loading_bar_bg.png" Plist="" /> |
| 51 | <SingleColor A="255" R="150" G="200" B="255" /> | 51 | <SingleColor A="255" R="150" G="200" B="255" /> |
| 52 | <FirstColor A="255" R="150" G="200" B="255" /> | 52 | <FirstColor A="255" R="150" G="200" B="255" /> |
| 53 | <EndColor A="255" R="255" G="255" B="255" /> | 53 | <EndColor A="255" R="255" G="255" B="255" /> |
| 54 | <ColorVector ScaleY="1.0000" /> | 54 | <ColorVector ScaleY="1.0000" /> |
| 55 | </AbstractNodeData> | 55 | </AbstractNodeData> |
| 56 | <AbstractNodeData Name="txt" ActionTag="639322624" Tag="127" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" LeftMargin="406.6560" RightMargin="233.3440" TopMargin="564.2560" BottomMargin="19.7440" IsCustomSize="True" FontSize="30" LabelText="LOADING 0%" VerticalAlignmentType="VT_Center" OutlineSize="3" OutlineEnabled="True" ShadowOffsetX="2.0000" ShadowOffsetY="-2.0000" ctype="TextObjectData"> | 56 | <AbstractNodeData Name="txt" ActionTag="639322624" Tag="127" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" LeftMargin="542.2080" RightMargin="417.7920" TopMargin="638.2880" BottomMargin="25.7120" IsCustomSize="True" FontSize="30" LabelText="LOADING 0%" VerticalAlignmentType="VT_Center" OutlineSize="3" OutlineEnabled="True" ShadowOffsetX="2.0000" ShadowOffsetY="-2.0000" ctype="TextObjectData"> |
| 57 | <Size X="320.0000" Y="56.0000" /> | 57 | <Size X="320.0000" Y="56.0000" /> |
| 58 | <AnchorPoint ScaleY="0.5000" /> | 58 | <AnchorPoint ScaleY="0.5000" /> |
| 59 | <Position X="406.6560" Y="47.7440" /> | 59 | <Position X="542.2080" Y="53.7120" /> |
| 60 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> | 60 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> |
| 61 | <CColor A="255" R="224" G="132" B="25" /> | 61 | <CColor A="255" R="224" G="132" B="25" /> |
| 62 | <PrePosition X="0.4236" Y="0.0746" /> | 62 | <PrePosition X="0.4236" Y="0.0746" /> |
| 63 | <PreSize X="0.3333" Y="0.0875" /> | 63 | <PreSize X="0.2500" Y="0.0778" /> |
| 64 | <FontResource Type="Normal" Path="ui/font/yahei.ttf" Plist="" /> | 64 | <FontResource Type="Normal" Path="ui/font/yahei.ttf" Plist="" /> |
| 65 | <OutlineColor A="255" R="255" G="255" B="255" /> | 65 | <OutlineColor A="255" R="255" G="255" B="255" /> |
| 66 | <ShadowColor A="255" R="110" G="110" B="110" /> | 66 | <ShadowColor A="255" R="110" G="110" B="110" /> |
| 67 | </AbstractNodeData> | 67 | </AbstractNodeData> |
| 68 | <AbstractNodeData Name="txt_ver" ActionTag="-1812371118" Tag="86" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" LeftMargin="873.0080" RightMargin="16.9920" TopMargin="604.5920" BottomMargin="15.4080" FontSize="20" LabelText="ver:1.0" ShadowOffsetX="2.0000" ShadowOffsetY="-2.0000" ctype="TextObjectData"> | 68 | <AbstractNodeData Name="txt_ver" ActionTag="-1812371118" Tag="86" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" LeftMargin="1187.3440" RightMargin="22.6560" TopMargin="681.4160" BottomMargin="18.5840" FontSize="20" LabelText="ver:1.0" ShadowOffsetX="2.0000" ShadowOffsetY="-2.0000" ctype="TextObjectData"> |
| 69 | <Size X="70.0000" Y="20.0000" /> | 69 | <Size X="70.0000" Y="20.0000" /> |
| 70 | <AnchorPoint ScaleX="1.0000" ScaleY="0.5000" /> | 70 | <AnchorPoint ScaleX="1.0000" ScaleY="0.5000" /> |
| 71 | <Position X="943.0080" Y="25.4080" /> | 71 | <Position X="1257.3440" Y="28.5840" /> |
| 72 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> | 72 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> |
| 73 | <CColor A="255" R="255" G="255" B="255" /> | 73 | <CColor A="255" R="255" G="255" B="255" /> |
| 74 | <PrePosition X="0.9823" Y="0.0397" /> | 74 | <PrePosition X="0.9823" Y="0.0397" /> |
| 75 | <PreSize X="0.0729" Y="0.0313" /> | 75 | <PreSize X="0.0547" Y="0.0278" /> |
| 76 | <OutlineColor A="255" R="255" G="0" B="0" /> | 76 | <OutlineColor A="255" R="255" G="0" B="0" /> |
| 77 | <ShadowColor A="255" R="110" G="110" B="110" /> | 77 | <ShadowColor A="255" R="110" G="110" B="110" /> |
| 78 | </AbstractNodeData> | 78 | </AbstractNodeData> |
| 79 | <AbstractNodeData Name="txt_update_ver" ActionTag="1813049155" Tag="355" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" LeftMargin="14.2080" RightMargin="875.7920" TopMargin="604.1440" BottomMargin="15.8560" FontSize="20" LabelText="ver:1.0" ShadowOffsetX="2.0000" ShadowOffsetY="-2.0000" ctype="TextObjectData"> | 79 | <AbstractNodeData Name="txt_update_ver" ActionTag="1813049155" Tag="355" IconVisible="False" PositionPercentXEnabled="True" PositionPercentYEnabled="True" LeftMargin="18.9440" RightMargin="1191.0560" TopMargin="680.9120" BottomMargin="19.0880" FontSize="20" LabelText="ver:1.0" ShadowOffsetX="2.0000" ShadowOffsetY="-2.0000" ctype="TextObjectData"> |
| 80 | <Size X="70.0000" Y="20.0000" /> | 80 | <Size X="70.0000" Y="20.0000" /> |
| 81 | <AnchorPoint ScaleY="0.5000" /> | 81 | <AnchorPoint ScaleY="0.5000" /> |
| 82 | <Position X="14.2080" Y="25.8560" /> | 82 | <Position X="18.9440" Y="29.0880" /> |
| 83 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> | 83 | <Scale ScaleX="1.0000" ScaleY="1.0000" /> |
| 84 | <CColor A="255" R="255" G="255" B="255" /> | 84 | <CColor A="255" R="255" G="255" B="255" /> |
| 85 | <PrePosition X="0.0148" Y="0.0404" /> | 85 | <PrePosition X="0.0148" Y="0.0404" /> |
| 86 | <PreSize X="0.0729" Y="0.0313" /> | 86 | <PreSize X="0.0547" Y="0.0278" /> |
| 87 | <OutlineColor A="255" R="255" G="0" B="0" /> | 87 | <OutlineColor A="255" R="255" G="0" B="0" /> |
| 88 | <ShadowColor A="255" R="110" G="110" B="110" /> | 88 | <ShadowColor A="255" R="110" G="110" B="110" /> |
| 89 | </AbstractNodeData> | 89 | </AbstractNodeData> | ... | ... |
| 1 | <SolutionConfig Version="3.10.0.0"> | 1 | <SolutionConfig Version="3.10.0.0"> |
| 2 | <PublishDirectory Value="res/" /> | 2 | <PublishDirectory Value="D:/xhx/client/rubbish/client/res/" /> |
| 3 | <PackageDirectory Value="package/" /> | 3 | <PackageDirectory Value="package/" /> |
| 4 | <PublishType Value="Reference" /> | 4 | <PublishType Value="Reference" /> |
| 5 | <SolutionSize Value="960 * 640" /> | 5 | <SolutionSize Value="1280 * 720" /> |
| 6 | <ResolutionName Value="iPhone 4/4S" /> | 6 | <ResolutionName Value="Android" /> |
| 7 | <DefaultSerializer Value="Serializer_FlatBuffers" /> | 7 | <DefaultSerializer Value="Serializer_FlatBuffers" /> |
| 8 | <CustomSerializer Value="Serializer_FlatBuffers" /> | 8 | <CustomSerializer Value="Serializer_FlatBuffers" /> |
| 9 | <IsNameStandardized Value="False" /> | 9 | <IsNameStandardized Value="False" /> | ... | ... |
| ... | @@ -7,5 +7,37 @@ | ... | @@ -7,5 +7,37 @@ |
| 7 | <LastRunType Value="Windows" /> | 7 | <LastRunType Value="Windows" /> |
| 8 | </Value> | 8 | </Value> |
| 9 | </Item> | 9 | </Item> |
| 10 | <Item Key="PackageParamsKey"> | ||
| 11 | <Value ctype="PackageParams"> | ||
| 12 | <LuaIsEncrypt Value="False" /> | ||
| 13 | <LuaEncryptKey Value="" /> | ||
| 14 | <LuaEncryptSign Value="" /> | ||
| 15 | <Android_PackageName Value="org.cocos.rubbish" /> | ||
| 16 | <AndroidkeyStore Value="" /> | ||
| 17 | <AndroidVersion Value="" /> | ||
| 18 | <iOS_Target Value="rubbish-mobile" /> | ||
| 19 | <iOS_BundleID Value="" /> | ||
| 20 | <Platform Value="None" /> | ||
| 21 | <RunPlatform Value="None" /> | ||
| 22 | <FrameworkVersion Value="cocos2d-x-3.10" /> | ||
| 23 | <IsDebugKeystore Value="True" /> | ||
| 24 | <KeystorePassword Value="" /> | ||
| 25 | <KeystoreAliasName Value="" /> | ||
| 26 | <KeystoreAliasPassword Value="" /> | ||
| 27 | <EnableSourceMap Value="False" /> | ||
| 28 | <EnableHTML5Advanced Value="False" /> | ||
| 29 | </Value> | ||
| 30 | </Item> | ||
| 31 | <Item Key="TabsParamsKey"> | ||
| 32 | <Value ctype="TabsInfo"> | ||
| 33 | <OpenedDocuments> | ||
| 34 | <FilePathData Path="ui/LoadingDataLayer.csd" /> | ||
| 35 | <FilePathData Path="ui/rubbish/LoadingScene.csd" /> | ||
| 36 | <FilePathData Path="ui/rubbish/GameStartLayer.csd" /> | ||
| 37 | <FilePathData Path="ui/rubbish/GameScene.csd" /> | ||
| 38 | </OpenedDocuments> | ||
| 39 | <ActiveDocument Path="ui/rubbish/GameScene.csd" /> | ||
| 40 | </Value> | ||
| 41 | </Item> | ||
| 10 | </Properties> | 42 | </Properties> |
| 11 | </UserData> | 43 | </UserData> |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
No preview for this file type
-
Please register or sign in to post a comment