Changeset 9598

Show
Ignore:
Timestamp:
04/17/08 00:39:07 (5 years ago)
Author:
tarchan
Message:

lang/java/NanikaKit: 里々スクリプトの評価を修正 #95

Location:
lang/java/NanikaKit/trunk/src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/java/NanikaKit/trunk/src/com/mac/tarchan/nanika/SakuraGhost.java

    r9535 r9598  
    99 
    1010import java.awt.Component; 
     11import java.awt.EventQueue; 
    1112import java.awt.Graphics2D; 
    1213import java.awt.Rectangle; 
     
    454455         * @return このゴーストへの参照 
    455456         */ 
    456         public SakuraGhost waitTime(long ms) 
    457         { 
    458                 try 
    459                 { 
    460                         Thread.sleep(ms); 
    461                 } 
    462                 catch (InterruptedException e) 
    463                 { 
    464                 } 
    465  
    466                 return this; 
    467         } 
    468  
    469         /** 
    470          * えんいー 
    471          *  
    472          * @return このゴーストへの参照 
    473          */ 
    474         public SakuraGhost yen_e() 
    475         { 
     457        public SakuraGhost waitTime(final long ms) 
     458        { 
     459                EventQueue.invokeLater(new Runnable() 
     460                { 
     461                        public void run() 
     462                        { 
     463                                try 
     464                                { 
     465                                        Thread.sleep(ms); 
     466                                } 
     467                                catch (InterruptedException e) 
     468                                { 
     469                                        log.error("sleep error: " + ms, e); 
     470                                } 
     471                        } 
     472                }); 
     473 
    476474                return this; 
    477475        } 
     
    525523                        kero.draw(g); 
    526524                } 
     525                observer.getToolkit().sync(); 
    527526        } 
    528527 
  • lang/java/NanikaKit/trunk/src/test/com/mac/tarchan/nanika/NiseSatori.java

    r9535 r9598  
    5252 
    5353        /** 区切り文字 */ 
    54         Pattern delimiter = Pattern.compile("(@|*|#).*"); 
     54        Pattern delimiter = Pattern.compile("[@*#](.*)"); 
    5555 
    5656        /** 
     
    6363        public boolean load(NanikaArchive nar) 
    6464        { 
     65                // TODO load(File ghost) をシミュレートすべきか? 
    6566                log.debug("satori nar: " + nar); 
    6667                File ghostDir = nar.getGhostDirectory(); 
     
    171172                                        // トーク 
    172173                                        log.trace("トーク=" + line); 
    173                                         line = scanTalk(s, line); 
     174                                        line = scanTalk(s, s.match().group(1)); 
    174175                                } 
    175176                                else if (line.startsWith("@")) 
     
    204205        private String scanTalk(Scanner s, String line) 
    205206        { 
    206                 String key = line.substring(1); 
     207                String key = line; 
    207208                StringBuilder value = new StringBuilder(); 
    208209                while (true) 
     
    260261                log.trace(String.format("\"%s\"=\"%s\"", key , value)); 
    261262                talks.put(key , value); 
    262 //              List<String> list = talks.get(key); 
    263 //              if (list == null) 
    264 //              { 
    265 //                      list = new LinkedList<String>(); 
    266 //                      talks.put(key, list); 
    267 //              } 
    268 //              list.add(value); 
    269263        } 
    270264 
     
    281275                log.trace(String.format("\"%s\"=\"%s\"", key , value)); 
    282276                words.put(key , value); 
    283 //              List<String> list = words.get(key); 
    284 //              if (list == null) 
    285 //              { 
    286 //                      list = new LinkedList<String>(); 
    287 //                      words.put(key, list); 
    288 //              } 
    289 //              list.add(value); 
    290277        } 
    291278 
     
    302289        { 
    303290                return talks.get(key); 
    304 //              List<String> list = talks.get(key); 
    305 //              if (list == null) return null; 
    306 // 
    307 //              int len = list.size(); 
    308 //              int index = rand.nextInt(len); 
    309 //              String talk = list.get(index); 
    310 //              return talk; 
    311291        } 
    312292 
     
    320300        { 
    321301                return words.get(key); 
    322 //              List<String> list = words.get(key); 
    323 //              if (list == null) return null; 
    324 // 
    325 //              int len = list.size(); 
    326 //              int index = rand.nextInt(len); 
    327 //              String word = list.get(index); 
    328 //              return word; 
    329302        } 
    330303 
     
    340313                log.debug("command: " + command); 
    341314//              return "\\0\\s[0]こんにちは。\\1\\s[10]よぉ。\\e"; 
     315 
    342316                String talk = getTalk(""); 
    343317                log.debug("里々=" + talk); 
     318 
    344319                talk = eval(talk); 
    345320                log.debug("さくら=" + talk); 
     321 
    346322                return talk; 
    347323        } 
     
    359335                buf.append("\\0\\s[0]\\1\\s[10]"); 
    360336                int scope = 1; 
    361 //              Pattern p = Pattern.compile("(?:|((.+)))"); 
    362 //              while (s.hasNextLine()) 
     337                int wait = 100; 
    363338                while (true) 
    364339                { 
    365                         String find = s.findInLine(":|(.+?)|\n|[^:(]+"); 
     340                        String find = s.findInLine(":|((.+?))|、|。|\n|[^:(、。]+"); 
    366341                        if (find == null) break; 
    367342                        log.debug("find=" + find); 
     
    369344                        if (find.startsWith(":")) 
    370345                        { 
     346                                // スコープ切り替え 
    371347                                scope = scope != 0 ? 0 : 1; 
    372348                                buf.append("\\"); 
     
    375351                        else if (find.startsWith("(")) 
    376352                        { 
    377                                 String key = find.substring(1, find.length() - 1); 
     353                                // サーフェス切り替え 
     354//                              String key = find.substring(1, find.length() - 1); 
     355                                String key = s.match().group(1); 
    378356                                try 
    379357                                { 
     
    385363                                catch (NumberFormatException e) 
    386364                                { 
     365                                        // 単語置き換え 
    387366                                        String word = getWord(key); 
    388367                                        if (word == null) word = "{" + key + "}"; 
     
    390369                                } 
    391370                        } 
     371                        else if (find.startsWith("、")) 
     372                        { 
     373                                // 読点 
     374                                buf.append("、"); 
     375                                buf.append("\\_w["); 
     376                                buf.append(wait); 
     377                                buf.append("]"); 
     378                        } 
     379                        else if (find.startsWith("。")) 
     380                        { 
     381                                // 句点 
     382                                buf.append("。"); 
     383                                buf.append("\\_w["); 
     384                                buf.append(wait); 
     385                                buf.append("]"); 
     386                        } 
    392387                        else if (find.startsWith("\n")) 
    393388                        { 
     389                                // 改行 
    394390                                buf.append("\\n"); 
    395391                        } 
    396392                        else 
    397393                        { 
     394                                // テキスト 
    398395                                buf.append(find); 
    399396                        } 
    400397                } 
    401398 
     399                // さくらスクリプトを返す 
    402400                return replace(replace_after, buf.toString()); 
    403401        }