Example #1
0
        public static string Sum(ActionFile actionFile)
        {
            if (!srvmd5memo.ContainsKey(actionFile.Name))
            {
                Sum(actionFile.GoalMessage);
                Sum(actionFile.ResultMessage);
                Sum(actionFile.FeedbackMessage);
                string hashableGoal     = PrepareToHash(actionFile.GoalMessage);
                string hashableResult   = PrepareToHash(actionFile.ResultMessage);
                string hashableFeedback = PrepareToHash(actionFile.FeedbackMessage);
                if (hashableGoal == null || hashableResult == null || hashableFeedback == null)
                {
                    return(null);
                }

                byte[] goal     = Encoding.ASCII.GetBytes(hashableGoal);
                byte[] result   = Encoding.ASCII.GetBytes(hashableResult);
                byte[] feedback = Encoding.ASCII.GetBytes(hashableFeedback);

                var md5 = System.Security.Cryptography.IncrementalHash.CreateHash(System.Security.Cryptography.HashAlgorithmName.MD5);
                md5.AppendData(goal);
                md5.AppendData(result);
                md5.AppendData(feedback);
                var hash = md5.GetHashAndReset();

                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < hash.Length; i++)
                {
                    sb.AppendFormat("{0:x2}", hash[i]);
                }
                srvmd5memo.Add(actionFile.Name, sb.ToString());
            }
            return(srvmd5memo[actionFile.Name]);
        }
Example #2
0
    /// <summary>
    /// Returns true if the current action is a new action that is not currently in the ActionFile.
    /// If the action is in the ActionFile, it will return false.
    /// </summary>
    /// <returns></returns>
    public static bool CurrentActionIsNew()
    {
        DynamicAction action     = instance.currentAction;
        ActionFile    actionFile = instance.loadedActionFile;

        return(!actionFile.actions.Contains(action));
    }
Example #3
0
 // Start is called before the first frame update
 void Start()
 {
     if (tussleScriptDocument != null)
     {
         testActionFile = new ActionFile();
         ParseActionScript(tussleScriptDocument.text, testActionFile, false);
     }
 }
Example #4
0
    /// <summary>
    /// Parse a string representation of an Action Script
    /// </summary>
    /// <param name="actionScript">the action script to parse</param>
    /// <returns>-1 on error, 1 on success</returns>
    public static int ParseActionScript(string actionScript, ActionFile outputFile, bool overwrite)
    {
        //Reset the working vars
        workingAction       = null;
        workingSubGroupName = null;

        StringReader reader = new StringReader(actionScript);

        string line;
        int    lineNumber = 0;

        while ((line = reader.ReadLine()) != null)
        {
            line = line.Trim(); //Remove the tabs. We ain't python.
            if (line.Length == 0 || line.StartsWith("#"))
            {
                lineNumber++;
                continue; //Skip empty lines and comments
            }

            string tokenValue;
            //Process Start Token
            if ((tokenValue = GetTokenVal(line, ActionTokens.Start)) != null)
            {
                if (workingAction == null)
                {
                    workingAction = new DynamicAction(tokenValue);
                    //Debug.Log(string.Format("Creating new action with name {0}", tokenValue));
                }
                else
                {
                    return(throwException("Attempting to create a new action before finishing the old one", lineNumber));
                }
            }

            //Process End Token
            else if ((tokenValue = GetTokenVal(line, ActionTokens.End, 0)) != null)
            {
                //TODO Finish the action here
                //Debug.Log("Ending Action Definition");
                outputFile.Add(workingAction, overwrite);

                workingAction = null;
            }

            if (workingAction != null)
            {
                ProcessActionSection(line, workingAction, lineNumber);
            }

            lineNumber++;
        }

        return(SUCCESS);
    }
 public void OnFighterInfoReady(FighterInfo fInfo)
 {
     fighter_info    = fInfo;
     actions_file    = fighter_info.action_file;
     _current_action = new NeutralAction();
     _current_action.SetDynamicAction(actions_file.Get("NeutralAction"));
     if (isInBuilder)
     {
         _current_action.setIsInBuilder(true);
     }
     _current_action.SetUp(getBattleObject());
 }
