简体   繁体   English

脚本优化C#

[英]Script optimization C#

I'm working on an autosplitter for a program called Livesplit. 我正在为一个名为Livesplit的程序进行自动拆分。 It's used for speedrunning and by creating autosplitter you can watch memory addresses to tell the app to do an action when the value changes. 它用于快速运行,并且通过创建自动拆分器,您可以观察内存地址,以告诉应用程序在值更改时执行操作。

It is using C# so it shouldn't be a problem to do some magic. 它正在使用C#,因此做一些魔术应该不是问题。

I'm a complete coding noob with pretty much zero programming experience. 我是一个完整的编码菜鸟,几乎有零编程经验。 I have no idea how to optimize this code, so it first does not look bad and second so the app itself doesn't have problems with it. 我不知道如何优化此代码,因此它首先看起来并不糟糕,其次它使应用程序本身没有问题。

Right now, my code looks like this but it is horrifying. 现在,我的代码看起来像这样,但令人恐惧。

state("GoingDown", "v1")
{
    int Loading : "GoingDown.exe", 0x6874EC;
    string30 LevelFirst : "GoingDown.exe", 0x263E28;
    string30 LevelSecond : "GoingDown.exe", 0x263E37;
    string15 Cutscene : "GoingDown.exe", 0x26B543;
}

state("GoingDown", "v2")
{
    int Loading : "GoingDown.exe", 0x6874EC;
    string30 LevelFirst : "GoingDown.exe", 0x263E40;
    string30 LevelSecond : "GoingDown.exe", 0x263E4F;
    string15 Cutscene : "GoingDown.exe", 0x26B55B;
}

init
{
    if (modules.First().ModuleMemorySize == 0x79A726)
        version = "v1";
    else if (modules.First().ModuleMemorySize == 0x79B000)
        version = "v2";
}

start
{
    //return (old.Level == "M00_CIV_Intro_1" && current.Level == "M01_HOO_Tranes_Hood_1" && current.Loading != 0);
    return (current.LevelFirst.Equals("M01_HOO_Tranes_Hood_1") && current.Loading != 0 && old.Loading == 0 || current.LevelSecond.Equals("M01_HOO_Tranes_Hood_1") && current.Loading != 0 && old.Loading == 00);
}

