Esempio n. 1
0
 /// <summary>
 /// 커맨드를 추가한다
 /// </summary>
 /// <param name="genfunc">Segment 생성 함수</param>
 /// <param name="commandName">커맨드 이름</param>
 /// <param name="commandAliases">커맨드 이름 추가 지정</param>
 public static void AddCommand(CommandSegmentGenerateFunc genfunc, string commandName, params string[] commandAliases)
 {
     s_aliasToSegFunction[commandName] = genfunc;
     foreach (var name in commandAliases)
     {
         s_aliasToSegFunction[name] = genfunc;
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 커맨드를 추가한다
 /// </summary>
 /// <param name="genfunc">Segment 생성 함수</param>
 /// <param name="commandName">커맨드 이름</param>
 /// <param name="commandAliases">커맨드 이름 추가 지정</param>
 public static void AddCommand(CommandSegmentGenerateFunc genfunc, string commandName, params string[] commandAliases)
 {
     s_aliasToSegFunction[commandName]	= genfunc;
     foreach(var name in commandAliases)
     {
         s_aliasToSegFunction[name]		= genfunc;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 문자열으로 스크립트 파싱
        /// </summary>
        /// <param name="scriptData"></param>
        /// <returns></returns>
        public static FSNScriptSequence FromString(string scriptData, FSNSession session)
        {
            // 디버깅 세션 세팅
            FSNDebug.currentRuntimeStage = FSNDebug.RuntimeStage.Compile;

            var sequence = new FSNScriptSequence();

            sequence.OriginalScriptPath = "(string)";
            sequence.ScriptHashKey      = GenerateHashKeyFromScript(scriptData);                    // 해시키 생성해두기 (세이브 파일과 스크립트 파일 버전 체크용)

            // ===== FIRST PASS : 헤더 파일 먼저 해석 ==================================

            ProcessHeaders(scriptData, sequence, session);


            // ===== SECOND PASS : 나머지 스크립트 요소들 해석 =========================
            var strstream = new System.IO.StringReader(scriptData);

            // 스크립트 해석 상태값들
            CommandGenerateProtocol protocol = new CommandGenerateProtocol();

            // flags
            Segments.Period periodSeg         = null;                                                   // Period 세그먼트. 먼저 만들어놓고 있다가 적당한 때에 삽입한다. (스크립트와 실제 세그먼트 순서가 다르기 때문)
            bool            textMultilineMode = false;                                                  // 텍스트 여러줄 처리중인지 (//)
            string          multilineText     = "";                                                     // 멀티라인 모드에서, 텍스트 처리중일 때
            //

            // ** 스크립트 로드 후 첫번째 스냅샷에서 다시 이전으로 돌아가는 것은 불가능하므로, 맨 처음에 oneway 컨트롤 세그먼트를 추가해준다
            var onewayAtFirstSeg = new Segments.Control();

            onewayAtFirstSeg.controlType = Segments.Control.ControlType.Oneway;
            var onewaySegInfo = new FSNScriptSequence.Parser.GeneratedSegmentInfo()
            {
                newSeg = onewayAtFirstSeg
            };

            protocol.PushSegment(onewaySegInfo);
            //

            string line       = null;
            int    linenumber = 0;                           // 줄 번호

            while ((line = strstream.ReadLine()) != null)    // 줄 단위로 읽는다.
            {
                line = sequence.Header.Macros.Replace(line); // 정적 매크로 치환

                linenumber++;
                FSNDebug.currentProcessingScriptLine = linenumber;                      // 디버깅 정보 설정

                if (!textMultilineMode && line.Length == 0)                             // * 빈 줄은 스루. 단 여러줄 텍스트 모드일 경우 빈 줄에서는 여러줄 모드를 끝내게 한다.
                {
                    continue;
                }

                if (line.EndsWith(c_token_LineConcat))                                                  // * 여러줄 텍스트로 지정된 경우, 자동으로 여러줄 모드로. 해당 라인 붙이기
                {
                    textMultilineMode = true;

                    if (multilineText.Length > 0)                                                               // 이미 쌓여있는 텍스트가 있다면 공백 추가
                    {
                        multilineText += "\n";
                    }
                    multilineText += line.Substring(0, line.Length - c_token_LineConcat.Length);
                }
                else
                {
                    var pretoken = line.Length > 0? line.Substring(0, 1) : "";
                    switch (pretoken)                                                                                           // 앞쪽 토큰으로 명령 구분
                    {
                    case c_token_Comment:                                                                                       // * 주석
                        // 스루. 뭐 왜 뭐 주석인데 뭐
                        break;

                    case c_token_PreProcessor:                                                                                  // * 전처리 구문
                        // 프리프로세서는 첫번째 패스에서 처리함.
                        break;

                    case c_token_Command:                                                                                       // * 명령
                    {
                        var commandAndParam = line.Substring(1).Split(c_whiteSpaceArray, 2);                                    // 명령어 파라미터 구분
                        var command         = commandAndParam[0];
                        var paramStr        = commandAndParam.Length > 1? commandAndParam[1] : "";

                        CommandSegmentGenerateFunc genfunc = null;
                        s_aliasToSegFunction.TryGetValue(command, out genfunc);
                        if (genfunc == null)                                                                                                                                                                    // 등록된 명령어인지 체크
                        {
                            Debug.LogError("Unknown command : " + command);
                        }
                        else
                        {
                            protocol.parameters = ParseParameters(paramStr);
                            genfunc(protocol);
                        }
                    }
                    break;

                    case c_token_HardLabel:                                                                                     // * hard label
                    {
                        var labelSeg = new Segments.Label();
                        labelSeg.labelName = line.Substring(1);
                        labelSeg.labelType = Segments.Label.LabelType.Hard;

                        var segInfo = new GeneratedSegmentInfo();
                        segInfo.newSeg        = labelSeg;
                        segInfo.usePrevPeriod = true;                                                                   // Label 전에 period로 다 출력해야함
                        segInfo.selfPeriod    = false;
                        protocol.PushSegment(segInfo);
                    }
                    break;

                    case c_token_SoftLabel:                                                                                     // * soft label
                    {
                        var labelSeg = new Segments.Label();
                        labelSeg.labelName = line.Substring(1);
                        labelSeg.labelType = Segments.Label.LabelType.Soft;

                        var segInfo = new GeneratedSegmentInfo();
                        segInfo.newSeg        = labelSeg;
                        segInfo.usePrevPeriod = true;                                                                   // Label 전에 period로 다 출력해야함
                        segInfo.selfPeriod    = false;
                        protocol.PushSegment(segInfo);
                    }
                    break;

                    case c_token_Period:                                                                                        // * period
                        if (line.Length == 1)                                                                                   // . 한글자일 때 - 일반 period
                        {
                            if (periodSeg != null)                                                                              // * 이미 period 명령어가 대기중일 때, 기존 명령어를 먼저 처리한다
                            {
                                sequence.m_segments.Add(periodSeg);
                            }
                            periodSeg = new Segments.Period();
                        }
                        else if (line.Length == 2 && line[1].ToString() == c_token_Period)                                      // .. 으로 두 글자일 때 - 연결 period, 만약 period가 이전에 등장했다면 연결으로 변경
                        {
                            Segments.Period lastPeriodseg;

                            if (periodSeg != null)                                                                                                                      // 처리 안된 period가 있을 경우, 이것을 chaining으로 변경해준다
                            {
                                lastPeriodseg = periodSeg;
                            }
                            else if ((lastPeriodseg = sequence.m_segments[sequence.m_segments.Count - 1] as Segments.Period)
                                     .type == Segment.Type.Period)                                                                                              // 아닐 경우, 가장 마지막으로 추가된 세그먼트가 period를 chaining으로 변경한다
                            {
                                //
                            }
                            else
                            {                                                                                                                                                                   // 그도 아닐 경우 새로 period 생성
                                periodSeg     = new Segments.Period();
                                lastPeriodseg = periodSeg;
                            }

                            lastPeriodseg.isChaining = true;                                                                                                    // 선택한 period에 chaining속성 부여
                        }
                        else
                        {
                            Debug.LogError("invalid command... is it a period command?");
                        }
                        break;

                    case c_token_ForceText:
                    default:                                                                                                    // * 아무 토큰도 없음 : 텍스트
                    {
                        if (line.Length > 0 && line[0].ToString() == c_token_ForceText)                                         // 만약 강제 텍스트 토큰 (~) 이 붙어있었다면, 해당 토큰 제거
                        {
                            line = line.Substring(1);
                        }

                        multilineText += multilineText.Length > 0? "\n" + line : line;
                        var textSeg = new Segments.Text();
                        textSeg.text     = multilineText;
                        textSeg.textType = Segments.Text.TextType.Normal;

                        multilineText     = "";                                                 // 멀티라인 텍스트 보관되어있던 것을 초기화
                        textMultilineMode = false;

                        var segInfo = new GeneratedSegmentInfo();
                        segInfo.newSeg        = textSeg;
                        segInfo.usePrevPeriod = true;                                           // 출력 명령어임
                        segInfo.selfPeriod    = true;                                           // 스스로 period를 포함함
                        protocol.PushSegment(segInfo);
                    }
                    break;
                    }

                    GeneratedSegmentInfo newSegInfo = null;
                    while ((newSegInfo = protocol.PullSegment()) != null)                       // 새로 생성된 시퀀스 모두 처리
                    {
                        if (newSegInfo.usePrevPeriod && periodSeg != null)                      // * 선행 period를 먼저 처리해야하는 상황
                        {
                            periodSeg.scriptLineNumber = linenumber;                            // 줄번호 기록?
                            sequence.m_segments.Add(periodSeg);
                            periodSeg = null;
                        }

                        newSegInfo.newSeg.scriptLineNumber = linenumber;                                // 줄번호 기록
                        sequence.m_segments.Add(newSegInfo.newSeg);                                     // 시퀀스 추가
                        if (newSegInfo.newSeg.type == Segment.Type.Label)                               // 라벨일 경우 등록
                        {
                            sequence.RegisterLabelSegment();
                        }

                        if (newSegInfo.selfPeriod)                                                                              // * 방금 추가된 세그먼트가 period를 포함하는 개념이라면, period 대기시켜놓기
                        {
                            periodSeg = new Segments.Period();
                        }
                    }
                }
            }

            if (periodSeg != null)                                                                              // 끝날 때까지 처리되지 않은 period가 있다면 여기서 추가해준다
            {
                periodSeg.scriptLineNumber = linenumber;                                                        // 줄번호 기록?
                sequence.m_segments.Add(periodSeg);
                periodSeg = null;
            }

            // 디버깅 세션 세팅
            FSNDebug.currentRuntimeStage = FSNDebug.RuntimeStage.Runtime;

            return(sequence);
        }