Example #6
0
    public void LoadNewFighter(FighterInfo fInfo)
    {
        FighterDirName = fInfo.directory_name;

        loadedFighter    = fInfo;
        loadedActionFile = ActionFile.LoadActionsFromFile(FighterDirName, fInfo.actionFilePath);
        currentAction    = loadedActionFile.GetFirst();
        loadedSpriteInfo = SpriteInfo.LoadSpritesFromFile(FighterDirName, fInfo.spriteInfoPath);
        loadedSpriteInfo.LoadDirectory(FighterDirName, loadedFighter);

        FireModelChange();
    }
    void OnActionFileChanged(ActionFile actionFile)
    {
        clearAll();

        //Create all the new buttons
        foreach (DynamicAction action in actionFile.actions)
        {
            instantiateButton(action);
        }

        //Realign the grid
        grid.Reposition();
    }
Example #8
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.PropertyField(position, property, label, true);
        ActionFile info = fieldInfo.GetValue(property.serializedObject.targetObject) as ActionFile;

        if (property.isExpanded)
        {
            if (GUI.Button(new Rect(position.xMin + 30f, position.yMax - 20f, position.width - 30f, 20f), "Load From Text Asset"))
            {
                info.LoadFromTextAsset();
            }
        }
    }
Example #9
0
 public void LoadActions()
 {
     if (json_file != null)
     {
         action_file = JsonUtility.FromJson <ActionFile>(json_file.text);
     }
     else
     {
         string combinedPath = FileLoader.PathCombine(FileLoader.GetFighterPath(directory), filename);
         string json         = FileLoader.LoadTextFile(combinedPath);
         action_file = JsonUtility.FromJson <ActionFile>(json);
     }
 }
Example #10
0
    /// <summary>
    /// Fire all the changes to things that were modified in the editor
    /// </summary>
    private void Start()
    {
        Application.targetFrameRate = 60;

        //Load the fighter, then initialize it. We need to call the changed event here once the directory loads before we do the rest
        loadedFighter.LoadDirectory(FighterDirName);
        FighterInfoChangedEvent(loadedFighter);

        loadedActionFile = ActionFile.LoadActionsFromFile(FighterDirName, loadedFighter.actionFilePath);
        currentAction    = loadedActionFile.GetFirst();
        loadedSpriteInfo = SpriteInfo.LoadSpritesFromFile(FighterDirName, loadedFighter.spriteInfoPath);
        loadedSpriteInfo.LoadDirectory(FighterDirName, loadedFighter);
        FireModelChange();
    }
Example #11
0
        public void Should_ProduceCorrectMD5Sums_When_GivenRosDefaultActionFiles(MsgFileLocation stubFile, string[] lines,
                                                                                 Dictionary <string, string> md5sums)
        {
            // Parse action file
            var actionFile = new ActionFile(stubFile, lines);

            actionFile.ParseAndResolveTypes();

            // Compare MD5 sums
            Assert.Equal(md5sums["Goal"], MD5.Sum(actionFile.GoalMessage));
            Assert.Equal(md5sums["ActionGoal"], MD5.Sum(actionFile.GoalActionMessage));
            Assert.Equal(md5sums["Result"], MD5.Sum(actionFile.ResultMessage));
            Assert.Equal(md5sums["ActionResult"], MD5.Sum(actionFile.ResultActionMessage));
            Assert.Equal(md5sums["Feedback"], MD5.Sum(actionFile.FeedbackMessage));
            Assert.Equal(md5sums["ActionFeedback"], MD5.Sum(actionFile.FeedbackActionMessage));
        }