split
{
    if (old.LevelFirst.Equals("M01_HOO_Tranes_Hood_1", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M01_HOO_Tranes_Hood_1", StringComparison.OrdinalIgnoreCase) || old.LevelSecond.Equals("M01_HOO_Tranes_Hood_1", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M01_HOO_Tranes_Hood_1", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("M01_HOO_Tranes_Hood_1a", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M01_HOO_Tranes_Hood_1a", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M01_HOO_Tranes_Hood_1a", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M01_HOO_Tranes_Hood_1a", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("M01_HOO_Tranes_Hood_2", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M01_HOO_Tranes_Hood_2", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M01_HOO_Tranes_Hood_2", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M01_HOO_Tranes_Hood_2", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("M01_HOO_Tranes_Hood_3", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M01_HOO_Tranes_Hood_3", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M01_HOO_Tranes_Hood_3", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M01_HOO_Tranes_Hood_3", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("M01_HOO_Tranes_Hood_4", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M01_HOO_Tranes_Hood_4", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M01_HOO_Tranes_Hood_4", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M01_HOO_Tranes_Hood_4", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("M02_HOO_Subway_1a", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M02_HOO_Subway_1a", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M02_HOO_Subway_1a", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M02_HOO_Subway_1a", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("M02_HOO_Subway_1b", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M02_HOO_Subway_1b", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M02_HOO_Subway_1b", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M02_HOO_Subway_1b", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("m02_hoo_subway_2", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m02_hoo_subway_2", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("m02_hoo_subway_2", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m02_hoo_subway_2", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("m02_hoo_subway_3", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m02_hoo_subway_3", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("m02_hoo_subway_3", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m02_hoo_subway_3", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("m03_hoo_whos_got_beef_1", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m03_hoo_whos_got_beef_1", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("m03_hoo_whos_got_beef_1", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m03_hoo_whos_got_beef_1", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("m03_hoo_whos_got_beef_2", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m03_hoo_whos_got_beef_2", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("m03_hoo_whos_got_beef_2", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m03_hoo_whos_got_beef_2", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("m03_hoo_whos_got_beef_3", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m03_hoo_whos_got_beef_3", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("m03_hoo_whos_got_beef_3", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m03_hoo_whos_got_beef_3", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("m03_hoo_whos_got_beef_4", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m03_hoo_whos_got_beef_4", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("m03_hoo_whos_got_beef_4", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m03_hoo_whos_got_beef_4", StringComparison.OrdinalIgnoreCase))
        return true;

    //if (old.LevelSecond.Equals("M04_HOO_Subway_layup_0", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M04_HOO_Subway_layup_0", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M04_HOO_Subway_layup_0", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M04_HOO_Subway_layup_0", StringComparison.OrdinalIgnoreCase))
    //  return true; (CUTSCENE NO NEED TO SPLIT)

    if (old.LevelSecond.Equals("M04_HOO_Subway_layup_1a", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M04_HOO_Subway_layup_1a", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M04_HOO_Subway_layup_1a", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M04_HOO_Subway_layup_1a", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("M04_HOO_Subway_layup_1b", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M04_HOO_Subway_layup_1b", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M04_HOO_Subway_layup_1b", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M04_HOO_Subway_layup_1b", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("M04_HOO_Subway_layup_2", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M04_HOO_Subway_layup_2", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M04_HOO_Subway_layup_2", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M04_HOO_Subway_layup_2", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("M05_HOO_Battle_1", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M05_HOO_Battle_1", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M05_HOO_Battle_1", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M05_HOO_Battle_1", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("M05_HOO_Battle_3", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M05_HOO_Battle_3", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M05_HOO_Battle_3", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M05_HOO_Battle_3", StringComparison.OrdinalIgnoreCase))
        return true;

    //if (old.LevelSecond.Equals("M06_IND_Bulletproof_0") && current.LevelSecond.Equals(":M06_IND_Bulletproof_0", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M06_IND_Bulletproof_0", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M06_IND_Bulletproof_0", StringComparison.OrdinalIgnoreCase))
    //  return true; (CUTSCENE NO NEED TO SPLIT)

    if (old.LevelSecond.Equals("m06_ind_bulletproof_1", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m06_ind_bulletproof_1", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("m06_ind_bulletproof_1", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m06_ind_bulletproof_1", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("m06_ind_bulletproof_2", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m06_ind_bulletproof_2", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("m06_ind_bulletproof_2", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m06_ind_bulletproof_2", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("M06_IND_Bulletproof_3", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M06_IND_Bulletproof_3", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M06_IND_Bulletproof_3", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M06_IND_Bulletproof_3", StringComparison.OrdinalIgnoreCase))
        return true;

    //if (old.LevelSecond.Equals("M07_HOO_Blind_Justice_0") && current.LevelSecond.Equals(":M07_HOO_Blind_Justice_0", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M07_HOO_Blind_Justice_0", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M07_HOO_Blind_Justice_0", StringComparison.OrdinalIgnoreCase))
    //  return true; (CUTSCENE NO NEED TO SPLIT)

    if (old.LevelSecond.Equals("M07_HOO_Blind_Justice_1", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M07_HOO_Blind_Justice_1", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M07_HOO_Blind_Justice_1", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M07_HOO_Blind_Justice_1", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("M07_HOO_Blind_Justice_2", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M07_HOO_Blind_Justice_2", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M07_HOO_Blind_Justice_2", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M07_HOO_Blind_Justice_2", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("M07_HOO_Blind_Justice_3", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M07_HOO_Blind_Justice_3", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M07_HOO_Blind_Justice_3", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M07_HOO_Blind_Justice_3", StringComparison.OrdinalIgnoreCase))
        return true;

    //if (old.LevelSecond.Equals("m08_hoo_remember_alamo_0") && current.LevelSecond.Equals(":m08_hoo_remember_alamo_0", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("m08_hoo_remember_alamo_0", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m08_hoo_remember_alamo_0", StringComparison.OrdinalIgnoreCase))
    //  return true; (CUTSCENE NO NEED TO SPLIT)

    if (old.LevelSecond.Equals("m08_hoo_remember_alamo_1", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m08_hoo_remember_alamo_1", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("m08_hoo_remember_alamo_1", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m08_hoo_remember_alamo_1", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("m08_hoo_remember_alamo_2", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m08_hoo_remember_alamo_2", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("m08_hoo_remember_alamo_2", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m08_hoo_remember_alamo_2", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("M08_HOO_Remember_Alamo_3", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M08_HOO_Remember_Alamo_3", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M08_HOO_Remember_Alamo_3", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M08_HOO_Remember_Alamo_3", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("M09_CIV_Cat_and_Mouse_1a", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M09_CIV_Cat_and_Mouse_1a", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M09_CIV_Cat_and_Mouse_1a", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M09_CIV_Cat_and_Mouse_1a", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("M09_CIV_Cat_and_Mouse_1b", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M09_CIV_Cat_and_Mouse_1b", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M09_CIV_Cat_and_Mouse_1b", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M09_CIV_Cat_and_Mouse_1b", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("m09_civ_cat_and_mouse_2", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m09_civ_cat_and_mouse_2", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("m09_civ_cat_and_mouse_2", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m09_civ_cat_and_mouse_2", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("m10_civ_bridge_1", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m10_civ_bridge_1", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("m10_civ_bridge_1", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m10_civ_bridge_1", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("m10_civ_bridge_2", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m10_civ_bridge_2", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("m10_civ_bridge_2", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":m10_civ_bridge_2", StringComparison.OrdinalIgnoreCase))
        return true;

    if (old.LevelSecond.Equals("M11_CIV_Blimp_1", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M11_CIV_Blimp_1", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M11_CIV_Blimp_1", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M11_CIV_Blimp_1", StringComparison.OrdinalIgnoreCase))
        return true;

    // NOT SURE IF IT WORKS
    //if (old.LevelSecond.Equals("M11_CIV_Blimp_2", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M11_CIV_Blimp_2", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M01_HOO_Tranes_Hood_1", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M01_HOO_Tranes_Hood_1", StringComparison.OrdinalIgnoreCase))
    //  return true; 

    // Final split
    if (current.Cutscene.Contains("M11_010") && current.Cutscene != old.Cutscene)
        return true;
}

isLoading
{
    return (current.Loading == 0);
}

I don't know how to deal with so many if statements. 我不知道如何处理那么多的if语句。 Put it in a dictionary perhaps? 放在字典里吧? But then I have no idea how to make that. 但是后来我不知道该怎么做。

You are comparing old.LevelFirst and old.LevelSecond against lots of static values and doing a case insensitive comparison. 您正在将old.LevelFirstold.LevelSecond与大量静态值进行比较,并进行不区分大小写的比较。 Why not, at the top of your split method, take local lowercase copies of these values: 为什么不这样做,在您的split方法的顶部,获取这些值的本地小写副本:

var first = old.LevelFirst.Lower();
var second = old.LevelSecond.Lower();

This makes comparisons easier as follows: 这使得比较更加容易,如下所示:

if(first == "..." || first == "..." || first == "..." || ...)
    return true;

Next, I think you have a bug. 接下来,我认为您有一个错误。 You have if statements that say: 您有if语句说:

if(first == "xxxx" && second == "yyyy" || second == "zzz")
    return true;

This statement will return true if second == "zzz" regardless of that value of first as || 如果second == "zzz"无论first||值如何,该语句将返回true。 has a lower precedence than && . 优先级低于&& You need to put brackets around your second comparisons ie 您需要在second比较中加上括号,即

if(first == "xxxx" && (second == "yyyy" || second == "zzz"))
    return true;

Next, look at using a switch statement for first level instead of if statements (ensuring the values you compare with are lower case: 接下来,看一下在第一级使用switch语句而不是if语句(确保与之比较的值是小写的):

switch(first)
{
    case "m01_hoo_tranes_hood_1" :
        return 
            (second == ":m01_hoo_tranes_hood_1") ||
            (second == "m01_hoo_tranes_hood_1") ||
            (second == ":m01_hoo_tranes_hood_1");

    case "m01_hoo_tranes_hood_1" :
       .....
}

These is a logic change here - I am assuming that if first is m01_hoo_tranes_hood_1 but not any of the second values, then the logic will fall right through to the end and return false. 这些是这里的逻辑更改-我假设如果firstm01_hoo_tranes_hood_1但不是second值中的任何一个,那么该逻辑将一直m01_hoo_tranes_hood_1到最后并返回false。 Your if logic could allow for the same first value to match later on and have different logic but this can be incorporated into the above case statement anyway. 您的if逻辑可以允许以后使用相同的first值进行匹配,并具有不同的逻辑,但是无论如何都可以将其合并到上述case语句中。

Finally, look at the variable values. 最后,查看变量值。 Are the colon : prefixes relevant or is it a case that "they may or may not be there so I need to check for both"? 冒号:前缀是否相关?或者是否是“它们可能存在或可能不存在,所以我需要同时检查两者”的情况? If so, back on those two var first = / var = second = statements, and remove the : prefix which should reduce the comparisons: 如果是这样,请返回这两个var first = / var = second =语句,并删除:前缀,这将减少比较:

if(first.StartsWith(":"))
    first = first.Substring(1); // Remove first character

Now you don't need to include the colon prefix in all your compares. 现在,您不需要在所有比较中都包含冒号前缀。

Thanks, Chris 谢谢克里斯

From what I could tell you could cut a lot of code by doing something like 据我所知,您可以通过执行类似的操作来减少大量代码

 Func<string,string,bool>  eq = (a,b) => a.Equals(b, StringComparison.OrdinalIgnoreCase);

    var levels = new string[] 
    {
       "M01_HOO_Tranes_Hood_1",
       "M01_HOO_Tranes_Hood_1a",
       "M01_HOO_Tranes_Hood_2",
       "M01_HOO_Tranes_Hood_3",
       "M01_HOO_Tranes_Hood_4",
       "M02_HOO_Subway_1a",
       "M02_HOO_Subway_1b",
       "m02_hoo_subway_2",
       "m02_hoo_subway_3",
       "m03_hoo_whos_got_beef_1",
       "m03_hoo_whos_got_beef_2",
       "m03_hoo_whos_got_beef_3",
       "m03_hoo_whos_got_beef_4",
       "M04_HOO_Subway_layup_1a",
       "M04_HOO_Subway_layup_1b",
       "M04_HOO_Subway_layup_2",
       "M05_HOO_Battle_1",
       "M05_HOO_Battle_3",
       "m06_ind_bulletproof_1",
       "m06_ind_bulletproof_2",
       "M06_IND_Bulletproof_3",
       "M07_HOO_Blind_Justice_1",
       "M07_HOO_Blind_Justice_2",
       "M07_HOO_Blind_Justice_3",
       "m08_hoo_remember_alamo_1",
       "m08_hoo_remember_alamo_2",
       "M08_HOO_Remember_Alamo_3",
       "M09_CIV_Cat_and_Mouse_1a",
       "M09_CIV_Cat_and_Mouse_1b",
       "m09_civ_cat_and_mouse_2",
       "m10_civ_bridge_1",
       "m10_civ_bridge_2",
       "M11_CIV_Blimp_1"
    };

    if(levels.Any((level) => eq(old.LevelFirst,level) &&  eq(current.LevelSecond, ":" + level) || eq(old.LevelSecond,level) && eq(current.LevelFirst, ":" + level)))
       return true;

    // NOT SURE IF IT WORKS
    //if (old.LevelSecond.Equals("M11_CIV_Blimp_2", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M11_CIV_Blimp_2", StringComparison.OrdinalIgnoreCase) || old.LevelFirst.Equals("M01_HOO_Tranes_Hood_1", StringComparison.OrdinalIgnoreCase) && current.LevelSecond.Equals(":M01_HOO_Tranes_Hood_1", StringComparison.OrdinalIgnoreCase))
    //  return true; 

    // Final split
    if (current.Cutscene.Contains("M11_010") && current.Cutscene != old.Cutscene)
        return true;

But is this really more readable I don't know. 但这真的更可读吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM