Code Duplication    Length = 43-45 lines in 3 locations

il2fb/config/ds/schemas/hud.py 1 location

@@ 12-56 (lines=45) @@
9
from .helpers import field_from_ini, field_to_ini
10
11
12
@zope.interface.implementer(INISerializable)
13
@zope.interface.implementer(DefaultProvider)
14
class HUD(Model):
15
    show_mission_info = BooleanType(
16
        default=True,
17
        required=True,
18
    )
19
    show_kill_info = BooleanType(
20
        default=True,
21
        required=True,
22
    )
23
    show_at_bottom = BooleanType(
24
        default=False,
25
        required=True,
26
    )
27
28
    @classmethod
29
    def from_ini(cls, ini):
30
        return cls({
31
            'show_mission_info': not field_from_ini(
32
                cls.show_mission_info, ini,
33
                'game', 'NoMissionInfoHud',
34
                False,
35
            ),
36
            'show_kill_info': not field_from_ini(
37
                cls.show_kill_info, ini,
38
                'game', 'noKillInfoHud',
39
                False,
40
            ),
41
            'show_at_bottom': field_from_ini(
42
                cls.show_at_bottom, ini,
43
                'game', 'lowInfoHud',
44
            ),
45
        })
46
47
    def to_ini(self, ini):
48
        field_to_ini(not self.show_mission_info, ini, 'game', 'NoMissionInfoHud')
49
        field_to_ini(not self.show_kill_info, ini, 'game', 'noKillInfoHud')
50
        field_to_ini(self.show_at_bottom, ini, 'game', 'lowInfoHud')
51
52
    @classmethod
53
    def default(cls):
54
        return cls({
55
            field_name: field.default
56
            for field_name, field in cls.fields.items()
57
        })
58

il2fb/config/ds/schemas/events.py 1 location

@@ 13-56 (lines=44) @@
10
from .helpers import field_from_ini, field_to_ini
11
12
13
@zope.interface.implementer(INISerializable)
14
@zope.interface.implementer(DefaultProvider)
15
class Logging(Model):
16
    file_name = StringType(
17
        default="eventlog.lst",
18
        min_length=1,
19
        required=True,
20
    )
21
    keep_file = BooleanType(
22
        default=True,
23
        required=True,
24
    )
25
    log_buildings = BooleanType(
26
        default=False,
27
        required=True,
28
    )
29
30
    @classmethod
31
    def from_ini(cls, ini):
32
        return cls({
33
            'file_name': field_from_ini(
34
                cls.file_name, ini,
35
                'game', 'eventlog',
36
            ),
37
            'keep_file': field_from_ini(
38
                cls.keep_file, ini,
39
                'game', 'eventlogkeep',
40
            ),
41
            'log_buildings': field_from_ini(
42
                cls.log_buildings, ini,
43
                'game', 'eventlogHouse',
44
            ),
45
        })
46
47
    def to_ini(self, ini):
48
        field_to_ini(self.file_name, ini, 'game', 'eventlog')
49
        field_to_ini(self.keep_file, ini, 'game', 'eventlogkeep')
50
        field_to_ini(self.log_buildings, ini, 'game', 'eventlogHouse')
51
52
    @classmethod
53
    def default(cls):
54
        return cls({
55
            field_name: field.default
56
            for field_name, field in cls.fields.items()
57
        })
58
59

il2fb/config/ds/schemas/morse.py 1 location

@@ 12-54 (lines=43) @@
9
from .helpers import field_from_ini, field_to_ini
10
11
12
@zope.interface.implementer(INISerializable)
13
@zope.interface.implementer(DefaultProvider)
14
class Morse(Model):
15
    allow_morse_as_text = BooleanType(
16
        default=True,
17
        required=True,
18
    )
19
    show_morse_as_text = BooleanType(
20
        default=False,
21
        required=True,
22
    )
23
    block_morse_chat = BooleanType(
24
        default=False,
25
        required=True,
26
    )
27
28
    @classmethod
29
    def from_ini(cls, ini):
30
        return cls({
31
            'allow_morse_as_text': field_from_ini(
32
                cls.allow_morse_as_text, ini,
33
                'NET', 'allowMorseAsText',
34
            ),
35
            'show_morse_as_text': field_from_ini(
36
                cls.show_morse_as_text, ini,
37
                'game', 'ShowMorseAsText',
38
            ),
39
            'block_morse_chat': field_from_ini(
40
                cls.block_morse_chat, ini,
41
                'game', 'BlockMorseChat',
42
            ),
43
        })
44
45
    def to_ini(self, ini):
46
        field_to_ini(self.allow_morse_as_text, ini, 'NET', 'allowMorseAsText')
47
        field_to_ini(self.show_morse_as_text, ini, 'game', 'ShowMorseAsText')
48
        field_to_ini(self.block_morse_chat, ini, 'game', 'BlockMorseChat')
49
50
    @classmethod
51
    def default(cls):
52
        return cls({
53
            field_name: field.default
54
            for field_name, field in cls.fields.items()
55
        })
56