Example #12
0
    private bool OverwriteFromTussleScript(FileInfo info)
    {
        string tussleScriptString = File.ReadAllText(info.FullName);
        //Keep a backup of the action file in case there's an error
        ActionFile oldActionFile = loadedActionFile;
        int        result        = TussleScriptParser.ParseActionScript(tussleScriptString, loadedActionFile, true);

        if (result < 0)
        {
            loadedActionFile = oldActionFile;
            Debug.LogWarning("Error parsing TussleScript: " + info.Name);
            return(false);
        }
        ChangedActionFile();
        return(true);
    }
    public void CreateFighter(DirectoryInfo createdDir, FighterInfo templateFighter)
    {
        FighterInfo newInfo;

        if (templateFighter != null)
        {
            newInfo = CloneTemplateFighter(createdDir, templateFighter);
        }
        else
        {
            newInfo = new FighterInfo();
            ActionFile newActions = new ActionFile();
            newActions.Save(Path.Combine(createdDir.FullName, "fighter_actions.json"));
            newInfo.displayName    = directoryName;
            newInfo.directory_name = directoryName;
            newInfo.actionFilePath = "fighter_actions.json";
            newInfo.GenerateDefaultAttributes();
            if (generateActions)
            {
                //TODO Clone default actions here
            }

            if (useSprite)
            {
                DirectoryInfo spriteDir  = Directory.CreateDirectory(Path.Combine(createdDir.FullName, "sprites"));
                SpriteInfo    spriteInfo = new SpriteInfo();

                spriteInfo.spriteDirectory = "sprites";
                spriteInfo.default_sprite  = "idle";
                spriteInfo.costumeName     = "default";

                spriteInfo.Save(Path.Combine(createdDir.FullName, "sprite_info.json"));
                newInfo.sprite_info = spriteInfo;
            }

            if (useModel)
            {
                //TODO create model directory and stuff
            }
        }

        newInfo.Save(Path.Combine(FileLoader.GetFighterDir(directoryName).FullName, "fighter_info.json"));
        newInfo.sprite_info.Save(Path.Combine(createdDir.FullName, "sprite_info.json"));

        LegacyEditorData.instance.LoadNewFighter(newInfo);
        Dispose();
    }
Example #14
0
    public static ActionFile LoadActionsFromFile(string directory, string filename = "fighter_actions.json")
    {
        string dir          = FileLoader.GetFighterPath(directory);
        string combinedPath = Path.Combine(dir, filename);

        if (File.Exists(combinedPath))
        {
            string     json = File.ReadAllText(combinedPath);
            ActionFile info = JsonUtility.FromJson <ActionFile>(json);
            info.SortAllActions();
            return(info);
        }
        else
        {
            Debug.LogWarning("No action file found at " + directory + "/" + filename);
            return(null);
        }
    }
        public DownloadTracker(
            Context context,
            IDataSourceFactory dataSourceFactory,
            File actionFile,
            DownloadAction.Deserializer[] deserializers)
        {
            this.context           = context.ApplicationContext;
            this.dataSourceFactory = dataSourceFactory;
            this.actionFile        = new ActionFile(actionFile);
            trackNameProvider      = new DefaultTrackNameProvider(context.Resources);
            listeners             = new List <IListener>();
            trackedDownloadStates = new Dictionary <string, DownloadAction>();
            HandlerThread actionFileWriteThread = new HandlerThread("DownloadTracker");

            actionFileWriteThread.Start();
            actionFileWriteHandler = new Handler(actionFileWriteThread.Looper);
            LoadTrackedActions(deserializers);
        }
Example #16
0
    public void LoadDirectory(string directoryName)
    {
        directory_name = directoryName;
        string fullDirectory = FileLoader.GetFighterPath(directoryName);

        //Initialize the meta-level sprites like icons and whatnot
        franchise_icon_sprite = FileLoader.LoadSprite(FileLoader.PathCombine(fullDirectory, franchiseIconPath));
        css_icon_sprite       = FileLoader.LoadSprite(FileLoader.PathCombine(fullDirectory, css_icon_path));
        css_portrait_sprite   = FileLoader.LoadSprite(FileLoader.PathCombine(fullDirectory, css_portrait_path));

        //Load the external data json
        string action_file_json = FileLoader.LoadTextFile(FileLoader.PathCombine(fullDirectory, action_file_path));

        action_file = JsonUtility.FromJson <ActionFile>(action_file_json);
        string sprite_info_json = FileLoader.LoadTextFile(FileLoader.PathCombine(fullDirectory, sprite_info_path));

        sprite_info = JsonUtility.FromJson <SpriteInfo>(sprite_info_json);
        sprite_info.LoadDirectory(directoryName, this);

        //Mark the fighter info as initialized and ready
        initialized = true;
    }