Example #1
0
    static public void AddEmptyRoomElements(ref RoomData rd)
    {
        CameraBoundsData cameraBoundsData = new CameraBoundsData();

        cameraBoundsData.size = new Vector2(52, 38);
        cameraBoundsData.pos  = Vector2.zero;
        rd.cameraBoundsData   = cameraBoundsData;
        rd.AddPropData(cameraBoundsData);

        PlayerStartData playerStartData = new PlayerStartData();

        playerStartData.pos = new Vector2(0, 0);
        rd.AddPropData(playerStartData);

        Rect[] groundRects =
        {
            new Rect(0,    17.5f, 52, 3),  // top
            new Rect(0,   -16.5f, 52, 5),  // bottom
            new Rect(-24,      0,  4, 38), // left
            new Rect(24,       0,  4, 38), // right
        };
        foreach (Rect rect in groundRects)
        {
            GroundData newGroundData = new GroundData {
                pos  = rect.position,
                size = rect.size,
            };
            rd.AddPropData(newGroundData);
        }
    }
Example #2
0
    // ----------------------------------------------------------------
    //	Serialization
    // ----------------------------------------------------------------
    public RoomData ToData()
    {
        RoomData rd = new RoomData(MyWorldData, RoomKey);

        // -- General Properties --
        rd.SetPosGlobal(PosGlobal);
        rd.SetDesignerFlag(MyRoomData.DesignerFlag);
        rd.SetIsSecret(MyRoomData.IsSecret);
        rd.isClustStart = MyRoomData.isClustStart;
        //rd.HasPlayerBeenHere = MyRoomData.HasPlayerBeenHere;

        // Find CameraBounds manually.
        CameraBounds cameraBounds = GetComponentInChildren <CameraBounds>();

        if (cameraBounds != null)
        {
            rd.cameraBoundsData = cameraBounds.ToData() as CameraBoundsData;
        }

        // -- Props --
        Prop[] allProps = FindObjectsOfType <Prop>();
        foreach (Prop prop in allProps)
        {
            if (!prop.DoSaveInRoomFile())
            {
                continue;
            }                                           // This type of Prop doesn't save to Room file? Skip it.
            rd.AddPropData(prop.ToData());
        }
        // Reverse the propDatas list so it's saved in the same order each time. (Kinda weird, but this is the easy solution.)
        rd.allPropDatas.Reverse();

        return(rd);
    }
Example #3
0
    static public void LoadRoomDataFromItsFile(RoomData rd)
    {
        // First, make empty buckets of all PropDatas.
        rd.ClearAllPropDataLists();

        // Load the file!
        string[] roomFile = GetRoomFileAsStringArray(rd.WorldIndex, rd.RoomKey);

        // NULL room file...
        if (roomFile == null)
        {
            AddEmptyRoomElements(ref rd);
        }
        // There IS a room file!...
        else
        {
            debug_roomDataLoadingRoomKey = rd.RoomKey;             // for printing to console.
            foreach (string lineString in roomFile)
            {
                if (lineString == "")
                {
                    continue;                                   // If this line is EMPTY, skip it!
                }
                int affectNameEndIndex = lineString.IndexOf(' ');
                if (affectNameEndIndex == -1)
                {
                    continue;
                }                                                         // Wrong formatting!
                string affectName       = lineString.Substring(0, affectNameEndIndex);
                string propertiesString = lineString.Substring(affectNameEndIndex + 1);
                // Room Properties
                if (affectName == ROOM_PROPERTIES)
                {
                    SetRoomPropertyFieldValuesFromFieldsString(rd, propertiesString);
                }
                // Props!
                else
                {
                    PropData propData = GetNewPropDataFromAffectName(affectName);
                    if (propData == null)                       // Safety check.
                    {
                        Debug.LogError("Oops! Unidentifiable text in room file: " + rd.RoomKey + ". Text: \"" + lineString + "\"");
                        continue;
                    }
                    SetPropDataFieldValuesFromFieldsString(propData, propertiesString);
                    rd.AddPropData(propData);
                }
            }
        }
    }